Commit 777163d9 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Small refactoring.

parent 0a14343e
......@@ -4673,37 +4673,61 @@ sub _review_user {
();
}
} keys %in;
my $new_users = [grep { $_ and $_->{email} }
@{($new_admin || {})->{$role} || []}];
my @new_users = grep { $_ and $_->{email} }
@{($new_admin || {})->{$role} || []};
 
foreach my $email (@del_users) {
next if grep { $email eq $_->{email} } @$new_users;
$list->delete_list_admin($role, [$email]);
}
foreach
my $user (@{(ref $new_users eq 'ARRAY') ? $new_users : []}) {
my $email = $user->{email};
if (grep { $email eq $_ } @del_users) {
; #FIXME: Update user?
} elsif ($list->add_list_admin($role, $user)) {
# Notify the new list owner/editor
Sympa::send_notify_to_user(
$list,
'added_as_listadmin',
$email,
{ admin_type => $role,
delegator => $param->{'user'}{'email'}
}
my $stash = [];
my $processed = 0;
my $spindle;
my @add = grep {
my $email = $_->{email};
!grep { $email eq $_ } @del_users;
} @new_users;
$spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'add',
role => $role,
email => [map { $_->{email} } @add],
gecos => [map { $_->{gecos} } @add],
sender => $param->{'user'}{'email'},
quiet => $param->{'quiet'},
scenario_context => {skip => 1},
stash => $stash,
);
Sympa::WWW::Report::notice_report_web('user_notified',
{'notified_user' => $email},
$spindle and $processed += $spindle->spin;
my @del = grep {
my $email = $_;
!grep { $email eq $_->{email} } @new_users;
} @del_users;
$spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'del',
role => $role,
email => [@del],
sender => $param->{'user'}{'email'},
quiet => $param->{'quiet'},
scenario_context => {skip => 1},
stash => $stash,
);
$spindle and $processed += $spindle->spin;
foreach my $report (@$stash) {
if ($report->[1] eq 'notice') {
Sympa::WWW::Report::notice_report_web(@{$report}[2, 3],
$param->{'action'});
} else {
#FIXME: Report error
Sympa::WWW::Report::reject_report_web(@{$report}[1 .. 3],
$param->{action});
}
}
unless (@$stash) {
Sympa::WWW::Report::notice_report_web('performed', {},
$param->{'action'});
}
 
if ($list->get_family and (@del_users or @{$new_users || []})) {
# FIXME: Required?
if ($list->get_family and $processed) {
$list->update_config_changes('param', $role);
}
}
......
......@@ -55,8 +55,6 @@ sub _twist {
my $request = shift;
my $list = $request->{context};
my $which = $list->{'name'};
my $robot = $list->{'domain'};
my $sender = $request->{sender};
my $email = $request->{email};
my $comment = $request->{gecos};
......@@ -118,11 +116,28 @@ sub _twist {
}
return undef if grep { $_->[0] eq 'user' or $_->[0] eq 'intern' } @stash;
return 1 unless $role eq 'member'; #FIXME: Send report?
if ($role eq 'member') {
_report_member($self, $request);
} else {
_report_user($self, $request);
}
return 1;
}
sub _report_member {
my $self = shift;
my $request = shift;
my $list = $request->{context};
my $sender = $request->{sender};
my $email = $request->{email};
my $comment = $request->{gecos};
$self->add_stash($request, 'notice', 'now_subscriber',
{'email' => $email, listname => $list->{'name'}});
# FIXME: Required?
my $user = Sympa::User->new($email);
$user->lang($list->{'admin'}{'lang'}) unless $user->lang;
$user->save;
......@@ -141,7 +156,7 @@ sub _twist {
$log->syslog(
'info',
'ADD %s %s from %s accepted (%.2f seconds, %d subscribers)',
$which,
$list->{'name'},
$email,
$sender,
Time::HiRes::time() - $self->{start_time},
......@@ -157,7 +172,34 @@ sub _twist {
}
);
}
return 1;
}
sub _report_user {
my $self = shift;
my $request = shift;
my $list = $request->{context};
my $role = $request->{role};
my $email = $request->{email};
my $sender = $request->{sender};
# Notify the new list owner/editor
unless ($request->{quiet}) {
Sympa::send_notify_to_user($list, 'added_as_listadmin', $email,
{admin_type => $role, delegator => $sender});
$self->add_stash($request, 'notice', 'user_notified',
{'notified_user' => $email});
}
$log->syslog(
'info',
'request "add" %s %s to %s from %s accepted (%.2f seconds)',
$role,
$email,
$list,
$sender,
Time::HiRes::time() - $self->{start_time}
);
}
1;
......@@ -177,6 +219,11 @@ quiet add has been chosen (which requires the
quiet_subscription setting to be "optional") or forced (which
requires the quiet_subscription setting to be "on").
B<Note>:
The autharization secenario C<add.*> is applicable only when the {role}
attribute is C<'member'> (default).
In the other cases the scenario processing should be skipped.
=head2 Attributes
See also L<Sympa::Request/"Attributes">.
......@@ -199,6 +246,14 @@ users will be added even if the list is closed.
I<Optional>.
Display name of the user to be added.
=item {role}
I<Optional>.
Role of the user to be added: C<'member'>, C<'owner'> or C<'editor'>.
Default value is C<'member'>.
This attribute was introduced on Sympa 6.2.67b.2.
=item {quiet}
I<Optional>.
......
......@@ -93,7 +93,22 @@ sub _twist {
}
return undef if grep { $_->[0] eq 'user' or $_->[0] eq 'intern' } @stash;
return 1 unless $role eq 'member'; # FIXME: Send report?
if ($role eq 'member') {
_report_member($self, $request);
} else {
_report_user($self, $request);
}
return 1;
}
sub _report_member {
my $self = shift;
my $request = shift;
my $list = $request->{context};
my $who = $request->{email};
my $sender = $request->{sender};
# Only when deletion was done by request, bounce information will be
# cleared. Note that tracking information will be kept.
......@@ -114,7 +129,7 @@ sub _twist {
$log->syslog(
'info',
'DEL %s %s from %s accepted (%.2f seconds, %d subscribers)',
$which,
$list->{'name'},
$who,
$sender,
Time::HiRes::time() - $self->{start_time},
......@@ -130,7 +145,28 @@ sub _twist {
}
);
}
return 1;
}
sub _report_user {
my $self = shift;
my $request = shift;
my $list = $request->{context};
my $role = $request->{role};
my $who = $request->{email};
$self->add_stash($request, 'notice', 'removed',
{role => $role, email => $who});
$log->syslog(
'info',
'request "del" %s %s from %s from %s accepted (%.2f seconds)',
$role,
$who,
$list,
$request->{sender},
Time::HiRes::time() - $self->{start_time}
);
}
1;
......@@ -148,6 +184,11 @@ Removes a user from a list (requested by another user).
Verifies the authorization and sends acknowledgements
unless quiet is specified.
+B<Note>:
The autharization secenario C<del.*> is applicable only when the {role}
attribute is C<'member'> (default).
In the other cases the scenario processing should be skipped.
=head2 Attributes
See also L<Sympa::Request::Handler/"Attributes">.
......@@ -165,6 +206,14 @@ I<Optional>.
If true value is specified,
users will be deleted even if the list is closed.
=item {role}
I<Optional>.
Role of the user to be deleted: C<'member'>, C<'owner'> or C<'editor'>.
Default value is C<'member'>.
This attribute was introduced on Sympa 6.2.67b.2.
=item {quiet}
I<Optional>.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment