Unverified Commit c0602e17 authored by Luc Didry's avatar Luc Didry
Browse files

Follow-up #300 — Global setting to allow account deletion or not

parent 1730f78f
......@@ -70,7 +70,7 @@
</form>
[% END %]
[% IF session.auth == 'classic' %]
[% IF session.auth == 'classic' AND conf.allow_account_deletion %]
<h4>[%|loc%]Deleting your account[%END%]</h4>
<p>
[%|loc%]Deleting your account will unsubscribe you from all your lists, remove your ownership of your lists and permanently delete your account.[%END%]
......
......@@ -731,12 +731,12 @@ our %required_privileges = (
# as possible.
 
our %require_csrftoken = (
'add' => 1,
'del' => 1,
'move_user' => 1,
'savefile' => 1,
'setpasswd' => 1,
'setpref' => 1,
'add' => 1,
'del' => 1,
'move_user' => 1,
'savefile' => 1,
'setpasswd' => 1,
'setpref' => 1,
);
 
# this definition is used to choose the left side menu type (admin ->
......@@ -1169,6 +1169,7 @@ while ($query = CGI::Fast->new) {
'pictures_max_size',
'show_report_abuse',
'quiet_subscription',
'allow_account_deletion',
) {
 
$param->{'conf'}{$p} = Conf::get_robot_conf($robot, $p);
......@@ -17155,144 +17156,156 @@ sub do_auth {
}
 
sub do_delete_account {
wwslog(
'info',
sprintf('Account deletion: %s asked for its account to be deleted',
$param->{'user'}->{'email'})
);
# Show form if HTTP POST method not used.
return 1 unless $ENV{'REQUEST_METHOD'} eq 'POST';
my $email =
Sympa::Tools::Text::canonic_email($param->{'user'}->{'email'});
my $passwd = delete $in{'passwd'}; # Clear it.
unless ($email) {
Sympa::WWW::Report::reject_report_web('user', 'no_email', {},
$param->{'action'});
wwslog('info', 'No email');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "no_email"
}
if (Conf::get_robot_conf($robot, 'allow_account_deletion')) {
wwslog(
'info',
sprintf(
'Account deletion: %s asked for its account to be deleted',
$param->{'user'}->{'email'})
);
return 'pref';
}
 
unless ($session->{auth} eq 'classic') {
Sympa::WWW::Report::reject_report_web('user', 'no_classic_session',
{}, $param->{'action'});
wwslog('info', 'No classic session');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "no_classic_session"
}
);
return 'pref';
}
# Show form if HTTP POST method not used.
return 1 unless $ENV{'REQUEST_METHOD'} eq 'POST';
 
my $next_action =
$session->confirm_action($in{'action'}, $in{'response_action'},
previous_action => 'pref');
my $email =
Sympa::Tools::Text::canonic_email($param->{'user'}->{'email'});
my $passwd = delete $in{'passwd'}; # Clear it.
 
unless ($passwd) {
Sympa::WWW::Report::reject_report_web('user', 'missing_arg',
{'argument' => 'passwd'},
$param->{'action'});
wwslog('info', 'Missing parameter passwd');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "missing_parameter"
}
);
return 'pref';
}
unless ($email) {
Sympa::WWW::Report::reject_report_web('user', 'no_email', {},
$param->{'action'});
wwslog('info', 'No email');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "no_email"
}
);
return 'pref';
}
 
my $data;
unless ($session->{auth} eq 'classic') {
Sympa::WWW::Report::reject_report_web('user',
'no_classic_session', {}, $param->{'action'});
wwslog('info', 'No classic session');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "no_classic_session"
}
);
return 'pref';
}
 
unless (($next_action eq '1')
|| ($data = Sympa::WWW::Auth::check_auth($robot, $email, $passwd))) {
$log->syslog('notice', 'Authentication failed');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => 'authentication'
}
);
return 'pref';
}
my $next_action =
$session->confirm_action($in{'action'}, $in{'response_action'},
previous_action => 'pref');
 
return $next_action unless $next_action eq '1';
unless ($passwd) {
Sympa::WWW::Report::reject_report_web('user', 'missing_arg',
{'argument' => 'passwd'},
$param->{'action'});
wwslog('info', 'Missing parameter passwd');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => "missing_parameter"
}
);
return 'pref';
}
 
$param->{'email'} = $email;
my $data;
 
_set_my_lists_info();
unless (($next_action eq '1')
|| ($data = Sympa::WWW::Auth::check_auth($robot, $email, $passwd))
) {
$log->syslog('notice', 'Authentication failed');
web_db_log(
{ 'parameters' => $email,
'target_email' => $email,
'status' => 'error',
'error_type' => 'authentication'
}
);
return 'pref';
}
return $next_action unless $next_action eq '1';
 
my @only_owner;
for my $list (sort keys %{$param->{'which'}}) {
my $l = Sympa::List->new($list, $robot);
# Unsubscribe
$l->delete_list_member('users' => [$email])
if $param->{'which'}->{$list}->{'is_subscriber'};
# Remove from the editors
$l->delete_list_admin('editor', $email)
if $param->{'which'}->{$list}->{'is_editor'};
# Remove from the owners
if ($param->{'which'}->{$list}->{'is_owner'}) {
my @admins = $l->get_admins('owner');
if (scalar(@admins) > 1) {
$l->delete_list_admin('owner', $email);
# Don't let a list without a privileged admin
my @privileged_admins = $l->get_admins('privileged_owner');
unless (scalar(@privileged_admins)) {
@admins = $l->get_admins('owner');
for my $admin (@admins) {
$l->update_list_admin($admin->{email}, 'owner',
{profile => 'privileged'});
$param->{'email'} = $email;
_set_my_lists_info();
my @only_owner;
for my $list (sort keys %{$param->{'which'}}) {
my $l = Sympa::List->new($list, $robot);
# Unsubscribe
$l->delete_list_member('users' => [$email])
if $param->{'which'}->{$list}->{'is_subscriber'};
# Remove from the editors
$l->delete_list_admin('editor', $email)
if $param->{'which'}->{$list}->{'is_editor'};
# Remove from the owners
if ($param->{'which'}->{$list}->{'is_owner'}) {
my @admins = $l->get_admins('owner');
if (scalar(@admins) > 1) {
$l->delete_list_admin('owner', $email);
# Don't let a list without a privileged admin
my @privileged_admins =
$l->get_admins('privileged_owner');
unless (scalar(@privileged_admins)) {
@admins = $l->get_admins('owner');
for my $admin (@admins) {
$l->update_list_admin($admin->{email}, 'owner',
{profile => 'privileged'});
}
}
} else {
wwslog(
'info',
sprintf(
'Account deletion: %s is the only owner of %s. The account will not be deleted.',
$email, $list
)
);
push @only_owner, $list;
}
} else {
wwslog(
'info',
sprintf(
'Account deletion: %s is the only owner of %s. The account will not be deleted.',
$email, $list
)
);
push @only_owner, $list;
}
}
}
 
if (@only_owner) {
Sympa::WWW::Report::reject_report_web('user', 'still_owner',
{lists => join(', ', @only_owner)},
$param->{'action'});
return 'pref';
}
if (@only_owner) {
Sympa::WWW::Report::reject_report_web('user', 'still_owner',
{lists => join(', ', @only_owner)},
$param->{'action'});
return 'pref';
}
 
my $user = Sympa::User->new($email);
$user->expire;
my $user = Sympa::User->new($email);
$user->expire;
 
wwslog(
'info',
sprintf('Account deletion: the account of %s has been deleted',
$email)
);
wwslog(
'info',
sprintf('Account deletion: the account of %s has been deleted',
$email)
);
 
Sympa::WWW::Report::notice_report_web('account_deleted', {},
$param->{'action'});
Sympa::WWW::Report::notice_report_web('account_deleted', {},
$param->{'action'});
 
do_logout();
do_logout();
} else {
wwslog(
'info',
sprintf(
'Account deletion: %s asked for its account to be deleted but allow_account_deletion is not set to 1.',
$param->{'user'}->{'email'})
);
}
}
 
sub prevent_visibility_bypass {
......
......@@ -2151,6 +2151,15 @@ our @params = (
'file' => 'sympa.conf',
'optional' => 1,
},
{ 'name' => 'allow_account_deletion',
'gettext_id' =>
'EXPERIMENTAL! Allow users to delete their account. If enabled, shows a "delete my account" form in user\'s preferences page.',
'gettext_comment' =>
'Account deletion usubscribe the users from his/her lists and remove him/her from lists ownership. Only usable by users using internal authentication (i.e. no LDAP, no SSO…). See https://github.com/sympa-community/sympa/issues/300 for details',
'default' => '0',
'file' => 'sympa.conf',
'optional' => 1,
},
## Not implemented yet.
## {
......
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