From 47135d7827c75073278089d43220df48f250b118 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 19 Apr 2012 00:12:57 +0200 Subject: Search tools. --- lib/Fripost/Schema/Search.pm | 10 ++++++++++ lib/Fripost/Schema/Type/Domain.pm | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/Fripost') diff --git a/lib/Fripost/Schema/Search.pm b/lib/Fripost/Schema/Search.pm index 7c0ece6..3dc2efa 100644 --- a/lib/Fripost/Schema/Search.pm +++ b/lib/Fripost/Schema/Search.pm @@ -53,6 +53,12 @@ sub _domainEntry { &_get_values( $entry, \%domain, 'domain', 'dc'); map { &_get_values($entry, \%domain, $_) } qw /isActive owner/; + if (defined $domain{owner}) { + $domain{owner} = [ $domain{owner} ] + unless (ref $domain{owner}) eq 'ARRAY'; + $domain{owner} = [ map { (split /=/, (split /,/, $_, 2)[0], 2)[1] } + @{$domain{owner}} ]; + } return \%domain; } @@ -60,6 +66,10 @@ sub _aliasEntry { my $entry = shift; my %alias; &_get_values( $entry, \%alias, 'address', 'mailLocalAddress'); + if (defined $alias{address}) { + $alias{address} = [ $alias{address} ] + unless (ref $alias{address}) eq 'ARRAY'; + } &_get_values( $entry, \%alias, 'goto', 'mailTarget'); &_get_values( $entry, \%alias, 'isActive'); return \%alias; diff --git a/lib/Fripost/Schema/Type/Domain.pm b/lib/Fripost/Schema/Type/Domain.pm index f85ea87..0d2be17 100644 --- a/lib/Fripost/Schema/Type/Domain.pm +++ b/lib/Fripost/Schema/Type/Domain.pm @@ -14,6 +14,8 @@ our $VERSION = '0.01'; # domain is given, returns all domains. # Filters on values of both keys `domain' and `owner' (unless they are # undefined). +# If `owner' is the empty string, serch for non self-managed domains +# only. sub search { my $self = shift; @@ -26,7 +28,14 @@ sub search { my @filters = ('(ObjectClass=virtualDomain)'); push @filters, "(dc=" .$_[0]->{domain}. ")" if defined $_[0]->{domain}; - push @filters, "(owner=" .$owner. ")" if defined $_[0]->{owner}; + if (defined $_[0]->{owner}) { + if ($_[0]->{owner} eq '') { + push @filters, "(!(owner=*))"; + } + else { + push @filters, "(owner=" .$owner. ")"; + } + } my $filter; if ($#filters == 0) { $filter = $filters[0]; -- cgit v1.2.3