aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Panel
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 23:59:24 +0100
committerGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 23:59:24 +0100
commitae6b8a2905bfc7905030479e06f3490f2c901099 (patch)
tree0bf7637e7700016904c13948c6c4c144152eae4f /lib/Fripost/Panel
parent050f245fd22572f36de9339df800757018628449 (diff)
Factorized the code to list localparts.
Diffstat (limited to 'lib/Fripost/Panel')
-rw-r--r--lib/Fripost/Panel/Interface.pm148
1 files changed, 72 insertions, 76 deletions
diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm
index 228233e..eb9d69a 100644
--- a/lib/Fripost/Panel/Interface.pm
+++ b/lib/Fripost/Panel/Interface.pm
@@ -51,7 +51,7 @@ sub ListDomains : StartRunmode {
$template->param( $self->userInfo );
$template->param( canIAddDomain => $canIAdd );
$template->param( domains => [ map { { &fill_HTML_template_from_entry($_)
- , URI => &mkURL('.', $_->{name})
+ , URL => &mkURL('.', $_->{name})
, isPending => $_->{isPending} // 0
} }
@domains ] );
@@ -59,6 +59,7 @@ sub ListDomains : StartRunmode {
}
+
# Add a new (locked) domain.
sub AddDomain : Runmode {
my $self = shift;
@@ -131,6 +132,7 @@ sub AddDomain : Runmode {
}
+
# On this page, authenticated users can edit the domain description and
# catch-alls, and toggle activation (if they have the permission).
sub EditDomain : Runmode {
@@ -177,106 +179,89 @@ sub EditDomain : Runmode {
-
-
-# This Run Mode lists the known users, aliases and lists under the current
-# domain.
+# On this page, authenticated users can list the virtual users, aliases
+# and lists under the current domain.
sub ListLocals : Runmode {
my $self = shift;
my %CFG = $self->cfg;
- my $d = ($self->split_path)[1];
+ my $domainname = ($self->split_path)[1];
my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG );
my $q = $self->query;
if (defined $q->param('unlock')) {
- my $error; # TODO
- $fp->domain->unlock( $d, $q->param('unlock'), -error => \$error )
+ # Unlock the domain, and come back to the home page.
+ # Errors are thrown away.
+ $fp->domain->unlock( $domainname, $q->param('unlock'), -error => undef )
if $q->param('unlock') ne '';
$fp->done;
return $self->redirect('../');
}
- # Query *the* matching domain
- my %domain = $fp->domain->get( $d, -die => 404 );
-
- # Query the users, aliases and lists under the given domain. We don't
- # die with a HTTP error code here, as it is not supposed to crash.
- my @users = $fp->user->search( $d );
- my @aliases = $fp->alias->search( $d );
- my @lists = $fp->list->search( $d );
+ # Query *the* matching domain, or 404.
+ my $domain = $fp->domain->search( $domainname, -filter => 'unlocked' )
+ // die "404\n";
+ # Query the users, aliases and lists under the given domain.
+ my @locals = $fp->local->search ( $domainname, sort => 1);
$fp->done;
+ map { $_->{name} = (split_addr $_->{name})[0]; # Remove the domainpart
+ $_->{URL} = &mkURL('.', $_->{name}) } # Add a URL
+ @locals;
+
+ my @users = grep { $_->{type} eq 'user' } @locals;
+ my @aliases = grep { $_->{type} eq 'alias'} @locals;
+ my @lists = grep { $_->{type} eq 'list' } @locals;
+
+ # Add a link to the list (external) homepage.
+ map { $_->{listURL} = $CFG{'listurl_'.$_->{transport}}.
+ email_to_ascii($_->{name}.'@'.$domainname) }
+ @lists;
my $template = $self->load_tmpl( 'list-locals.html', cache => 1,
, loop_context_vars => 1 );
$template->param( $self->userInfo );
- $template->param( domain => encode_entities($domain{domain})
- , isactive => $domain{isactive}
- , description => join ("\n", @{$domain{description}}) );
+ $template->param( &fill_HTML_template_from_entry ($domain,
+ -loop => ['catchAll'] )
+ , CAodd => not $#aliases % 2 );
+
# Can the user edit the domain (change description, toggle
- # activation, modify catchalls?)
- $template->param( canEditDomain => $domain{permissions} =~ /[op]/ );
+ # activation, modify catch-alls?)
+ $template->param( canEditDomain => $domain->{permissions} =~ /[op]/ );
# Can the user add users?
- $template->param( canAddUser => $domain{permissions} =~ /p/ );
+ $template->param( canAddUser => $domain->{permissions} =~ /p/ );
# Should we list users?
$template->param( listUsers => $#users >= 0 ||
- $domain{permissions} =~ /p/ );
+ $domain->{permissions} =~ /p/ );
$template->param( users => [
- map { { &mkLink(user => $_->{user})
- , description => join ("\n", @{$_->{description}})
- , isactive => $_->{isactive}
- , forwards => [ map { {forward => encode_entities($_)} }
- @{$_->{forwards}} ]
- , quota => $_->{quota}
- };
- }
- @users
- ]);
+ map { {&fill_HTML_template_from_entry ($_, -loop => ['forward'])} }
+ @users ]);
# Can the user add aliases?
- $template->param( canAddalias => $domain{permissions} =~ /[aop]/ );
- $template->param( listCanAddAlias => [ map { {user => encode_entities($_)} }
- @{$domain{canAddAlias}} ] )
- if $domain{permissions} =~ /[op]/;
+ $template->param( canAddalias => $domain->{permissions} =~ /[aop]/ );
+ $template->param( listCanAddAlias => [ map { {item => encode_entities($_)} }
+ @{$domain->{canAddAlias}} ] )
+ if $domain->{permissions} =~ /[op]/;
# Should we list aliases?
$template->param( listAliases => $#aliases >= 0 ||
- $domain{permissions} =~ /[aop]/ );
+ $domain->{permissions} =~ /[aop]/ );
$template->param( aliases => [
- map { { &mkLink(alias => $_->{alias})
- , description => join ("\n", @{$_->{description}})
- , isactive => $_->{isactive}
- , destinations => [ map { {destination => encode_entities($_)} }
- @{$_->{maildrop}} ]
- };
- }
- @aliases
- ]);
- $template->param( catchalls => [ map { {catchall => encode_entities($_)} }
- @{$domain{catchalls}} ]
- , CAodd => not $#aliases % 2);
+ map { {&fill_HTML_template_from_entry ($_, -loop => ['destination'])} }
+ @aliases ]);
# Can the user add lists?
- $template->param( canAddList => $domain{permissions} =~ /[lop]/ );
- $template->param( listCanAddList => [ map { {user => encode_entities($_)} }
- @{$domain{canAddList}} ] )
- if $domain{permissions} =~ /[op]/;
+ $template->param( canAddList => $domain->{permissions} =~ /[lop]/ );
+ $template->param( listCanAddList => [ map { {item => encode_entities($_)} }
+ @{$domain->{canAddList}} ] )
+ if $domain->{permissions} =~ /[op]/;
# Should we list lists?
- $template->param( listLists => $#lists >= 0 || $domain{permissions} =~ /[lop]/ );
+ $template->param( listLists => $#lists >= 0 ||
+ $domain->{permissions} =~ /[lop]/ );
$template->param( lists => [
- map { { &mkLink(list => $_->{list})
- , description => join ("\n", @{$_->{description}})
- , isactive => $_->{isactive}
- , ispending => $_->{ispending}
- , transport => $_->{transport}
- , listURL => $CFG{'listurl_'.$_->{transport}}.
- email_to_ascii($_->{list}.'@'.$d)
- };
- }
- @lists
- ]);
+ map { {&fill_HTML_template_from_entry ($_, -loop => ['destination'])} }
+ @lists ]);
return $template->output;
}
@@ -531,7 +516,7 @@ sub mkLink {
my $k = shift;
my $d = shift;
( $k => encode_entities($d),
- $k.'URI' => &mkURL('.', $d) )
+ $k.'URL' => &mkURL('.', $d) )
}
sub userInfo {
@@ -542,41 +527,52 @@ sub userInfo {
( user_localpart => encode_entities($l)
, user_domainpart => encode_entities($d)
- , userURI => &mkURL ($root, $d, $l)
+ , userURL => &mkURL ($root, $d, $l)
)
}
-sub mkFormContentE {
+sub mkFormContentE { # TODO delete
&mkFormContent (map { encode_entities ($_) } @_);
}
-sub mkFormContent {
+sub mkFormContent { # TODO delete
join ("\x{0D}\x{0A}", @_);
}
-sub mkDesc {
+sub mkDesc { # TODO delete
my $desc = shift // return '';
join '<br>', map {encode_entities($_)} @$desc;
}
-my @single_valued_keys = qw/isActive/;
+my @single_valued_keys = qw/isActive quota/;
my @multi_valued_keys = qw/description catchAll
- canAddAlias canAddList/;
+ canAddAlias canAddList
+ forward destination/;
sub fill_HTML_template_from_entry {
my $entry = shift;
+ my %options = @_;
my %vars;
foreach my $key (keys %$entry) {
+ next if $options{'-hide'} and
+ grep { $key eq $_ } @{$options{'-hide'}};
+
if ($key eq 'name') {
$vars{$key} = encode_entities($entry->{$key});
}
- elsif (grep {$key eq $_} @single_valued_keys) {
+ elsif (grep {$key eq $_} ('URL', 'listURL', @single_valued_keys)) {
$vars{$key} = $entry->{$key};
}
elsif (grep {$key eq $_} @multi_valued_keys) {
- $vars{$key} = join "\x{0D}\x{0A}", map { encode_entities ($_) }
- @{$entry->{$key}};
+ my @array = map { encode_entities ($_) } @{$entry->{$key}};
+ if ($options{'-loop'} and
+ grep { $key eq $_ } @{$options{'-loop'}}) {
+ $vars{$key} = [ map {{item => $_}} @array ];
+ }
+ else {
+ $vars{$key} = join "\x{0D}\x{0A}", @array;
+ }
}
}
return %vars;