From 99b3ecbaf20b4e47ee6a403fd30268939e6e1244 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 25 Jan 2013 02:49:26 +0100 Subject: Updated and redocumented Fripost::Schema::Domain. --- lib/Fripost/Panel/Interface.pm | 85 ++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 33 deletions(-) (limited to 'lib/Fripost/Panel/Interface.pm') diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm index aee0df4..b0deeb0 100644 --- a/lib/Fripost/Panel/Interface.pm +++ b/lib/Fripost/Panel/Interface.pm @@ -40,17 +40,23 @@ sub ListDomains : StartRunmode { my %CFG = $self->cfg; my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG ); - my @domains = $fp->domain->search( -concat => "\n", -die => 403); + my @domains = $fp->domain->search( undef, -die => 403, -sort => 1, + -keys => [qw/name isActive isPending description/]); + my $canIAdd = $fp->domain->domain->canIAdd; $fp->done; - my $template = $self->load_tmpl( 'list-domains.html', cache => 1, + my $template = $self->load_tmpl( 'list-domains.html', cache => 1 , loop_context_vars => 1 ); $template->param( $self->userInfo ); - $template->param( domains => [ map { { &mkLink( domain => $_->{domain}) - , isactive => $_->{isactive} - , ispending => $_->{ispending} - , description => $_->{description} } } - @domains ] + $template->param( canIAddDomain => $canIAdd ); + $template->param( domains => [ + map { + { &mkLink( domain => $_->{name}) + , isActive => $_->{isActive} + , isPending => $_->{isPending} + , description => &mkDesc($_->{description}) + } } + @domains ] ); return $template->output; } @@ -67,7 +73,8 @@ sub ListLocals : Runmode { my $q = $self->query; if (defined $q->param('unlock')) { - $fp->domain->unlock( $d, $q->param('unlock') ) + my $error; # TODO + $fp->domain->unlock( $d, $q->param('unlock'), -error => \$error ) if $q->param('unlock') ne ''; $fp->done; return $self->redirect('../'); @@ -158,7 +165,7 @@ sub ListLocals : Runmode { # In this Run Mode authenticated users can edit the domain description -# and catchalls, and toggle activation (if they have the permission). +# and catch-alls, and toggle activation (if they have the permission). sub EditDomain : Runmode { my $self = shift; my %CFG = $self->cfg; @@ -173,28 +180,29 @@ sub EditDomain : Runmode { my $error; # Tells whether the change submission has failed. if (defined $q->param('submit')) { # Changes have been submitted: process them - $error = $fp->domain->replace({ - domain => $d, - isactive => $q->param('isactive') // 1, - description => $q->param('description') // undef, - catchalls => $q->param('catchalls') // undef, - canAddAlias => $q->param('canAddAlias') // undef, - canAddList => $q->param('canAddList') // undef - }, -concat => "(\n|\x{0D}\x{0A})"); + $fp->domain->replace({ + name => $d, + isActive => $q->param('isActive') // 1, + description => $q->param('description'), + catchAlls => [ split /\x{0D}\x{0A}/, ($q->param('catchAlls')//'') ], +# canAddAlias => [ split /\x{0D}\x{0A}/, ($q->param('canAddAlias')//'') ], +# canAddList => [ split /\x{0D}\x{0A}/, ($q->param('canAddList')//'') ] + # ^ TODO: if postmaster + }, -error => \$error); } - my %domain = $fp->domain->get( $d, -die => 404 ); + my $domain = $fp->domain->search( $d, -die => 403, -filter => 'unlocked' ) // die "404\n"; $fp->done; my $template = $self->load_tmpl( 'edit-domain.html', cache => 1, , loop_context_vars => 1 ); $template->param( $self->userInfo ); $template->param( domain => encode_entities($d) - , isPostmaster => $domain{permissions} eq 'p'); + , isPostmaster => $domain->{permissions} eq 'p'); if ($error) { # Preserve the (incorrect) form - $template->param( isactive => $q->param('isactive') // 1 + $template->param( isActive => $q->param('isActive') // 1 , description => $q->param('description') // undef - , catchalls => $q->param('catchalls') // undef + , catchAlls => $q->param('catchAlls') // undef , canAddAlias => $q->param('canAddAlias') // undef , canAddList => $q->param('canAddList') // undef , error => encode_entities ($error) ); @@ -371,16 +379,19 @@ sub AddDomain : Runmode { and grep { $q->param('postmaster') eq $_ } @postmasters; } - $error = $fp->domain->add({ - domain => $domain, - send_token_to => $q->param('postmaster') // undef, - isactive => $q->param('isactive') // 1, - description => $q->param('description') // undef, - catchalls => $q->param('catchalls') // undef }, - -concat => "(\n|\x{0D}\x{0A})", + $fp->domain->add({ + name => $domain, + isActive => $q->param('isActive') // 1, +# description => $q->param('description') // undef, +# catchAlls => [ split /\x{0D}\x{0A}/, $q->param('catchAlls') ] + }, + '-send-confirmation-token' => $q->param('postmaster') // undef, '-dry-run' => not (defined $q->param('postmaster')), - -domainurl => $q->url.'/'.encode_entities($domain).'/' # TODO: try that in nginx - ) unless $error; + -error => \$error, + webapp_url => $self->cfg('webapp_url'), + tmpl_path => $self->cfg('tmpl_path'), + email_from => $self->cfg('email_from') + ); } $fp->done; @@ -396,7 +407,10 @@ sub AddDomain : Runmode { } else { $tmpl_file = 'add-domain-2.html'; - @postmasters = Fripost::Schema::Domain::->list_postmasters($domain); + @postmasters = Fripost::Schema::Domain::->list_admin_emails( + $domain, -error => \$error + ); + $tmpl_file = 'add-domain-1.html' if $error; } my $template = $self->load_tmpl( $tmpl_file, cache => 1, @@ -404,9 +418,9 @@ sub AddDomain : Runmode { $template->param( $self->userInfo ); $template->param( error => encode_entities ($error) ) if $error; - $template->param( isactive => $q->param('isactive') // 1 + $template->param( isActive => $q->param('isActive') // 1 , description => $q->param('description') // undef - , catchalls => $q->param('catchalls') // undef + , catchAlls => $q->param('catchAlls') // undef ); $template->param( domain => encode_entities($domain) ) if defined $domain; @@ -559,6 +573,11 @@ sub mkFormContent { join ("\x{0D}\x{0A}", @_); } +sub mkDesc { + my $desc = shift // return ''; + join '
', map {encode_entities($_)} @$desc; +} + =head1 AUTHOR Guilhem Moulin C<< >> -- cgit v1.2.3