From a4fb637c441cad75350edcbbb2520f7a303b33c2 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 29 Sep 2012 21:17:15 +0200 Subject: Grant the right to create aliases and/or lists. --- TODO.org | 2 +- lib/Fripost/Panel/Interface.pm | 27 ++++++++++++++++++++------- lib/Fripost/Schema.pm | 19 +++++++++++++++++++ lib/Fripost/Schema/Domain.pm | 20 +++++++++++++++++--- template/edit-domain.html | 42 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 97 insertions(+), 13 deletions(-) diff --git a/TODO.org b/TODO.org index f040a8c..0ccac82 100644 --- a/TODO.org +++ b/TODO.org @@ -43,7 +43,7 @@ CLOSED: [2012-09-27 Thu 03:38] Mailman and Schleuder do not support IDNs, but we convert the list name into punicode first. -* TODO Give the right for domain owners and postmasters to grant the right +* DONE Give the right for domain postmasters to grant the right to create aliases and lists. * TODO Give the right to appoint co owners (for list and aliases). diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm index f102a21..ff9b291 100644 --- a/lib/Fripost/Panel/Interface.pm +++ b/lib/Fripost/Panel/Interface.pm @@ -167,7 +167,9 @@ sub EditDomain : Runmode { domain => $d, isactive => $q->param('isactive'), description => $q->param('description'), - catchalls => $q->param('catchalls') + catchalls => $q->param('catchalls'), + canCreateAlias => $q->param('canCreateAlias'), + canCreateList => $q->param('canCreateList') }, -concat => "(\n|\x{0D}\x{0A})"); } my %domain = $fp->domain->get( $d, -die => 404 ); @@ -177,21 +179,24 @@ sub EditDomain : Runmode { , loop_context_vars => 1 , global_vars => 1 ); $template->param( $self->userInfo ); - $template->param( domain => encode_entities($d) ); + $template->param( domain => encode_entities($d) + , isPostmaster => $domain{permissions} eq 'p'); if ($error) { # Preserve the (incorrect) form $template->param( isactive => $q->param('isactive') , description => $q->param('description') , catchalls => $q->param('catchalls') + , canCreateAlias => $q->param('canCreateAlias') + , canCreateList => $q->param('canCreateList') , error => encode_entities ($error) ); } else { $template->param( isactive => $domain{isactive} - , description => join ("\x{0D}\x{0A}", - @{$domain{description}}) - , catchalls => join ("\x{0D}\x{0A}", - map { encode_entities ($_) } - @{$domain{catchalls}}) ); + , description => &mkFormContent (@{$domain{description}}) + , catchalls => &mkFormContentE (@{$domain{catchalls}}) + , canCreateAlias => &mkFormContentE (@{$domain{canCreateAlias}}) + , canCreateList => &mkFormContentE (@{$domain{canCreateList}}) + ); } $template->param( newChanges => defined $q->param('submit') ); return $template->output; @@ -458,6 +463,14 @@ sub userInfo { ) } +sub mkFormContentE { + &mkFormContent (map { encode_entities ($_) } @_); +} + +sub mkFormContent { + join ("\x{0D}\x{0A}", @_); +} + =head1 AUTHOR Guilhem Moulin C<< >> diff --git a/lib/Fripost/Schema.pm b/lib/Fripost/Schema.pm index bb1f3f5..ad88c82 100644 --- a/lib/Fripost/Schema.pm +++ b/lib/Fripost/Schema.pm @@ -211,6 +211,25 @@ under the same terms as perl itself. =cut +sub _dn2email { + my $self = shift; + my $dn = shift; + $dn =~ s/^fvd=([^,]+),.*/\@$1/ and return $dn; + $dn =~ s/^fv(?:u|a|l)=([^,]+),fvd=([^,]+),.*/$1\@$2/ + or die "Wrong usage: of _dn2email: $dn"; + return $dn; +} +sub _email2dn { + my $self = shift; + my $email = shift; + my ($l,$d) = split /\@/, $email, 2; + die "Wrong usage: of _email2dn: $email" unless defined $d; + + my $dn = "fvd=$d,".$self->suffix; + $dn = "fvu=$l,".$dn if $l ne ''; + return $dn; +} + 1; __END__ diff --git a/lib/Fripost/Schema/Domain.pm b/lib/Fripost/Schema/Domain.pm index 64a8932..80810e5 100644 --- a/lib/Fripost/Schema/Domain.pm +++ b/lib/Fripost/Schema/Domain.pm @@ -100,9 +100,13 @@ sub get { return ( domain => domain_to_unicode($domain->get_value('fvd')) , isactive => $domain->get_value('fripostIsStatusActive') eq 'TRUE' , description => concat($concat, $domain->get_value('description')) - , catchalls => concat($concat, map { _email_to_unicode ($_) } + , catchalls => concat($concat, map { &_email_to_unicode ($_) } $domain->get_value('fripostOptionalMaildrop')) , permissions => get_perms($domain, $self->whoami) + , canCreateAlias => concat($concat, map { &_email_to_unicode ($self->_dn2email($_)) } + $domain->get_value('fripostCanCreateAlias')) + , canCreateList => concat($concat, map { &_email_to_unicode ($self->_dn2email($_)) } + $domain->get_value('fripostCanCreateList')) ) } @@ -118,7 +122,7 @@ sub replace { my $d = shift; my %options = @_; - foreach (qw/description catchalls/) { + foreach (qw/description catchalls canCreateAlias canCreateList/) { $d->{$_} = explode ($options{'-concat'}, $d->{$_}) if defined $d->{$_}; } @@ -131,6 +135,12 @@ sub replace { 'TRUE' : 'FALSE' , description => $d->{description} , fripostOptionalMaildrop => $d->{catchalls} + , fripostCanCreateAlias => + [ map $self->_email2dn($_), + @{$d->{canCreateAlias}} ] + , fripostCanCreateList => + [ map $self->_email2dn($_), + @{$d->{canCreateList}} ] } ); die $mesg->error."\n" if $mesg->code; }; @@ -165,10 +175,14 @@ sub _is_valid { -exact => 1 ); $d->{catchalls} = [ map { email_valid($_, -prefix => 'fake') } @{$d->{catchalls}} ]; + $d->{canCreateAlias} = [ map { email_valid($_, -prefix => 'fake') } + @{$d->{canCreateAlias}} ]; + $d->{canCreateList} = [ map { email_valid($_, -prefix => 'fake') } + @{$d->{canCreateList}} ]; } -# A variante of email_to_unicode that also takes care of domain aliases. +# A variant of email_to_unicode that also takes care of domain aliases. sub _email_to_unicode { my $email = shift; return '@'.domain_to_unicode($email) if $email =~ s/^\@//; diff --git a/template/edit-domain.html b/template/edit-domain.html index 3844775..a8af3fb 100644 --- a/template/edit-domain.html +++ b/template/edit-domain.html @@ -52,7 +52,7 @@

Description

- +
An optional description. (HTML tags are allowed.)
@@ -60,7 +60,7 @@

Catch-All aliases

- +
An optional list of destinations (one e-mail address per line) that will receive mail sent to non existing recipients. @@ -70,6 +70,44 @@ will then be sent to .
+ +
+ +

Grant right to create aliases

+ +
+ An optional list of e-mails (one address per line) that are + allowed to create aliases under your domain + . + It is possible to grant right for a whole domain by leaving out + the local part: For instance, listing + here will give every user + under example.org the right to + create aliases under + . + Note: You already have this right, so there is no need to + list your e-mail here. +
+ +
+ +

Grant right to create lists

+ +
+ An optional list of e-mails (one address per line) that are + allowed to create mailing lists under your domain + . + It is possible to grant right for a whole domain by leaving out + the local part: For instance, listing + here will give every user + under example.org the right to + create mailing lists under + . + Note: You already have this right, so there is no need to + list your e-mail here. +
+ +


-- cgit v1.2.3