Unverified Commit 6d712e4c authored by Luc Didry's avatar Luc Didry
Browse files

Fix #27 — Missing admin function to bulk unsubscribe

parent b6c92056
......@@ -119,6 +119,22 @@
[%|loc%]Do you really want to unsubscribe ALL selected subscribers?[%END%]
</strong>
</p>
[%~ ELSIF confirm_action == 'mass_del' ~%]
<h2>
<i class="fa fa-check-circle"></i>
[%|loc%]Delete email address from selected lists[%END%]
</h2>
<p>
<strong>
[% SET target = "&lt;${email}&gt;" ~%]
[%|loc(target)%]Do you really want to unsubscribe %1 from the following lists?[%END%]
</strong>
</p>
<ul>
[%~ FOREACH list = lists %]
<li>[% list %]</li>
[%~ END %]
</ul>
[%~ ELSIF confirm_action == 'delete_account' ~%]
<h2>
<i class="fa fa-check-circle"></i>
......@@ -396,6 +412,16 @@
[% IF quiet %]checked="checked"[%END%] />
<label for="quiet">[%|loc%]Quiet (don't send deletion email)[%END%]</label>
</div>
[%~ ELSIF confirm_action == 'mass_del' ~%]
[% FOREACH list = lists ~%]
<input type="hidden" name="lists" value="[% list %]" />
[%~ END %]
<input type="hidden" name="email" value="[% email %]" />
<div>
<input type="checkbox" id="quiet" name="quiet" value="1"
[% IF quiet %]checked="checked"[%END%] />
<label for="quiet">[%|loc%]Quiet (don't send deletion email)[%END%]</label>
</div>
[%~ ELSIF confirm_action == 'delete_account' ~%]
<fieldset>
<input type="hidden" name="passwd" value="x"/>
......
......@@ -3,9 +3,15 @@
<h2><i class="fa fa-search"></i> [%|loc%]User search result:[%END%]</h2>
<br />
[% IF which %]
<table class="responsive listOfItems">
<table class="responsive listOfItems toggleContainer" data-toggle-selector="input[name='lists']">
<caption>[%|loc(email)%]Lists which %1 is subscribed [%END%]</caption>
<tr>
<th>
<a href="#" data-tooltip aria-haspopup="true"
title="[%|loc%]Toggle Selection[%END%]" class="toggleButton">
<i class="fa fa-check-square-o"></i>
</a>
</th>
<th>[%|loc%]list[%END%]</th>
<th>[%|loc%]role[%END%]</th>
<th>[%|loc%]reception[%END%]</th>
......@@ -21,6 +27,11 @@
[% SET dark = 1 %]
<tr class="color0">
[% END %]
<td>
[% IF l.value.is_member %]
<input type="checkbox" name="lists" value="[% l.key %]" form="mass_del"/>
[% END %]
</td>
<td>
<a href="[% 'info' | url_rel([l.key]) %]" >
<strong>[%|obfuscate(conf.spam_protection) %][% l.key %]@[% domain %][% END %]</strong>
......@@ -68,6 +79,21 @@
</tr>
[% END %]
</table>
<form action="[% path_cgi %]" method="post" id="mass_del">
</form>
<div>
<input class="MainMenuLinks disableUnlessChecked"
data-selector="input[name='lists']" form="mass_del"
type="submit" name="action_mass_del"
value="[%|loc%]Delete selected email addresses[%END%]" />
</div>
<div>
<input type="checkbox" id="quiet" name="quiet" form="mass_del"/>
<label for="quiet">
[%|loc%]Quiet (don't send deletion email)[%END%]
</label>
</div>
<input type="hidden" name="email" value="[% email %]" form="mass_del"/>
[% ELSE %]
<p>[%|loc%]No mailing list available.[%END%]</p>
[% END %]
......
......@@ -194,6 +194,7 @@ our %comm = (
'auth_add' => 'do_auth_add',
'del' => 'do_del',
'auth_del' => 'do_auth_del',
'mass_del' => 'do_mass_del',
'modindex' => 'do_modindex',
'docindex' => 'do_docindex',
'reject' => 'do_reject',
......@@ -7313,6 +7314,79 @@ sub do_auth_del {
 
return ($in{'previous_action'} || 'sigindex');
}
# Deletes user from lists (requested by listmaster)
sub do_mass_del {
wwslog('info', '(%s) (%s)', $in{'email'},
join(', ', split /\0/, $in{'lists'}));
# Access control.
return undef
unless (Sympa::is_listmaster($robot, $param->{'user'}{'email'}));
# Turn data into usable structures
my @lists = split /\0/, $in{'lists'};
my $email = Sympa::Tools::Text::canonic_email($in{'email'});
return $in{'previous_action'} || 'serveradmin' unless $email;
# Action confirmed?
$param->{'email'} = $email;
$param->{'lists'} = \@lists;
$param->{'quiet'} = $in{'quiet'};
my $next_action = $session->confirm_action(
$in{'action'}, $in{'response_action'},
arg => join(',', @lists),
previous_action => 'serveradmin'
);
return $next_action unless $next_action eq '1';
for my $list (@lists) {
return $in{'previous_action'} || 'serveradmin' unless $email;
$list = Sympa::List->new($list, $robot);
my $stash = [];
my $processed = 0;
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'del',
email => $email,
sender => $param->{'user'}{'email'},
quiet => $param->{'quiet'},
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'} || 'serveradmin';
}
foreach my $report (@$stash) {
if ($report->[1] eq 'notice') {
Sympa::WWW::Report::notice_report_web(@{$report}[2, 3],
$param->{'action'});
} else {
Sympa::WWW::Report::reject_report_web(@{$report}[1 .. 3],
$param->{action});
}
}
unless (@$stash) {
Sympa::WWW::Report::notice_report_web('performed', {},
$param->{'action'});
}
# Skip search because we don't have the expression anymore.
delete $in{'previous_action'} if $in{'previous_action'} eq 'search';
}
return $in{'previous_action'} || 'serveradmin';
}
 
####################################################
# do_modindex
......
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