Commit 1920be54 authored by sikeda's avatar sikeda
Browse files

[-dev] Refactoring. send_notify_to_user() is moved from Sympa::List to Sympa package.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12459 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 7c4a8f39
......@@ -330,9 +330,9 @@ Subject: [% FILTER qencode %][%|loc(list.name)%]Listmaster: internal server erro
[%|loc%]See logs for more details.[%END%]
[% ELSIF type == 'hundred_percent_error' -%]
Subject: [% FILTER qencode %][%|loc(listname, listdomain)%]Listmaster: list %1@%2 at 100 percents error [%END%][%END%]
Subject: [% FILTER qencode %][%|loc(list.name, list.host)%]Listmaster: list %1@%2 at 100 percents error [%END%][%END%]
[%|loc(listname, listdomain)%]The list %1@%2 has 100 percents of its users in error. Something unusual must have happened.[%END%]
[%|loc(list.name, list.host)%]The list %1@%2 has 100 percents of its users in error. Something unusual must have happened.[%END%]
[%|loc(sender)%]The user %1, who tried to send a mail to this list, has been warned, as well as the list owners.[%END%]
......
......@@ -18,8 +18,8 @@ Deleted topic(s) is(are):[%END%]
[% t %]
[% END -%]
[%|loc(url)%]To update your topics subscription, go to the following page:
%1[% END %]
[%|loc%]To update your topics subscription, go to the following page:[%END%]
[% conf.wwsympa_url %]/suboptions/[% list.name %]
[% ELSIF type == 'added_as_listadmin' -%]
......
......@@ -6426,29 +6426,9 @@ sub do_auto_signoff {
## Send the confirmation email to the user.
 
if ($list->is_list_member($in{'email'})) {
my $ticket =
Sympa::Auth::create_one_time_ticket($in{'email'}, $robot,
'signoff/' . $list->{'name'}, $ip);
my $tt2_param = {
'list' => $list,
'type' => 'ticket_to_signoff',
'one_time_ticket' => $ticket,
'email' => $in{'email'},
'context' => 'auto_signoff',
'ip' => $ip,
};
unless (
Sympa::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
$log->syslog('notice',
"Unable to send template 'user_notification' to $in{'email'}"
);
return undef;
}
Sympa::send_notify_to_user($list, 'ticket_to_signoff', $in{'email'},
{context => 'auto_signoff', ip => $ip})
or return undef;
} else {
return Conf::get_robot_conf($robot, 'default_home');
}
......@@ -6460,38 +6440,24 @@ sub do_auto_signoff {
 
sub do_family_signoff_request {
wwslog('info', '');
## If the URL isn't valid, then go to home page. No need to guide the
## user: this function is supposed to be used by clicking on autocreated
## URL only.
# If the URL isn't valid, then go to home page. No need to guide the
# user: this function is supposed to be used by clicking on autocreated
# URL only.
return Conf::get_robot_conf($robot, 'default_home') unless $in{'email'};
my $family = Sympa::Family->new($in{'family'}, $robot);
return Conf::get_robot_conf($robot, 'default_home') unless $family;
Sympa::send_notify_to_user(
$robot,
'ticket_to_family_signoff',
$in{'email'},
{context => 'family_signoff', family => $family->{'name'}, ip => $ip}
) or return undef;
 
my $ticket =
Sympa::Auth::create_one_time_ticket($in{'email'}, $robot,
'family_signoff/' . $in{'family'} . '/' . $in{'email'}, $ip);
my $tt2_param = {
'family' => $in{'family'},
'type' => 'ticket_to_family_signoff',
'one_time_ticket' => $ticket,
'email' => $in{'email'},
'context' => 'family_signoff',
'ip' => $ip,
};
unless (
Sympa::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
$log->syslog('notice',
'Unable to send template "user_notification" to %s',
$in{'email'});
return undef;
}
$param->{'signing_off_email'} = $in{'email'};
$param->{'family'} = $in{'family'};
# If OK, return the page displaying the information to the user.
return 1;
}
 
sub do_family_signoff {
......@@ -6731,28 +6697,9 @@ sub do_sigrequest {
return 1;
}
if ($list->is_list_member($in{'email'})) {
my $ticket =
Sympa::Auth::create_one_time_ticket($in{'email'}, $robot,
'signoff/' . $list->{'name'}, $ip);
my $tt2_param = {
'type' => 'ticket_to_signoff',
'list' => $list,
'one_time_ticket' => $ticket,
'email' => $in{'email'}
};
unless (
Sympa::send_file(
$robot, 'user_notification', $in{'email'}, $tt2_param
)
) {
$log->syslog('notice',
"Unable to send template 'user_notification' to $in{'email'}"
);
return undef;
}
Sympa::send_notify_to_user($list, 'ticket_to_signoff', $in{'email'},
{ip => $ip})
or return undef;
} else {
$param->{'not_subscriber'} = 1;
}
......@@ -12444,15 +12391,14 @@ sub do_edit_list {
 
## Compare with new entries
foreach my $entry (@{$new_admin->{$admin_type}}) {
unless ($previous_emails{$entry->{'email'}}) {
## Notify the new list owner/editor
$list->send_notify_to_user(
# Notify the new list owner/editor
Sympa::send_notify_to_user(
$list,
'added_as_listadmin',
$entry->{'email'},
{ 'admin_type' => $admin_type,
'delegator' => $param->{'user'}{'email'}
{ admin_type => $admin_type,
delegator => $param->{'user'}{'email'}
}
);
Sympa::Report::notice_report_web('user_notified',
......@@ -20501,36 +20447,10 @@ sub do_delete_pictures {
sub do_change_email_request {
wwslog('info', '(%s)', $in{'new_email'});
 
unless (
$param->{'one_time_ticket'} = Sympa::Auth::create_one_time_ticket(
$in{'new_email'}, $robot,
'change_email/' . $param->{'user'}{'email'}, $ip
)
) {
$log->syslog('notice',
"Unable to create one_time_ticket for $in{'new_email'}, service do_change_email_request"
);
} else {
$log->syslog('notice', '%s', $param->{'one_time_ticket'});
}
$param->{'new_email'} = $in{'new_email'};
my $tt2_param = {
'type' => 'ticket_to_send',
'one_time_ticket' => $param->{'one_time_ticket'},
'to' => $in{'new_email'},
};
unless (
Sympa::send_file(
$robot, 'user_notification', $in{'new_email'}, $tt2_param
)
) {
$log->syslog('notice',
"Unable to send template 'user_notification' to $in{'new_email'}"
);
return undef;
}
Sympa::send_notify_to_user($robot, 'ticket_to_send', $in{'new_email'},
{email => $param->{'user'}{'email'}, ip => $ip})
or return undef;
return '1';
}
 
......
......@@ -859,6 +859,119 @@ sub send_notify_to_listmaster {
return 1;
}
=over
=item send_notify_to_user ( $that, $operation, $user, $param )
Send a notice to a user (sender, subscriber or another user)
by parsing user_notification.tt2 template.
Parameters:
=over
=item $that
L<Sympa::List>, Robot or Site.
=item $operation
Notification type.
=item $user
E-mail of notified user.
=item $param
Hashref or arrayref. Values for template parsing.
=back
Returns:
C<1> or C<undef>.
=back
=cut
sub send_notify_to_user {
$log->syslog('debug2', '(%s, %s, %s, ...)', @_);
my $that = shift;
my $operation = shift;
my $user = shift;
my $param = shift || {};
my ($list, $robot_id);
if (ref $that eq 'Sympa::List') {
$list = $that;
$robot_id = $list->{'domain'};
} elsif ($that and $that ne '*') {
$robot_id = $that;
} else {
$robot_id = '*';
}
$param->{'auto_submitted'} = 'auto-generated';
die 'Missing parameter "operation"' unless $operation;
die 'missing parameter "user"' unless $user;
if (ref $param eq "HASH") {
$param->{'to'} = $user;
$param->{'type'} = $operation;
if ($operation eq 'ticket_to_signoff') {
$param->{one_time_ticket} =
Sympa::Auth::create_one_time_ticket($user, $robot_id,
'signoff/' . $list->{'name'},
$param->{ip})
or return undef;
} elsif ($operation eq 'ticket_to_family_signoff') {
$param->{one_time_ticket} =
Sympa::Auth::create_one_time_ticket($user, $robot_id,
'family_signoff/' . $param->{family} . '/' . $user,
$param->{ip})
or return undef;
} elsif ($operation eq 'ticket_to_send') {
$param->{'one_time_ticket'} =
Sympa::Auth::create_one_time_ticket($user, $robot_id,
'change_email/' . $param->{email},
$param->{ip})
or return undef;
}
unless (Sympa::send_file($that, 'user_notification', $user, $param)) {
$log->syslog('notice',
'Unable to send template "user_notification" to %s', $user);
return undef;
}
} elsif (ref $param eq "ARRAY") {
my $data = {
'to' => $user,
'type' => $operation
};
for my $i (0 .. $#{$param}) {
$data->{"param$i"} = $param->[$i];
}
unless (Sympa::send_file($that, 'user_notification', $user, $data)) {
$log->syslog('notice',
'Unable to send template "user_notification" to %s', $user);
return undef;
}
} else {
$log->syslog(
'err',
'error on incoming parameter "%s", it must be a ref on HASH or a ref on ARRAY',
$param
);
return undef;
}
return 1;
}
=head3 Internationalization
=over
......@@ -1031,7 +1144,7 @@ Is the user listmaster?
# Old names: [6.2b-6.2.3] Sympa::Robot::is_listmaster($who, $robot_id)
sub is_listmaster {
my $that = shift;
my $who = Sympa::Tools::Text::canonic_email(shift);
my $who = Sympa::Tools::Text::canonic_email(shift);
return undef unless defined $who;
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email($that);
......
......@@ -1779,18 +1779,11 @@ sub distribute_msg {
my $rate = $self->get_total_bouncing() * 100 / $total;
if ($rate > $self->{'admin'}{'bounce'}{'warn_rate'}) {
$self->send_notify_to_owner('bounce_rate', {'rate' => $rate});
if ($rate == 100) {
$self->send_notify_to_user('hundred_percent_error',
$message->{'sender'});
Sympa::send_notify_to_listmaster(
$self->{'domain'},
'hundred_percent_error',
{ 'listname' => $self->{'name'},
'listdomain' => $self->{'domain'},
'sender' => $message->{'sender'}
}
)
if (100 <= $rate) {
Sympa::send_notify_to_user($self, 'hundred_percent_error',
$message->{sender});
Sympa::send_notify_to_listmaster($self, 'hundred_percent_error',
{sender => $message->{sender}});
}
}
......@@ -3096,72 +3089,8 @@ sub send_notify_to_editor {
return 1;
}
####################################################
# send_notify_to_user
####################################################
# Send a notice to a user (sender, subscriber ...)
# by parsing user_notification.tt2 template
#
# IN : -$self (+): ref(List)
# -$operation (+): notification type
# -$user(+): email of notified user
# -$param(+) : ref(HASH) | ref(ARRAY)
# values for template parsing
#
# OUT : 1 | undef
#
######################################################
sub send_notify_to_user {
my ($self, $operation, $user, $param) = @_;
$log->syslog('debug2', '(%s, %s, %s)', $self->{'name'}, $operation,
$user);
my $host = $self->{'admin'}->{'host'};
my $robot = $self->{'domain'};
$param->{'auto_submitted'} = 'auto-generated';
unless (defined $operation) {
die 'missing incoming parameter "$operation"';
}
unless ($user) {
die 'missing incoming parameter "$user"';
}
if (ref($param) eq "HASH") {
$param->{'to'} = $user;
$param->{'type'} = $operation;
if ($operation eq 'auto_notify_bouncers') {
}
unless (Sympa::send_file($self, 'user_notification', $user, $param)) {
$log->syslog('notice',
'Unable to send template "user_notification" to %s', $user);
return undef;
}
} elsif (ref($param) eq "ARRAY") {
my $data = {
'to' => $user,
'type' => $operation
};
for my $i (0 .. $#{$param}) {
$data->{"param$i"} = $param->[$i];
}
unless (Sympa::send_file($self, 'user_notification', $user, $data)) {
$log->syslog('notice',
'Unable to send template "user_notification" to %s', $user);
return undef;
}
} else {
$log->syslog('err',
'error on incoming parameter "$param", it must be a ref on HASH or a ref on ARRAY'
);
return undef;
}
return 1;
}
# Moved to Sympa::send_notify_to_user().
#sub send_notify_to_user;
=over
......@@ -10441,19 +10370,11 @@ sub modifying_msg_topic_for_list_members {
)
);
if ($#{$topics->{'intersection'}} >= 0) {
my $wwsympa_url =
Conf::get_robot_conf($self->{'domain'},
'wwsympa_url');
$self->send_notify_to_user(
'deleted_msg_topics',
if (@{$topics->{'intersection'}}) {
Sympa::send_notify_to_user(
$self, 'deleted_msg_topics',
$subscriber->{'email'},
{ 'del_topics' => $topics->{'intersection'},
'url' => sprintf(
'%s/suboptions/%s',
$wwsympa_url, $self->{'name'}
),
}
{del_topics => $topics->{'intersection'}}
);
unless (
$self->update_list_member(
......@@ -10895,14 +10816,14 @@ sub remove_bouncers {
# Sub for notifying users: "Be careful, you're bouncing".
sub notify_bouncers {
$log->syslog('debug2', '(%s, %s)', @_);
my $self = shift;
my $reftab = shift;
$log->syslog('debug', '(%s)', $self->{'name'});
foreach my $user (@$reftab) {
$log->syslog('notice', 'Notifying bouncing subsrciber of list %s: %s',
$self->{'name'}, $user);
$self->send_notify_to_user('auto_notify_bouncers', $user, {});
$self, $user);
Sympa::send_notify_to_user($self, 'auto_notify_bouncers', $user);
}
return 1;
}
......
Markdown is supported
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