Commit 59fcf4ff authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring.

- Now Sympa::List::update_list_member() allows plain hash as options.
- It no longer updates user_table.
- encoding/decoding custom attribute occurs in it.
and a few other insignificant fixes.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12442 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 6f46bb9c
......@@ -2564,9 +2564,8 @@ sub get_parameters_old {
} elsif ($pname =~ /^custom_attribute(.*)$/) {
my $key = $tokens[1];
$regexp = $in_regexp{'custom_attribute'};
$log->syslog('debug2',
"get_parameters (custom_attribute) : ($p)($key) $pname $in{$p} $Conf::Conf{$key}{type}"
);
$log->syslog('debug3', '{%s}{%s} %s %s %s',
$p, $key, $pname, $in{$p}, $Conf::Conf{$key}{type});
$custom_attribute->{$key} = {value => $in{$p}};
undef $in{$p};
 
......@@ -5599,10 +5598,9 @@ sub do_set {
my ($reception, $visibility) = ($in{'reception'}, $in{'visibility'});
my $email;
 
my $xml_custom_attribute;
if ($in{custom_attribute}) {
return undef if (check_custom_attribute() != 1);
$xml_custom_attribute = Sympa::Tools::Data::encode_custom_attribute(
return undef
unless _check_custom_attribute($list, $param->{action},
$in{custom_attribute});
}
 
......@@ -5756,8 +5754,8 @@ sub do_set {
} else {
$update->{'gecos'} = undef;
}
$update->{'custom_attribute'} = $xml_custom_attribute
if $xml_custom_attribute;
$update->{'custom_attribute'} = $in{custom_attribute}
if $in{custom_attribute};
 
unless ($list->update_list_member($email, $update)) {
Sympa::Report::reject_report_web('intern',
......@@ -5785,20 +5783,26 @@ sub do_set {
 
## checks if each element of the custom attribute is conform to the list's
## definition
sub check_custom_attribute {
# Old name: check_custom_attribute() in wwsympa.fcgi.
# TODO: This would be moved to a method of appropriate class.
sub _check_custom_attribute {
my $list = shift;
my $action = shift;
my $custom_attribute = shift;
 
my @custom_attributes = @{$list->{'admin'}{'custom_attribute'}};
my $isOK = 1;
 
foreach my $ca (@custom_attributes) {
my $value = $in{custom_attribute}{$ca->{id}}{value};
if ($ca->{optional} eq 'required' && $value eq '') {
my $value = $custom_attribute->{$ca->{id}}{value};
if ( $ca->{optional}
and $ca->{optional} eq 'required'
and not(defined $value and length $value)) {
Sympa::Report::reject_report_web('user', 'missing_arg',
{'argument' => "\"$ca->{name}\" is required"},
$param->{'action'});
wwslog('info', 'Missing parameter');
{'argument' => $ca->{name}}, $action);
wwslog('info', 'Missing parameter "%s"', $ca->{id});
web_db_log(
{ 'parameters' => "$in{'reception'},$in{'visibility'}",
{ 'parameters' => $ca->{id},
'status' => 'error',
'error_type' => 'missing_parameter'
}
......@@ -5807,23 +5811,22 @@ sub check_custom_attribute {
next;
}
 
## No further checking if attribute if empty
next if ($value =~ /^$/);
# No further checking if attribute is empty.
next unless defined $value and length $value;
 
my @values = split(/,/, $ca->{'enum_values'})
if (defined $ca->{'enum_values'});
my @values = split /,/, $ca->{enum_values}
if defined $ca->{enum_values};
 
## Check that the parameter has the correct format
unless (($ca->{'type'} eq 'enum' && grep(/^$value$/, @values))
|| ($ca->{'type'} eq 'integer' && $value =~ /^\d+$/)
|| ($ca->{'type'} eq 'string' && $value =~ /^.+$/)
|| ($ca->{'type'} eq 'text' && $value =~ /^.+$/m)) {
unless (($ca->{type} eq 'enum' and grep { $value eq $_ } @values)
or ($ca->{type} eq 'integer' and $value =~ /\A\d+\z/)
or ($ca->{type} eq 'string' and $value =~ /\A.+\z/)
or ($ca->{type} eq 'text' and length $value)) {
Sympa::Report::reject_report_web('user', 'syntax_errors',
{'params' => $ca->{name}},
$param->{'action'});
wwslog('info', 'Syntax error');
{'params' => $ca->{name}}, $action);
wwslog('info', 'Syntax error in parameter "%s"', $ca->{id});
web_db_log(
{ 'parameters' => $ca->{name},
{ 'parameters' => $ca->{id},
'status' => 'error',
'error_type' => 'missing_parameter'
}
......@@ -5965,24 +5968,22 @@ sub do_subscribe {
 
return undef if purely_closed('subscribe'); #FIXME: mv this to Scenario
if ($param->{'user'} and $param->{'user'}{'email'}) {
my $xml_custom_attribute;
if ($list->{'admin'}{'custom_attribute'}) {
## This variable is set in the subrequest form
## If not set, it means that the user has not been prompted to
## provide custom_attributes
# This variable is set in the subrequest form.
# If not set, it means that the user has not been prompted to
# provide custom_attributes.
unless ($in{'via_subrequest'}) {
wwslog('notice', 'Returning subrequest form');
return "subrequest";
}
if (check_custom_attribute() != 1) {
unless (
_check_custom_attribute(
$list, $param->{action}, $in{custom_attribute}
)
) {
wwslog('notice', "Missing required custom attributes");
return 'subrequest';
}
$xml_custom_attribute =
Sympa::Tools::Data::encode_custom_attribute(
$in{custom_attribute});
}
 
if ($param->{'is_subscriber'}) {
......@@ -6062,9 +6063,8 @@ sub do_subscribe {
unless (
$list->update_list_member(
$param->{'user'}{'email'},
{ 'subscribed' => 1,
'update_date' => time
}
subscribed => 1,
update_date => time
)
) {
Sympa::Report::reject_report_web(
......@@ -6106,8 +6106,8 @@ sub do_subscribe {
);
return undef;
}
$u->{'custom_attribute'} = $xml_custom_attribute
if (defined $xml_custom_attribute);
$u->{custom_attribute} = $in{custom_attribute}
if $in{custom_attribute};
$u->{'lang'} = $param->{'user'}{'lang'} || $param->{'lang'};
$u->{'parameter'} = 'manual subscription';
 
......@@ -6312,12 +6312,11 @@ sub do_suboptions {
 
## Subscription request (user not authenticated)
sub do_subrequest {
wwslog('info', '(%s, %s)', $in{'email'}, $in{'custom_attribute'});
wwslog('info', '(%s, %s)', $in{'email'}, $in{custom_attribute});
 
return undef if (purely_closed('subscribe'));
if (defined $in{'custom_attribute'}) {
$param->{'custom_attribute'} = $in{'custom_attribute'};
}
$param->{'custom_attribute'} = $in{custom_attribute}
if $in{custom_attribute};
 
## Auth ?
if ($param->{'user'}{'email'}) {
......@@ -11657,7 +11656,9 @@ sub do_resetbounce {
unless (
$list->update_list_member(
$email,
{'bounce' => 'NULL', 'update_date' => time, 'bounce_score' => 0}
bounce => undef,
update_date => time,
bounce_score => 0
)
) {
Sympa::Report::reject_report_web(
......
......@@ -1657,11 +1657,11 @@ sub change_user_email {
}
} else {
unless (
$list->update_list_member(
$in{'current_email'},
{'email' => $in{'new_email'}, 'update_date' => time}
email => $in{'new_email'},
update_date => time
)
) {
push @failed_for, $list;
......
......@@ -1232,21 +1232,20 @@ sub subscribe {
return 1;
}
if ($action =~ /do_it/i) {
my $user_entry = $list->get_list_member($sender);
if (defined $user_entry) {
# Only updates the date. Options remain the same.
my %update = (
update_date => time,
subscribed => 1,
);
$update{gecos} = $comment
if defined $comment and $comment =~ /\S/;
## Only updates the date
## Options remain the same
my $user = {};
$user->{'update_date'} = time;
$user->{'gecos'} = $comment if $comment;
$user->{'subscribed'} = 1;
unless ($list->update_list_member($sender, $user)) {
my $error = sprintf "Unable to update user %s in list %s",
$user, $list->{'name'};
unless ($list->update_list_member($sender, %update)) {
my $error = sprintf 'Unable to update user %s in list %s',
$sender, $list->{'name'};
Sympa::Report::reject_report_cmd('intern', $error,
{'listname' => $which},
$cmd_line, $sender, $robot);
......@@ -2816,10 +2815,12 @@ sub set {
}
my $update_mode = $mode;
$update_mode = '' if ($update_mode eq 'mail');
$update_mode = '' if $update_mode eq 'mail';
unless (
$list->update_list_member(
$sender, {'reception' => $update_mode, 'update_date' => time}
$sender,
reception => $update_mode,
update_date => time
)
) {
my $error =
......@@ -2842,7 +2843,9 @@ sub set {
if ($mode =~ /^(conceal|noconceal)/) {
unless (
$list->update_list_member(
$sender, {'visibility' => $mode, 'update_date' => time}
$sender,
visibility => $mode,
update_date => time
)
) {
my $error =
......
This diff is collapsed.
......@@ -42,7 +42,6 @@ use Sympa::Session;
use Sympa::Spool::Request;
use Sympa::Template;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::Password;
use Sympa::User;
......@@ -1507,20 +1506,16 @@ sub subscribe {
}
if ($is_sub) {
## Only updates the date
## Options remain the same
my $user = {};
$user->{'update_date'} = time;
$user->{'gecos'} = $gecos if $gecos;
$log->syslog('err', 'User already subscribed');
die SOAP::Fault->faultcode('Server')->faultstring('Undef.')
->faultdetail("SOAP subscribe : update user failed")
unless $list->update_list_member($sender, $user);
# Only updates the date. Options remain the same.
my %update = (update_date => time);
$update{gecos} = $gecos if defined $gecos and $gecos =~ /\S/;
unless ($list->update_list_member($sender, %update)) {
$log->syslog('err', 'User update failed');
die SOAP::Fault->faultcode('Server')->faultstring('Undef.')
->faultdetail("SOAP subscribe : update user failed");
}
} else {
my $u;
my $defaults = $list->get_default_user_options();
%{$u} = %{$defaults};
......@@ -1789,9 +1784,9 @@ sub setDetails {
}
# Set subscriber values; return 1 for success
%user = ();
$user{'gecos'} = $gecos if (defined $gecos);
$user{'reception'} = $reception
my %user;
$user{gecos} = $gecos if defined $gecos and $gecos =~ /\S/;
$user{reception} = $reception
# ideally, this should check against the available_user_options
# values from the $list config
if $reception
......@@ -1811,13 +1806,12 @@ sub setDetails {
$newcustom{$key}{value} = $value;
}
}
$user{'custom_attribute'} =
Sympa::Tools::Data::encode_custom_attribute(\%newcustom);
$user{'custom_attribute'} = \%newcustom;
}
die SOAP::Fault->faultcode('Server')
->faultstring('Unable to set user details')
->faultdetail("SOAP setDetails : update user failed")
unless $list->update_list_member($sender, \%user);
unless $list->update_list_member($sender, %user);
return SOAP::Data->name('result')->type('boolean')->value(1);
}
......@@ -1828,7 +1822,6 @@ sub setCustom {
my $list;
my $rv;
my %newcustom;
my %user;
my $sender = $ENV{'USER_EMAIL'};
my $robot = $ENV{'SYMPA_ROBOT'};
......@@ -1872,13 +1865,11 @@ sub setCustom {
# and defined $list->{'admin'}{'custom_attribute'};
$newcustom{$key}{value} = $value;
}
%user = ();
$user{'custom_attribute'} =
Sympa::Tools::Data::encode_custom_attribute(\%newcustom);
die SOAP::Fault->faultcode('Server')
->faultstring('Unable to set user attributes')
->faultdetail("SOAP setCustom : update user failed")
unless $list->update_list_member($sender, \%user);
unless $list->update_list_member($sender,
custom_attribute => \%newcustom);
return SOAP::Data->name('result')->type('boolean')->value(1);
}
......
......@@ -340,12 +340,8 @@ sub _update_subscriber_bounce_history {
}
$count++;
$self->{context}->update_list_member(
$bouncefor,
{ 'bounce' =>
sprintf('%s %s %s %s', $first, $last, $count, $status)
}
);
$self->{context}->update_list_member($bouncefor,
bounce => sprintf('%s %s %s %s', $first, $last, $count, $status));
}
return 1;
}
......
......@@ -1728,8 +1728,8 @@ sub expire_bounce {
unless (
$list->update_list_member(
$email,
{'bounce' => 'NULL'},
{'bounce_address' => 'NULL'}
bounce => undef,
bounce_address => undef
)
) {
$log->syslog('info', 'Failed update database for %s',
......@@ -1824,10 +1824,10 @@ sub eval_bouncers {
) {
my $score = get_score($user_ref, $list_traffic) || 0;
## copying score into DataBase
# Copying score into database.
unless (
$list->update_list_member(
$user_ref->{'email'}, {'bounce_score' => $score}
$user_ref->{'email'}, bounce_score => $score
)
) {
$log->syslog('err', 'Error while updating DB for user %s',
......
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