Commit 9164b65b authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring. Now new methods get_admins(), get_admins_email() and...

[dev] Refactoring.  Now new methods get_admins(), get_admins_email() and is_admin() are used to get information of list owners and editors.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12310 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 0caf9b56
......@@ -144,6 +144,9 @@ Subject: [% FILTER qencode %][%|loc%]A message archiving failed[%END%][%END%]
[%|loc(file,bad)%]Sympa could not archive message '%1'. Moving it into directory '%2'.[%END%]
[%|loc%]See logs for more details.[%END%]
[% ELSIF type == 'automatic_bounce_management' -%]
[% PROCESS 'automatic_bounce_management.tt2' -%]
[% ELSIF type == 'bounce_management_failed' -%]
Subject: [% FILTER qencode %][%|loc%]A bounce management failed[%END%][%END%]
......
To: [% to %]
[% IF type == 'arc_quota_exceeded' -%]
[% IF type == 'list_created' -%]
[% PROCESS 'list_created.tt2' -%]
[% IF type == 'list_rejected' -%]
[% PROCESS 'list_rejected.tt2' -%]
[% ELSIF type == 'arc_quota_exceeded' -%]
Subject: [% FILTER qencode %][%|loc(list.name)%]List %1 archive quota exceeded[%END%][%END%]
[%|loc(list.name,list.host,size,conf.host,conf.listmaster_email)%]%1 archive quota exceeded.
......@@ -76,6 +82,8 @@ or send an email to %1 with the following subject:
[%END%]
AUTH [%keyauth%] DEL [%list.name%] [%who%]
[% ELSIF type == 'automatic_bounce_management' -%]
[% PROCESS 'automatic_bounce_management.tt2' -%]
[% ELSIF type == 'bounce_rate' -%]
Subject: [% FILTER qencode %][%|loc(list.name)%]WARNING: bounce rate too high in list %1[%END%][%END%]
......
......@@ -3036,12 +3036,14 @@ sub check_param_in {
$param->{'subscriber'} =
$list->get_list_member($param->{'user'}{'email'})
if $param->{'is_subscriber'};
$param->{'is_privileged_owner'} = $param->{'is_listmaster'}
|| $list->am_i('privileged_owner', $param->{'user'}{'email'});
$param->{'is_owner'} = $param->{'is_privileged_owner'}
|| $list->am_i('owner', $param->{'user'}{'email'});
$param->{'is_privileged_owner'} =
$list->is_admin('privileged_owner', $param->{'user'}{'email'})
|| Sympa::is_listmaster($list, $param->{'user'}{'email'});
$param->{'is_owner'} =
$list->is_admin('owner', $param->{'user'}{'email'})
|| Sympa::is_listmaster($list, $param->{'user'}{'email'});
$param->{'is_editor'} =
$list->am_i('editor', $param->{'user'}{'email'});
$list->is_admin('actual_editor', $param->{'user'}{'email'});
$param->{'is_priv'} = $param->{'is_owner'}
|| $param->{'is_editor'};
$param->{'pictures_url'} =
......@@ -3292,42 +3294,26 @@ sub check_param_out {
}
}
 
## Owners
my $owners = $list->get_owners();
foreach my $o (@{$owners}) {
next unless $o->{'email'};
$param->{'owner'}{$o->{'email'}}{'gecos'} = $o->{'gecos'};
$param->{'owner'}{$o->{'email'}}{'visibility'} =
$o->{'visibility'};
$param->{'owner'}{$o->{'email'}}{'mailto'} =
Sympa::Tools::WWW::mailto($list, $o->{'email'},
$o->{'gecos'});
( $param->{'owner'}{$o->{'email'}}{'local'},
$param->{'owner'}{$o->{'email'}}{'domain'}
) = split('@', $o->{'email'});
my $masked_email = $o->{'email'};
$masked_email =~ s/\@/ AT /;
$param->{'owner'}{$o->{'email'}}{'masked_email'} = $masked_email;
}
## Editors
if (defined $list->{'admin'}{'editor'}) {
my $editors = $list->get_editors();
foreach my $e (@{$editors}) {
next unless $e->{'email'};
$param->{'editor'}{$e->{'email'}}{'gecos'} = $e->{'gecos'};
$param->{'editor'}{$e->{'email'}}{'visibility'} =
$e->{'visibility'};
$param->{'editor'}{$e->{'email'}}{'mailto'} =
Sympa::Tools::WWW::mailto($list, $e->{'email'},
$e->{'gecos'});
( $param->{'editor'}{$e->{'email'}}{'local'},
$param->{'editor'}{$e->{'email'}}{'domain'}
) = split('@', $e->{'email'});
my $masked_email = $e->{'email'};
# Owners and editors
foreach my $role (qw(owner editor)) {
foreach my $u ($list->get_admins($role)) {
next unless $u->{'email'};
my $mailto =
Sympa::Tools::WWW::mailto($list, $u->{'email'},
$u->{'gecos'});
my ($local, $domain) = split /\@/, $u->{'email'};
my $masked_email = $u->{'email'};
$masked_email =~ s/\@/ AT /;
$param->{'editor'}{$e->{'email'}}{'masked_email'} =
$masked_email;
$param->{$role}{$u->{'email'}} = {
gecos => $u->{gecos},
visibility => $u->{visibility},
mailto => $mailto,
local => $local,
domain => $domain,
masked_email => $masked_email
};
}
}
 
......@@ -3342,12 +3328,14 @@ sub check_param_out {
$param->{'subscriber'} =
$list->get_list_member($param->{'user'}{'email'})
if $param->{'is_subscriber'};
$param->{'is_privileged_owner'} = $param->{'is_listmaster'}
|| $list->am_i('privileged_owner', $param->{'user'}{'email'});
$param->{'is_owner'} = $param->{'is_privileged_owner'}
|| $list->am_i('owner', $param->{'user'}{'email'});
$param->{'is_privileged_owner'} =
$list->is_admin('privileged_owner', $param->{'user'}{'email'})
|| Sympa::is_listmaster($list, $param->{'user'}{'email'});
$param->{'is_owner'} =
$list->is_admin('owner', $param->{'user'}{'email'})
|| Sympa::is_listmaster($list, $param->{'user'}{'email'});
$param->{'is_editor'} =
$list->am_i('editor', $param->{'user'}{'email'});
$list->is_admin('actual_editor', $param->{'user'}{'email'});
$param->{'is_priv'} = $param->{'is_owner'}
|| $param->{'is_editor'};
 
......@@ -4944,11 +4932,8 @@ sub do_lists {
$list_info->{'date'} = $list->{'admin'}{'creation'}{'date'};
$list_info->{'topics'} = $list->{'admin'}{'topics'};
 
if ($param->{'user'}{'email'}
and $list->am_i(
'privileged_owner', $param->{'user'}{'email'},
{strict => 1}
)
if ( $param->{'user'}{'email'}
and $list->is_admin('privileged_owner', $param->{'user'}{'email'})
) {
$list_info->{'is_privileged_owner'} = 1;
$list_info->{'is_owner'} = 1;
......@@ -4956,14 +4941,13 @@ sub do_lists {
$list_info->{'admin'} = 1;
}
if ( $param->{'user'}{'email'}
and $list->am_i('owner', $param->{'user'}{'email'}, {strict => 1})
) {
and $list->is_admin('owner', $param->{'user'}{'email'})) {
$list_info->{'is_owner'} = 1;
# Compat. < 6.2b.2.
$list_info->{'admin'} = 1;
}
if ( $param->{'user'}{'email'}
and $list->am_i('editor', $param->{'user'}{'email'})) {
and $list->is_admin('actual_editor', $param->{'user'}{'email'})) {
$list_info->{'is_editor'} = 1;
# Compat. < 6.2b.2.
$list_info->{'admin'} = 1;
......@@ -9532,7 +9516,8 @@ sub do_savefile {
$param->{'subtitle'} = sprintf $param->{'subtitle'}, $in{'file'};
 
if ($param->{'list'}) {
unless ($list->am_i('owner', $param->{'user'}{'email'})) {
unless ($list->is_admin('owner', $param->{'user'}{'email'})
or Sympa::is_listmaster($list, $param->{'user'}->{'email'})) {
Sympa::Report::reject_report_web('auth', 'action_owner', {},
$param->{'action'}, $list);
wwslog('err', 'Not allowed');
......@@ -10891,42 +10876,17 @@ sub do_install_pending_list {
 
}
 
## Notify listmasters
# Notify listmasters and (optionally) owners
if ($in{'status'} eq 'open') {
Sympa::send_notify_to_listmaster($list, 'list_created',
[$list->{'name'}]);
$list->send_notify_to_owner('list_created', [$list->{'name'}])
if $in{'notify'};
} elsif ($in{'status'} eq 'closed') {
Sympa::send_notify_to_listmaster($list, 'list_rejected',
[$list->{'name'}]);
}
if ($in{'notify'}) {
my $owners = $list->get_owners();
foreach my $i (@{$owners}) {
## Notify all listowners, even if reception is nomail
next unless ($i->{'email'});
if ($in{'status'} eq 'open') {
unless (
Sympa::send_file(
$list, 'list_created', $i->{'email'}, {}
)
) {
wwslog('notice',
"Unable to send template 'list_created' to $i->{'email'}"
);
}
} elsif ($in{'status'} eq 'closed') {
unless (
Sympa::send_file(
$list, 'list_rejected', $i->{'email'}, {}
)
) {
wwslog('notice',
"Unable to send template 'list_rejected' to $i->{'email'}"
);
}
}
}
$list->send_notify_to_owner('list_rejected', [$list->{'name'}])
if $in{'notify'};
}
 
$param->{'status'} = $in{'status'};
......@@ -11883,17 +11843,8 @@ sub do_search_list {
next unless ($r_action eq 'do_it');
 
if ($param->{'user'}{'email'}
&& ($list->am_i(
'owner',
$param->{'user'}{'email'},
{'strict' => 1}
)
|| $list->am_i(
'editor',
$param->{'user'}{'email'},
{'strict' => 1}
)
)
and ( $list->is_admin('owner', $param->{'user'}{'email'})
or $list->is_admin('editor', $param->{'user'}{'email'}))
) {
$is_admin = 1;
}
......@@ -20740,8 +20691,9 @@ sub do_change_email {
foreach my $list (Sympa::List::get_which($old_email, $robot, $role)) {
 
## Check if admin is include via an external datasource
my $admin_user = $list->get_list_admin($role, $old_email);
if ($admin_user->{'included'}) {
my ($admin_user) =
@{$list->get_admins($role, filter => [email => $old_email])};
if ($admin_user and $admin_user->{'included'}) {
## Notify listmaster
Sympa::send_notify_to_listmaster(
$list,
......@@ -21995,10 +21947,9 @@ sub do_search_user {
$param->{'which'}{$l}{'host'} = $list->{'admin'}{'host'};
 
# show the requestor role not the requested one
if (( $list->am_i('owner', $param->{'user'}{'email'})
|| $list->am_i('editor', $param->{'user'}{'email'})
)
) {
if ( $list->is_admin('owner', $param->{'user'}{'email'})
or $list->is_admin('editor', $param->{'user'}{'email'})
or Sympa::is_listmaster($list, $param->{'user'}{'email'})) {
$param->{'which'}{$l}{'admin'} = 1;
}
 
......
......@@ -1675,11 +1675,13 @@ sub change_user_email {
foreach my $role ('owner', 'editor') {
foreach my $list (
Sympa::List::get_which($in{'current_email'}, $robot_id, $role)) {
## Check if admin is include via an external datasource
my $admin_user =
$list->get_list_admin($role, $in{'current_email'});
if ($admin_user->{'included'}) {
## Notify listmaster
# Check if admin is included via an external datasource
my ($admin_user) = @{
$list->get_admins($role,
filter => [email => $in{'current_email'}])
};
if ($admin_user and $admin_user->{'included'}) {
# Notify listmaster
Sympa::send_notify_to_listmaster(
$list,
'failed_to_change_included_admin',
......
......@@ -942,7 +942,8 @@ sub review {
my @users;
if ($action =~ /do_it/i) {
my $is_owner = $list->am_i('owner', $sender);
my $is_owner = $list->is_admin('owner', $sender)
|| Sympa::is_listmaster($list, $sender);
unless ($user = $list->get_first_list_member({'sortby' => 'email'})) {
Sympa::Report::reject_report_cmd('user', 'no_subscriber',
{'listname' => $listname}, $cmd_line);
......@@ -3406,7 +3407,7 @@ sub modindex {
my $i;
unless ($list->am_i('editor', $sender)) {
unless ($list->is_admin('actual_editor', $sender)) {
Sympa::Report::reject_report_cmd('auth', 'restricted_modindex', {},
$cmd_line);
$log->syslog('info', 'MODINDEX %s from %s refused, not allowed',
......
This diff is collapsed.
......@@ -405,7 +405,7 @@ sub new_from_template {
$data->{'list'}{'domain'} = $data->{'robot_domain'} = $robot_id;
$data->{'list'}{'host'} = $list->{'admin'}{'host'};
$data->{'list'}{'subject'} = $list->{'admin'}{'subject'};
$data->{'list'}{'owner'} = $list->get_owners();
$data->{'list'}{'owner'} = [$list->get_admins('owner')];
$data->{'list'}{'dir'} = $list->{'dir'}; #FIXME: Required?
}
......
......@@ -452,9 +452,13 @@ sub amI {
if ($function eq 'subscriber') {
return SOAP::Data->name('result')->type('boolean')
->value($list->is_list_member($user));
} elsif ($function =~ /^owner|editor$/) {
} elsif ($function eq 'editor') {
return SOAP::Data->name('result')->type('boolean')
->value($list->am_i($function, $user));
->value($list->is_admin('actual_editor', $user));
} elsif ($function eq 'owner') {
return SOAP::Data->name('result')->type('boolean')
->value($list->is_admin('owner', $user)
|| Sympa::is_listmaster($list, $user));
} else {
die SOAP::Fault->faultcode('Server')
->faultstring('Unknown function.')
......@@ -531,15 +535,12 @@ sub info {
. $listname);
## determine status of user
if (($list->am_i('owner', $sender) || $list->am_i('owner', $sender)))
{
if ($list->is_admin('owner', $sender)
or Sympa::is_listmaster($list, $sender)) {
$result_item->{'isOwner'} =
SOAP::Data->name('isOwner')->type('boolean')->value(1);
}
if (( $list->am_i('editor', $sender)
|| $list->am_i('editor', $sender)
)
) {
if ($list->is_admin('actual_editor', $sender)) {
$result_item->{'isEditor'} =
SOAP::Data->name('isEditor')->type('boolean')->value(1);
}
......@@ -749,7 +750,7 @@ sub closeList {
}
# check authorization
unless ($list->am_i('owner', $sender)
unless ($list->is_admin('owner', $sender)
or Sympa::is_listmaster($list, $sender)) {
$log->syslog('info', 'CloseList %s from %s not allowed',
$listname, $sender);
......@@ -1123,7 +1124,8 @@ sub review {
->faultdetail($reason_string);
}
if ($action =~ /do_it/i) {
my $is_owner = $list->am_i('owner', $sender);
my $is_owner = $list->is_admin('owner', $sender)
|| Sympa::is_listmaster($list, $sender);
## Members list synchronization if include is in use
if ($list->has_include_data_sources()) {
......@@ -1197,7 +1199,7 @@ sub fullReview {
}
unless (Sympa::is_listmaster($list, $sender)
or $list->am_i('owner', $sender)) {
or $list->is_admin('owner', $sender)) {
die SOAP::Fault->faultcode('Client')
->faultstring('Not enough privileges')
->faultdetail('Listmaster or listowner required');
......@@ -1230,39 +1232,21 @@ sub fullReview {
} while ($user = $list->get_next_list_member());
}
my $editors = $list->get_editors();
if ($editors) {
foreach my $user (@$editors) {
foreach my $role (qw(owner editor)) {
foreach my $user ($list->get_admins($role)) {
$user->{'email'} =~ y/A-Z/a-z/;
if (defined $members->{$user->{'email'}}) {
$members->{$user->{'email'}}{'isEditor'} = 1;
} else {
my $res;
$res->{'email'} = $user->{'email'};
$res->{'gecos'} = $user->{'gecos'};
$res->{'isOwner'} = 0;
$res->{'isEditor'} = 1;
$res->{'isSubscriber'} = 0;
$members->{$user->{'email'}} = $res;
}
}
}
my $owners = $list->get_owners();
if ($owners) {
foreach my $user (@$owners) {
$user->{'email'} =~ y/A-Z/a-z/;
if (defined $members->{$user->{'email'}}) {
$members->{$user->{'email'}}{'isOwner'} = 1;
} else {
my $res;
$res->{'email'} = $user->{'email'};
$res->{'gecos'} = $user->{'gecos'};
$res->{'isOwner'} = 1;
$res->{'isEditor'} = 0;
$res->{'isSubscriber'} = 0;
$members->{$user->{'email'}} = $res;
unless (defined $members->{$user->{'email'}}) {
$members->{$user->{'email'}} = {
email => $user->{'email'},
gecos => $user->{'gecos'},
isOwner => 0,
isEditor => 0,
isSubscriber => 0,
};
}
$members->{$user->{'email'}}{'isOwner'} = 1 if $role eq 'owner';
$members->{$user->{'email'}}{'isEditor'} = 1 if $role eq 'editor';
}
}
......@@ -1639,15 +1623,12 @@ sub which {
## determine status of user
$result_item->{'isOwner'} = 0;
if (($list->am_i('owner', $sender) || $list->am_i('owner', $sender)))
{
if ($list->is_admin('owner', $sender)
or Sympa::is_listmaster($list, $sender)) {
$result_item->{'isOwner'} = 1;
}
$result_item->{'isEditor'} = 0;
if (( $list->am_i('editor', $sender)
|| $list->am_i('editor', $sender)
)
) {
if ($list->is_admin('actual_editor', $sender)) {
$result_item->{'isEditor'} = 1;
}
$result_item->{'isSubscriber'} = 0;
......
......@@ -1190,7 +1190,8 @@ sub verify {
} elsif ($condition_key eq 'is_owner') {
foreach my $arg (@arg) {
if ($list2->am_i('owner', $arg)) {
if ($list2->is_admin('owner', $arg)
or Sympa::is_listmaster($list2, $arg)) {
$ok = $arg;
last;
}
......@@ -1209,7 +1210,7 @@ sub verify {
} elsif ($condition_key eq 'is_editor') {
foreach my $arg (@arg) {
if ($list2->am_i('editor', $arg)) {
if ($list2->is_admin('actual_editor', $arg)) {
$ok = $arg;
last;
}
......
......@@ -487,9 +487,10 @@ sub get_directory_content {
my @moderate_dir = grep (/(\.moderate)$/, @$tmpdir);
@moderate_dir = grep (!/^\.desc\./, @moderate_dir);
# the editor can see file not yet moderated
# a user can see file not yet moderated if he is th owner of these files
if ($list->am_i('editor', $user)) {
# The editor can see file not yet moderated.
# A user can see file not yet moderated if they are the owner of these
# files.
if ($list->is_admin('actual_editor', $user)) {
push(@dir, @moderate_dir);
} else {
my @privatedir = select_my_files($user, $doc, \@moderate_dir);
......
......@@ -382,9 +382,8 @@ sub do_remove_arc {
# If not list owner, list editor nor listmaster, check if
# sender of remove order is sender of the message to be
# removed.
unless ($list->am_i('privileged_owner', $sender)
or $list->am_i('owner', $sender)
or $list->am_i('editor', $sender)
unless ($list->is_admin('owner', $sender)
or $list->is_admin('editor', $sender)
or Sympa::is_listmaster($list, $sender)) {
unless (lc $sender eq lc($arc_message->{sender} || '')) {
$log->syslog('err',
......
......@@ -1015,103 +1015,56 @@ sub DoForward {
delete $message->{'rcpt'};
delete $message->{'family'};
if ($function eq "listmaster") {
if ($function eq 'listmaster') {
@rcpt = Sympa::get_listmasters_email($robot);
$log->syslog('notice', 'Warning: No listmaster defined in sympa.conf')
unless @rcpt;
} elsif ($function eq "owner") { # -request
@rcpt = $list->get_owners_email();
$log->syslog(
'notice',
'Warning: No owner defined or all of them use nomail option in list %s',
$name
) unless @rcpt;
} elsif ($function eq "editor") {
@rcpt = $list->get_editors_email();
$log->syslog(
'notice',
'Warning: No owner and editor defined or all of them use nomail option in list %s',
$name
) unless @rcpt;
} elsif ($function eq 'owner') { # -request
@rcpt = $list->get_admins_email('receptive_owner');
@rcpt = $list->get_admins_email('owner') unless @rcpt;
$log->syslog('notice', 'Warning: No owner defined at all in list %s',
$name)
unless @rcpt;
} elsif ($function eq 'editor') {
@rcpt = $list->get_admins_email('receptive_editor');
@rcpt = $list->get_admins_email('actual_editor') unless @rcpt;
$log->syslog('notice',
'Warning: No owner and editor defined at all in list %s', $name)
unless @rcpt;
}
## Did we find a recipient?
# Did we find a recipient?
unless (@rcpt) {
if ($function ne "listmaster") {
$log->syslog(
'err',
'No recipient available for %s function %s in list %s. Trying to proceed ignoring nomail option (message ID %s)',
$name,
$function,
$name,
$messageid
);
if ($function eq 'owner') { # -request
@rcpt = $list->get_owners_email({'ignore_nomail', 1});
$log->syslog('notice',
'Warning: No owner defined at all in list %s', $name)
unless @rcpt;
} elsif ($function eq "editor") {
@rcpt = $list->get_editors_email({'ignore_nomail', 1});
$log->syslog(
'notice',
'Warning: No owner and editor defined at all in list %s',
$name
) unless @rcpt;
}
}
## Could we find a recipient by ignoring the "nomail" option?
if (@rcpt) {
$log->syslog(
'notice',
'All the intended recipients of message %s in list %s have set the "nomail" option. Ignoring it and sending it to all of them',
$messageid,
$name
);
} else {
$log->syslog(
'err',
'Message for %s function %s ignored, %s undefined in list %s',
$name,
$function,
$function,
$name
);
my $string =
sprintf
'Impossible to forward a message to %s function %s : undefined in this list',
$name, $function;
Sympa::Report::reject_report_msg(
'intern', $string, $sender,
{ 'msg_id' => $messageid,
'entry' => 'forward',
'function' => $function,
'message' => $msg
},
$robot,
$msg_string,
$list
);
$log->db_log(
'robot' => $robot,
'list' => $list->{'name'},
'action' => 'DoForward',
'parameters' => "$name,$function",
'target_email' => '',
'msg_id' => $messageid,
'status' => 'error',
'error_type' => 'internal',
'user_email' => $sender
);
return undef;
}
$log->syslog('err',
'Message for %s function %s ignored, %s undefined in list %s',
$name, $function, $function, $name);
my $string =