From 62f0ac114989808ebb84e7728b4b7e9f65d53c0e Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 9 Sep 2012 23:34:54 +0200 Subject: Added delete links. --- lib/Fripost/Panel/Interface.pm | 57 +++++++++++++++++++++++++----------------- lib/Fripost/Schema/Alias.pm | 24 ++++++++++++++++++ lib/Fripost/Schema/List.pm | 23 +++++++++++++++++ lib/Fripost/Schema/Mailbox.pm | 24 ++++++++++++++++++ 4 files changed, 105 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm index b636861..6859e57 100644 --- a/lib/Fripost/Panel/Interface.pm +++ b/lib/Fripost/Panel/Interface.pm @@ -171,7 +171,7 @@ sub EditDomain : Runmode { my $template = $self->load_tmpl( 'edit-domain.html', cache => 1, utf8 => 1 , loop_context_vars => 1 , global_vars => 1 ); - $template->param( url => $self->query->url + $template->param( url => $q->url , user_localpart => $ul , user_domainpart => $ud , domain => $d @@ -190,7 +190,7 @@ sub EditDomain : Runmode { , catchalls => join ("\x{0D}\x{0A}", @{$domain{catchalls}}) ); } - $template->param( newChanges => defined $self->query->param('submit') ); + $template->param( newChanges => defined $q->param('submit') ); return $template->output; } @@ -209,10 +209,25 @@ sub EditLocal : Runmode { my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG ); + # Search for *the* matching mailbox, alias or list. + my %local = $fp->local->get ($l, $d, -die => 404, + -concat => "\x{0D}\x{0A}"); + die "Unknown type" unless grep { $local{type} eq $_ } + qw/mailbox alias list/; + my $error; # Tells whether the change submission has failed. - if (defined $q->param('submit')) { + my $t = $local{type}; + + if (defined $q->param('a') and $q->param('a') eq 'delete') { + # Delete the entry + $error = $fp->$t->delete($l, $d, -die => 0); + unless ($error) { + $fp->done; + return $self->redirect($q->url .'/'. $d .'/'); + } + } + elsif (defined $q->param('submit')) { # Changes have been submitted: process them - my $t = $q->param('t') // die "Undefined type"; my %entry; if ($t eq 'mailbox') { $entry{user} = $l.'@'.$d; @@ -269,19 +284,16 @@ sub EditLocal : Runmode { unless $error; } - # Search for *the* matching mailbox, alias or list. - my %local = $fp->local->get ($l, $d, -die => 404, - -concat => "\x{0D}\x{0A}"); $fp->done; - my $template = $self->load_tmpl( "edit-$local{type}.html", + my $template = $self->load_tmpl( "edit-$t.html", cache => 1, utf8 => 1 ); - $template->param( url => $self->query->url + $template->param( url => $q->url , user_localpart => $ul , user_domainpart => $ud , domain => $d ); - if ($error) { + if ($error and defined $q->param('submit')) { # Preserve the (incorrect) form, except the passwords if ($local{type} eq 'mailbox') { $template->param( user => $l @@ -295,33 +307,32 @@ sub EditLocal : Runmode { $template->param( list => $l ); } else { - # Unknown type - return $self->redirect($q->url.'/'.$d.'/'); + die "Unknown type"; } $template->param( isactive => $q->param('isactive') - , description => $q->param('description') - , error => encode_entities ($error, "‘‘") ); + , description => $q->param('description') ); } else { - if ($local{type} eq 'mailbox') { + if ($t eq 'mailbox') { $template->param( user => $local{user} , forwards => $local{forwards} ); } - elsif ($local{type} eq 'alias') { + elsif ($t eq 'alias') { $template->param( alias => $local{alias} , maildrop => $local{maildrop} ); } - elsif ($local{type} eq 'list') { + elsif ($t eq 'list') { $template->param( list => $local{list} ); } - else { - # Unknown type - return $self->redirect($q->url.'/'.$d.'/'); - } $template->param( isactive => $local{isactive} , description => $local{description} ); } - $template->param( newChanges => defined $self->query->param('submit') ); + my $news = (defined $q->param('submit') or + (defined $q->param('a') and $q->param('a') eq 'delete')); + $template->param( newChanges => $news ); + $template->param( error => encode_entities ($error, "‘‘") ) if $error; + $template->param( canDelete => 1 ); # TODO + $q->delete('a'); return $template->output; } @@ -383,7 +394,7 @@ sub AddLocal : Runmode { } my $template = $self->load_tmpl( "add-$t.html", cache => 1, utf8 => 1 ); - $template->param( url => $self->query->url + $template->param( url => $q->url , user_localpart => $ul , user_domainpart => $ud , domain => $d diff --git a/lib/Fripost/Schema/Alias.pm b/lib/Fripost/Schema/Alias.pm index c413257..0976093 100644 --- a/lib/Fripost/Schema/Alias.pm +++ b/lib/Fripost/Schema/Alias.pm @@ -134,6 +134,30 @@ sub add { return $@; } + +=item B (I, I, I) + +Delete the given alias. + +=cut + +sub delete { + my $self = shift; + my $l = shift; + my $d = shift; + my %options = @_; + + my $mesg = $self->ldap->delete( "fva=$l,fvd=$d,".$self->suffix ); + if ($mesg->code) { + if (defined $options{'-die'}) { + return $mesg->error unless $options{'-die'}; + die $options{'-die'}."\n"; + } + die $mesg->error; + } +} + + =back =head1 GLOBAL OPTIONS diff --git a/lib/Fripost/Schema/List.pm b/lib/Fripost/Schema/List.pm index ad0902d..ec66f76 100644 --- a/lib/Fripost/Schema/List.pm +++ b/lib/Fripost/Schema/List.pm @@ -143,6 +143,29 @@ sub add { } +=item B (I, I, I) + +Delete the given list. Note: this will NOT wipe the archives off the +disk, but merely delete the list entry in the LDAP directory. + +=cut + +sub delete { + my $self = shift; + my $l = shift; + my $d = shift; + my %options = @_; + + my $mesg = $self->ldap->delete( "fvl=$l,fvd=$d,".$self->suffix ); + if ($mesg->code) { + if (defined $options{'-die'}) { + return $mesg->error unless $options{'-die'}; + die $options{'-die'}."\n"; + } + die $mesg->error; + } +} + =back diff --git a/lib/Fripost/Schema/Mailbox.pm b/lib/Fripost/Schema/Mailbox.pm index a3ae4be..28ef376 100644 --- a/lib/Fripost/Schema/Mailbox.pm +++ b/lib/Fripost/Schema/Mailbox.pm @@ -160,6 +160,30 @@ sub add { } +=item B (I, I, I) + +Delete the given mailbox. Note: this will NOT wipe the mailbox off the +disk, but merely delete its entry in the LDAP directory. + +=cut + +sub delete { + my $self = shift; + my $l = shift; + my $d = shift; + my %options = @_; + + my $mesg = $self->ldap->delete( "fvu=$l,fvd=$d,".$self->suffix ); + if ($mesg->code) { + if (defined $options{'-die'}) { + return $mesg->error unless $options{'-die'}; + die $options{'-die'}."\n"; + } + die $mesg->error; + } +} + + =back =head1 GLOBAL OPTIONS -- cgit v1.2.3