Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving/copying a list, existing list may be overwritten #454

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions src/lib/Sympa/Request/Handler/move_list.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use Sympa::Spool::Digest::Collection;
use Sympa::Spool::Held;
use Sympa::Spool::Incoming;
use Sympa::Spool::Moderation;
use Sympa::Task;
use Sympa::Spool::Task;
use Sympa::Tools::File;

use base qw(Sympa::Request::Handler);
Expand All @@ -71,6 +71,21 @@ sub _twist {
die 'bug in logic. Ask developer'
unless ref $current_list eq 'Sympa::List';

# No changes.
if ($current_list->get_id eq $listname . '@' . $robot_id) {
$log->syslog('err', 'Cannot rename list: List %s will not be changed',
$current_list);
$self->add_stash(
$request, 'user',
'unable_to_rename_list',
{ listname => $current_list->get_id,
new_listname => $listname . '@' . $robot_id,
reason => 'no_change'
}
);
return undef;
}

# Check new listname syntax.
my $listname_re = Sympa::Regexps::listname();
unless (defined $listname
Expand All @@ -88,27 +103,31 @@ sub _twist {
$log->syslog('err',
'List %s is included by other list: cannot rename it',
$current_list);
$self->add_stash($request, 'user', 'cannot_rename_list',
{reason => 'included'});
$self->add_stash(
$request, 'user',
'unable_to_rename_list',
{ listname => $current_list->get_id,
new_listname => $listname . '@' . $robot_id,
reason => 'included'
}
);
return undef;
}
}

# Check listname on SMTP server.
# Do not test if listname did not change.
my $res;
unless ($current_list->get_id eq $listname . '@' . $robot_id) {
my $aliases = Sympa::Aliases->new(
Conf::get_robot_conf($robot_id, 'alias_manager'));
$res = $aliases->check($listname, $robot_id) if $aliases;
unless (defined $res) {
$log->syslog('err', 'Can\'t check list %.128s on %.128s',
$listname, $robot_id);
$self->add_stash($request, 'intern'); #FIXME
return undef;
}
my $aliases =
Sympa::Aliases->new(Conf::get_robot_conf($robot_id, 'alias_manager'));
my $res = $aliases->check($listname, $robot_id) if $aliases;
unless (defined $res) {
$log->syslog('err', 'Can\'t check list %.128s on %.128s',
$listname, $robot_id);
$self->add_stash($request, 'intern'); #FIXME
return undef;
}
if ($res or $current_list->get_id eq $listname . '@' . $robot_id) {

# Check this listname doesn't exist already.
if ($res or Sympa::List->new($listname, $robot_id, {'just_try' => 1})) {
$log->syslog('err',
'Could not rename list %s: new list %s on %s already exist',
$current_list, $listname, $robot_id);
Expand Down