From 906d5f24374eb190f6b7a00523fb16e5e683ac81 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 19 Sep 2012 02:10:41 +0200 Subject: Better way to create lists. --- lib/Fripost/Schema/List.pm | 92 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 16 deletions(-) (limited to 'lib/Fripost/Schema/List.pm') diff --git a/lib/Fripost/Schema/List.pm b/lib/Fripost/Schema/List.pm index c6fb4f2..69317b1 100644 --- a/lib/Fripost/Schema/List.pm +++ b/lib/Fripost/Schema/List.pm @@ -39,17 +39,21 @@ sub search { my %options = @_; my $concat = $options{'-concat'}; + my $filter = 'objectClass=FripostVirtualList'; + $filter = '(&('.$filter.')(!(fripostIsStatusPending=TRUE)))' + if (defined $options{'-is_pending'}) and !$options{'-is_pending'}; + my $lists = $self->ldap->search( base => "fvd=$domain,".$self->suffix, scope => 'one', deref => 'never', - filter => 'objectClass=FripostVirtualList', + filter => $filter, attrs => [ qw/fvl description fripostIsStatusActive fripostListManager/ ] ); if ($lists->code) { die $options{'-die'}."\n" if defined $options{'-die'}; - die $lists->error; + die $lists->error."\n"; } return map { { list => email_to_unicode($_->get_value('fvl')) , isactive => $_->get_value('fripostIsStatusActive') eq 'TRUE' @@ -117,19 +121,9 @@ sub add { , fripostIsStatusActive => $l->{isactive} ? 'TRUE' : 'FALSE' , fripostOwner => $self->whoami , fripostListManager => $l->{transport} + , fripostIsStatusPending => 'TRUE' + , fripostLocalAlias => $l2.'#'.$d ); - if ($l->{transport} eq 'mailman') { - $attrs{fripostListCommand} = - [ map { $l2.'-'.$_ } - qw/admin bounces confirm join leave loop owner - request subscribe unsubscribe/ ]; - } - elsif ($l->{transport} eq 'schleuder') { - $attrs{fripostListCommand} = - [ map { $l2.'-'.$_ } - # TODO: check that - qw/request bounce sendkey owner/ ]; - } $attrs{description} = $l->{description} if defined $l->{description} and @{$l->{description}}; @@ -137,10 +131,76 @@ sub add { attrs => [ %attrs ] ); if ($mesg->code) { die $options{'-die'}."\n" if defined $options{'-die'}; - die $mesg->error; + die $mesg->error."\n"; } }; return $@; + # TODO: send email to mklist-$transport to finalize +} + + +=item B (I, I) + +Tells whether the given list's status is I, meaning an entry +has been created in the LDAP directory (for instance by the domain owner +from the Web Panel), but the local aliases have not yet been added by +the ListCreator entity, and the list is not known by the list manager. + +=cut + +sub is_pending { + my $self = shift; + my ($l,$d) = split /\@/, email_to_ascii(shift), 2; + my %options = @_; + + my $mesg = $self->ldap->search( + base => "fvl=$l,fvd=$d,".$self->suffix, + scope => 'base', + deref => 'never', + filter => 'objectClass=FripostVirtualList', + attrs => [ 'fvl', 'fripostIsStatusPending' ] + ); + die "Error: ".$l.'@'.$d.": No such object in the LDAP directory\n" + if $mesg->code == 32; # No such object; a common error here. + die $mesg->error if $mesg->code; + + die "Error: Multiple matching entries found." if $mesg->count > 1; + my $list = $mesg->pop_entry; + + die "Error: No matching entry found." unless defined $list; + my $r = $list->get_value('fripostIsStatusPending'); + return (defined $r and $r eq 'TRUE'); +} + + +=item B (I, I, I) + +Add the lists commands, and remove the pending status. + +=cut + +sub add_commands { + my $self = shift; + my ($l,$d) = split /\@/, email_to_ascii(shift), 2; + my $cmds = shift; + my %options = @_; + + my $mesg; + foreach my $cmd (@$cmds) { + $mesg = $self->ldap->add( "fvlc=$l-$cmd,fvl=$l,fvd=$d,".$self->suffix, + attrs => [ objectClass => 'FripostVirtualListCommand', + FripostLocalAlias => $l.'-'.$cmd.'#'.$d ] ); + last if $mesg->code; + } + + $mesg = $self->ldap->modify( "fvl=$l,fvd=$d,".$self->suffix, + , delete => 'fripostIsStatusPending' ) + unless $mesg->code; + + if ($mesg->code) { + die $options{'-die'}."\n" if defined $options{'-die'}; + die $mesg->error."\n"; + } } @@ -162,7 +222,7 @@ sub delete { return $mesg->error unless $options{'-die'}; die $options{'-die'}."\n"; } - die $mesg->error; + die $mesg->error."\n"; } } -- cgit v1.2.3