Unverified Commit b200c05f authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Merge pull request #559 from ikedas/refactor_scenario_2019 by ikedas

Refactor Sympa::Scenario (cf. #520)
parents bac9b6f9 55083843
......@@ -17,7 +17,7 @@
[% IF pitem.scenario && is_listmaster ~%]
&nbsp;<a class="input"
href="[% 'dump_scenario' | url_rel([list,pitem.name]) %]"
href="[% 'dump_scenario' | url_rel([list,pitem.scenario]) %]"
title="[%|loc%]scenario source[%END%]">[%|loc%]scenario source[%END~%]
</a>
[%~ END %]
......
......@@ -83,14 +83,18 @@
<label for="read_access">[%|loc%]Read access[%END%]</label>
<select id="read_access" name="read_access">
[% FOREACH s = scenari_read %]
<option value='[% s.key %]' [% s.value.selected %]>[% s.value.web_title %]</option>
<option value="[% s.key %]"
[%~ IF s.value.selected %] selected="selected"[% END ~%]
>[% s.value.title %]</option>
[% END %]
</select>
<label for="edit_access">[%|loc%]Edit access[%END%]</label>
<select id="edit_access" name="edit_access">
[% FOREACH s = scenari_edit %]
<option value='[% s.key %]' [% s.value.selected %]>[% s.value.web_title %]</option>
<option value="[% s.key %]"
[%~ IF s.value.selected %] selected="selected"[% END ~%]
>[% s.value.title %]</option>
[% END %]
</select>
<input type="hidden" name="list" value="[% list %]" />
......
......@@ -13,7 +13,7 @@
[% ELSE %]
<div id="ActionHeader">
<h2 class='block'>[% pname %] [% scenario_name %] </h2>
<h2 class='block'>[% scenario_function %].[% scenario_name %] </h2>
<span class="text_center">([%|loc%]path:[%END%] [% scenario_path %])</span>
</div>
<font size="-2">
......@@ -22,7 +22,7 @@
<fieldset>
<textarea cols="80" rows="10" name="new_scenario_content">[% dumped_scenario %]</textarea><br />
<input type="hidden" name="list" value="[% list %]" />
<input type="hidden" name="pname" value="[% pname %]" />
<input type="hidden" name="scenario_function" value="[% scenario_function %]" />
<!-- template is ready for saving scenario with scope limited to the current list or to the current robot but wwsympa
[% IF is_listmaster %]
......
......@@ -44,7 +44,7 @@
<li><a href="[% 'review' | url_rel([l.key]) %]"><i class="fa fa-users"></i> [%|loc%]Review members[%END%]</a></li>
[% END %]
[% IF is_user_allowed_to('archive.web_access', l.key) %]
[% IF is_user_allowed_to('archive_web_access', l.key) %]
<li><a href="[% 'arc' | url_rel([l.key]) %]"><i class="fa fa-archive"></i> [%|loc%]Archives[%END%]</a></li>
[% END %]
</ul>
......
......@@ -63,7 +63,7 @@
<li><a href="[% 'review' | url_rel([l.key]) %]">[%|loc%]Review members[%END%]</a></li>
[% END %]
[% IF is_user_allowed_to('archive.web_access', l.key) %]
[% IF is_user_allowed_to('archive_web_access', l.key) %]
<li><a href="[% 'arc' | url_rel([l.key]) %]">[%|loc%]Archives[%END%]</a></li>
[% END %]
</ul>
......
This diff is collapsed.
......@@ -1885,26 +1885,23 @@ sub _infer_server_specific_parameter_values {
}
}
foreach my $action (split(/,/, $param->{'config_hash'}{'use_blacklist'}))
foreach
my $action (split /\s*,\s*/, $param->{'config_hash'}{'use_blacklist'})
{
$param->{'config_hash'}{'blacklist'}{$action} = 1;
}
next unless $action =~ /\A[.\w]+\z/;
# Compat. <= 6.2.38
$action = {
'shared_doc.d_read' => 'd_read',
'shared_doc.d_edit' => 'd_edit',
'archive.access' => 'archive_mail_access', # obsoleted
'web_archive.access' => 'archive_web_access', # obsoleted
'archive.web_access' => 'archive_web_access',
'archive.mail_access' => 'archive_mail_access',
'tracking.tracking' => 'tracking',
}->{$action}
|| $action;
foreach my $log_module (
split(/,/, $param->{'config_hash'}{'log_module'} || '')) {
$param->{'config_hash'}{'loging_for_module'}{$log_module} = 1;
}
foreach my $log_condition (
split(/,/, $param->{'config_hash'}{'log_condition'} || '')) {
chomp $log_condition;
if ($log_condition =~ /^\s*(ip|email)\s*\=\s*(.*)\s*$/i) {
$param->{'config_hash'}{'loging_condition'}{$1} = $2;
} else {
$log->syslog('err',
'Unrecognized log_condition token %s; ignored',
$log_condition);
}
$param->{'config_hash'}{'blacklist'}{$action} = 1;
}
if ($param->{'config_hash'}{'ldap_export_name'}) {
......@@ -1982,7 +1979,20 @@ sub _infer_robot_parameter_values {
. $param->{'config_hash'}{'domain'};
# split action list for blacklist usage
foreach my $action (split(/,/, $Conf{'use_blacklist'})) {
foreach my $action (split /\s*,\s*/, $Conf{'use_blacklist'}) {
next unless $action =~ /\A[.\w]+\z/;
# Compat. <= 6.2.38
$action = {
'shared_doc.d_read' => 'd_read',
'shared_doc.d_edit' => 'd_edit',
'archive.access' => 'archive_mail_access', # obsoleted
'web_archive.access' => 'archive_web_access', # obsoleted
'archive.web_access' => 'archive_web_access',
'archive.mail_access' => 'archive_mail_access',
'tracking.tracking' => 'tracking',
}->{$action}
|| $action;
$param->{'config_hash'}{'blacklist'}{$action} = 1;
}
......
......@@ -56,7 +56,6 @@ use Sympa::Log;
use Sympa::Process;
use Sympa::Regexps;
use Sympa::Robot;
use Sympa::Scenario;
use Sympa::Spindle::ProcessTemplate;
use Sympa::Spool::Auth;
use Sympa::Template;
......@@ -4232,6 +4231,7 @@ sub is_moderated {
}
## Is the list archived?
#FIXME: Broken. Use scenario or is_archiving_enabled().
sub is_archived {
$log->syslog('debug', '');
if (shift->{'admin'}{'archive'}{'web_access'}) {
......@@ -4243,6 +4243,7 @@ sub is_archived {
}
## Is the list web archived?
#FIXME: Broken. Use scenario or is_archiving_enabled().
sub is_web_archived {
my $self = shift;
return 1
......@@ -4285,54 +4286,8 @@ sub is_included {
# Moved to Sympa::Spindle::ProcessDigest::_may_distribute_digest().
#sub may_distribute_digest;
## Loads all scenari for an action
sub load_scenario_list {
my ($self, $action, $robot) = @_;
$log->syslog('debug3', '(%s, %s)', $action, $robot);
my $directory = "$self->{'dir'}";
my %list_of_scenario;
my %skip_scenario;
my @list_of_scenario_dir =
@{Sympa::get_search_path($self, subdir => 'scenari')};
unshift @list_of_scenario_dir, $self->{'dir'} . '/scenari'; #FIXME
foreach my $dir (@list_of_scenario_dir) {
next unless (-d $dir);
my $scenario_regexp = Sympa::Regexps::scenario();
while (<$dir/$action.*:ignore>) {
if (/$action\.($scenario_regexp):ignore$/) {
my $name = $1;
$skip_scenario{$name} = 1;
}
}
while (<$dir/$action.*>) {
next unless (/$action\.($scenario_regexp)$/);
my $name = $1;
# Ignore default setting on <= 6.2.40, using symbolic link.
next if $name eq 'default' and -l "$dir/$action.$name";
next if (defined $list_of_scenario{$name});
next if (defined $skip_scenario{$name});
my $scenario = Sympa::Scenario->new(
'robot' => $robot,
'directory' => $directory,
'function' => $action,
'name' => $name
);
$list_of_scenario{$name} = $scenario;
}
}
## Return a copy of the data to prevent unwanted changes in the central
## scenario data structure
return Sympa::Tools::Data::dup_var(\%list_of_scenario);
}
# Moved: Use Sympa::Scenario::get_scenarios().
#sub load_scenario_list;
# Deprecated: Use Sympa::Task::get_tasks().
#sub load_task_list;
......@@ -8028,8 +7983,7 @@ sub _load_list_param {
my $value = shift;
my $p = shift;
my $robot = $self->{'domain'};
my $directory = $self->{'dir'};
my $robot = $self->{'domain'};
# Empty value.
unless (defined $value and $value =~ /\S/) {
......@@ -8058,21 +8012,9 @@ sub _load_list_param {
## Scenario
if ($p->{'scenario'}) {
$value =~ y/,/_/;
my $scenario = Sympa::Scenario->new(
'function' => $p->{'scenario'},
'robot' => $robot,
'name' => $value,
'directory' => $directory
);
## We store the path of the scenario in the sstructure
## Later Sympa::Scenario::request_action() will look for the scenario in
## %Sympa::Scenario::all_scenarios through Scenario::new()
$value = {
'file_path' => $scenario->{'file_path'},
'name' => $scenario->{'name'}
};
$value =~ y/,/_/; # Compat. eg "add owner,notify"
#FIXME: Check existence of scenario file.
$value = {'name' => $value};
} elsif ($p->{'task'}) {
$value = {'name' => $value};
}
......
......@@ -420,8 +420,8 @@ sub check_spam_status {
: $self->{context};
my $spam_status =
Sympa::Scenario::request_action($robot_id || $Conf::Conf{'domain'},
'spam_status', 'smtp', {'message' => $self});
Sympa::Scenario->new($robot_id, 'spam_status')
->authz('smtp', {'message' => $self});
if (defined $spam_status) {
if (ref($spam_status) eq 'HASH') {
$self->{'spam_status'} = $spam_status->{'action'};
......
......@@ -38,7 +38,7 @@ use base qw(Sympa::Request::Handler);
my $language = Sympa::Language->instance;
my $log = Sympa::Log->instance;
use constant _action_scenario => 'archive.mail_access';
use constant _action_scenario => 'archive_mail_access';
use constant _action_regexp => qr'reject|do_it'i;
use constant _context_class => 'Sympa::List';
......
......@@ -76,8 +76,8 @@ sub _twist {
do {
my $email = lc($user->{'email'});
my $result =
Sympa::Scenario::request_action($list, 'visibility',
$auth_method, $self->{scenario_context});
Sympa::Scenario->new($list, 'visibility')
->authz($auth_method, $self->{scenario_context});
my $action;
$action = $result->{'action'} if ref $result eq 'HASH';
......
......@@ -58,8 +58,8 @@ sub _twist {
Sympa::List::get_which($sender, $request->{context}, 'member')) {
# Skip hidden lists.
my $result =
Sympa::Scenario::request_action($list, 'visibility', $auth_method,
$self->{scenario_context});
Sympa::Scenario->new($list, 'visibility')
->authz($auth_method, $self->{scenario_context});
my $action = $result->{'action'} if ref $result eq 'HASH';
unless ($action) {
......
......@@ -58,8 +58,8 @@ sub _twist {
Sympa::List::get_which($email, $request->{context}, 'member')) {
# Skip hidden lists.
my $result =
Sympa::Scenario::request_action($list, 'visibility', $auth_method,
$self->{scenario_context});
Sympa::Scenario->new($list, 'visibility')
->authz($auth_method, $self->{scenario_context});
my $action = $result->{'action'} if ref $result eq 'HASH';
unless ($action) {
......
......@@ -38,7 +38,7 @@ use base qw(Sympa::Request::Handler);
my $language = Sympa::Language->instance;
my $log = Sympa::Log->instance;
use constant _action_scenario => 'archive.mail_access';
use constant _action_scenario => 'archive_mail_access';
use constant _action_regexp => qr'reject|do_it'i;
use constant _context_class => 'Sympa::List';
......
......@@ -62,12 +62,8 @@ sub _twist {
## Set title in the current language
foreach my $p ('subscribe', 'unsubscribe', 'send', 'review') {
my $scenario = Sympa::Scenario->new(
'robot' => $robot,
'directory' => $list->{'dir'},
'file_path' => $list->{'admin'}{$p}{'file_path'}
);
$data->{$p} = $scenario->get_current_title();
my $scenario = Sympa::Scenario->new($list, $p);
$data->{$p} = $scenario->get_current_title;
}
## Digest
......
......@@ -78,8 +78,8 @@ sub _twist {
# Is the guest user allowed to subscribe in this list?
# Emulating subscription privilege of target user.
my $result =
Sympa::Scenario::request_action($list, 'subscribe', 'md5',
{sender => $email});
Sympa::Scenario->new($list, 'subscribe')
->authz('md5', {sender => $email});
my $action;
$action = $result->{'action'} if ref $result eq 'HASH';
......
......@@ -38,7 +38,7 @@ use base qw(Sympa::Request::Handler);
my $language = Sympa::Language->instance;
my $log = Sympa::Log->instance;
use constant _action_scenario => 'archive.mail_access';
use constant _action_scenario => 'archive_mail_access';
use constant _action_regexp => qr'reject|do_it'i;
use constant _context_class => 'Sympa::List';
......
......@@ -61,8 +61,8 @@ sub _twist {
foreach my $list (@{Sympa::List::get_lists($robot) || []}) {
my $result =
Sympa::Scenario::request_action($list, 'visibility', $auth_method,
$self->{scenario_context});
Sympa::Scenario->new($list, 'visibility')
->authz($auth_method, $self->{scenario_context});
my $action;
$action = $result->{'action'} if ref $result eq 'HASH';
......
......@@ -61,8 +61,8 @@ sub _twist {
$listname = $list->{'name'};
my $result =
Sympa::Scenario::request_action($list, 'visibility', $auth_method,
$self->{scenario_context});
Sympa::Scenario->new($list, 'visibility')
->authz($auth_method, $self->{scenario_context});
my $action;
$action = $result->{'action'} if ref $result eq 'HASH';
......
This diff is collapsed.
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