Commit 08eced98 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Refactoring: WWSympa: del function was integrated to Sympa::Request framework.

parent ce62658a
......@@ -167,7 +167,9 @@
<form action="[% path_cgi %]" method="POST">
[% IF confirm_action == 'add' ~%]
<input type="hidden" name="email" value="[% email %]" />
[% FOREACH e = email ~%]
<input type="hidden" name="email" value="[% e %]" />
[%~ END %]
<div>
<input type="checkbox" id="quiet" type="checkbox" name="quiet" value="1"
[% IF quiet %]checked="checked"[%END%] />
......
......@@ -7145,38 +7145,46 @@ sub do_add {
# Access control.
return undef unless defined check_authz('do_add', 'add');
 
my $email = Sympa::Tools::Text::canonic_email($in{'email'});
return $in{'previous_action'} || 'review' unless $email;
my @emails =
grep {$_} map { Sympa::Tools::Text::canonic_email($_) }
split /\0/, $in{'email'};
return $in{'previous_action'} || 'review' unless @emails;
 
$param->{'email'} = $email;
$param->{'email'} = [@emails];
$param->{'quiet'} = $in{'quiet'};
 
# Action confirmed?
my $next_action = $session->confirm_action(
$in{'action'}, $in{'response_action'},
arg => $email,
previous_action => $in{'previous_action'}
arg => join(',', sort @emails),
previous_action => ($in{'previous_action'} || 'review')
);
return $next_action unless $next_action eq '1';
 
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'add',
email => $email,
sender => $param->{'user'}{'email'},
md5_check => 1,
scenario_context => {
email => $email,
sender => $param->{'user'}{'email'},
remote_host => $param->{'remote_host'},
remote_addr => $param->{'remote_addr'}
},
);
unless ($spindle and $spindle->spin) {
my $stash = [];
my $processed = 0;
foreach my $email (@emails) {
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'add',
email => $email,
sender => $param->{'user'}{'email'},
md5_check => 1,
scenario_context => {
email => $email,
sender => $param->{'user'}{'email'},
remote_host => $param->{'remote_host'},
remote_addr => $param->{'remote_addr'}
},
stash => $stash,
);
$spindle and $processed += $spindle->spin;
}
unless ($processed) {
return $in{'previous_action'} || 'review';
}
 
foreach my $report (@{$spindle->{stash} || []}) {
foreach my $report (@$stash) {
if ($report->[1] eq 'notice') {
Sympa::Report::notice_report_web(@{$report}[2, 3],
$param->{'action'});
......@@ -7185,7 +7193,7 @@ sub do_add {
$param->{action});
}
}
unless (@{$spindle->{stash} || []}) {
unless (@$stash) {
Sympa::Report::notice_report_web('performed', {}, $param->{'action'});
}
 
......@@ -7196,22 +7204,17 @@ sub do_add {
# No longer used. Use do_authowner().
#sub do_add_fromsub;
 
####################################################
# do_del
####################################################
# Deletes a user from a list (requested by an other user)
#
# IN : -
#
# OUT : 'loginrequest'
# | ($in{'previous_action'} || 'review') | undef
#
####################################################
## TODO: vérifier validité email
# Deletes user(s) from a list (requested by owner)
sub do_del {
wwslog('info', '');
wwslog('info', '(%s)', $in{'email'});
 
my @emails = split /\0/, $in{'email'};
# Access control.
return undef unless defined check_authz('do_del', 'del');
my @emails =
grep {$_} map { Sympa::Tools::Text::canonic_email($_) }
split /\0/, $in{'email'};
return $in{'previous_action'} || 'review' unless @emails;
 
$param->{'email'} = [@emails];
$param->{'quiet'} = $in{'quiet'};
......@@ -7224,125 +7227,44 @@ sub do_del {
);
return $next_action unless $next_action eq '1';
 
my $result = Sympa::Scenario::request_action(
$list, 'del',
$param->{'auth_method'},
{ 'sender' => $param->{'user'}{'email'},
'email' => $in{'email'},
'remote_host' => $param->{'remote_host'},
'remote_addr' => $param->{'remote_addr'}
}
);
my $del_is;
my $reason;
if (ref($result) eq 'HASH') {
$del_is = $result->{'action'};
$reason = $result->{'reason'};
}
unless ($del_is =~ /do_it/) {
Sympa::Report::reject_report_web('auth', $reason, {},
$param->{'action'}, $list);
wwslog('info', '%s may not del', $param->{'user'}{'email'});
web_db_log(
{ 'target_email' => $in{'email'},
'status' => 'error',
'error_type' => 'internal'
}
my $stash = [];
my $processed = 0;
foreach my $email (@emails) {
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'del',
email => $email,
sender => $param->{'user'}{'email'},
md5_check => 1,
scenario_context => {
email => $email,
sender => $param->{'user'}{'email'},
remote_host => $param->{'remote_host'},
remote_addr => $param->{'remote_addr'}
},
stash => $stash,
);
return undef;
$spindle and $processed += $spindle->spin;
}
unless ($processed) {
return $in{'previous_action'} || 'review';
}
 
my ($total, @removed_users);
foreach my $email (@emails) {
my $escaped_email = Sympa::Tools::Text::escape_chars($email);
my $user_entry = $list->get_list_member($email);
unless (defined($user_entry)) {
Sympa::Report::reject_report_web('user', 'user_not_subscriber',
{'email' => $email},
$param->{'action'}, $list);
wwslog('info', '%s not subscribed', $email);
web_db_log(
{ 'target_email' => $in{'email'},
'status' => 'error',
'error_type' => 'not_subscriber'
}
);
next;
}
push @removed_users, $email;
my $bounce_dir = $list->get_bounce_dir();
if (-f $bounce_dir . '/' . $escaped_email) {
unless (unlink $bounce_dir . '/' . $escaped_email) {
wwslog(
'info',
'Failed deleting %s',
$bounce_dir . '/' . $escaped_email
);
web_db_log(
{ 'target_email' => $in{'email'},
'status' => 'error',
'error_type' => 'internal'
}
);
next;
}
}
wwslog('info', 'Subscriber %s deleted from list %s',
$email, $param->{'list'});
unless ($in{'quiet'}) {
unless (Sympa::send_file($list, 'removed', $email, {})) {
wwslog('notice', 'Unable to send template "removed" to %s',
$email);
}
foreach my $report (@$stash) {
if ($report->[1] eq 'notice') {
Sympa::Report::notice_report_web(@{$report}[2, 3],
$param->{'action'});
} else {
Sympa::Report::reject_report_web(@{$report}[1 .. 3],
$param->{action});
}
web_db_log(
{ 'target_email' => $email,
'status' => 'success'
}
);
}
$total = $list->delete_list_member(
'users' => \@removed_users,
'exclude' => '1',
'operation' => 'del',
);
unless (defined $total) {
Sympa::Report::reject_report_web('intern',
'delete_subscriber_db_failed', {}, $param->{'action'}, $list,
$param->{'user'}{'email'}, $robot);
wwslog('info', 'Failed');
web_db_log(
{ 'target_email' => $in{'email'},
'status' => 'error',
'error_type' => 'internal'
}
);
return undef;
unless (@$stash) {
Sympa::Report::notice_report_web('performed', {}, $param->{'action'});
}
 
Sympa::Report::notice_report_web('del_performed', {'total' => $total},
$param->{'action'});
$param->{'is_subscriber'} = 1;
$param->{'may_signoff'} = 1;
## Skip search because we don't have the expression anymore
delete $in{'previous_action'} if ($in{'previous_action'} eq 'search');
# Skip search because we don't have the expression anymore.
delete $in{'previous_action'} if $in{'previous_action'} eq 'search';
return $in{'previous_action'} || 'review';
}
 
......
......@@ -68,7 +68,7 @@ sub _twist {
if ($list->is_list_member($email)) {
$self->add_stash($request, 'user', 'already_subscriber',
{'email' => $email});
{'email' => $email, list => $list->{'name'}});
$log->syslog('err',
'ADD command rejected; user "%s" already member of list "%s"',
$email, $which);
......
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