Skip to content

Commit

Permalink
Merge pull request #1881 from ikedas/adam12b1/web-invite by adam12b1
Browse files Browse the repository at this point in the history
(AB) add an invite feature to WWSympa (#648)
  • Loading branch information
ikedas committed Aug 25, 2024
2 parents 03254d5 + 1d34341 commit 8d7164b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
7 changes: 6 additions & 1 deletion default/web_tt2/import.tt2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- import.tt2 -->
<form action="[% path_cgi %]" method="POST" class="add-request" name="multipleadd">
<input type="hidden" name="list" value="[% list %]" />
<input type="hidden" name="previous_action" value="[% action %]" />
<div>
<textarea name="dump" id="dump" cols="80" rows="25"
data-tooltip aria-haspopup="true"
Expand All @@ -15,7 +16,11 @@
<label for="quiet">[%|loc%]quiet[%END%]</label>
[% END ~%]
<input class="MainMenuLinks" type="submit" name="action_import"
value="[%|loc%]Add subscribers[%END%]" />
value="[%|loc%]Add[%END%]" />
</div>
<div>
<input class="MainMenuLinks" type="submit"
name="action_invite" value="[%|loc%]Invite[%END%]" />
</div>
</form>
<!-- end import.tt2 -->
4 changes: 4 additions & 0 deletions default/web_tt2/review.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
<input class="MainMenuLinks" type="submit"
name="action_add" value="[%|loc%]Add[%END%]" />
</div>
<div>
<input class="MainMenuLinks" type="submit"
name="action_invite" value="[%|loc%]Invite[%END%]" />
</div>
</fieldset>
</form>
<h4>[%|loc%]To add multiple users:[%END%]</h4>
Expand Down
77 changes: 77 additions & 0 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ our %comm = (
'sso_login' => 'do_sso_login',
'sso_login_succeeded' => 'do_sso_login_succeeded',
'stats' => 'do_stats',
'invite' => 'do_invite',
'subindex' => 'do_subindex',
'suboptions' => 'do_suboptions',
'subscribe' => 'do_subscribe',
Expand Down Expand Up @@ -16634,6 +16635,82 @@ sub _add_in_blocklist {

}

# web invite function (code adapted from do_add() and do_import()):
sub do_invite {

# Access control.
unless (defined check_authz('do_invite', 'invite')) {
add_stash('user', 'Invite not allowed');
return 'review';
}

my @emails;

# address for single user (from review.tt2) is in $in{email}:
if ($in{'email'}) {
@emails =
grep {$_} map { Sympa::Tools::Text::canonic_email($_) }
split /\0/, $in{'email'};
$log->syslog('info', 'single invite "%s"', join(' ',@emails));
unless (@emails) {
add_stash('user', 'no_email');
return 'review';
}
} else { # addresses for multiple users (from import.tt2) are $in{dump}
foreach (split /\r\n|\r|\n/, $in{'dump'}) {
next unless /\S/;
next if /\A\s*#/; #FIXME: email address can contain '#'

my ($email) = m{\A\s*(\S+)(?:\s+(.*))?\s*\z};
push @emails, $email;
}
$log->syslog('info', 'multiple invite "%s"', join(' ',@emails));
unless (@emails) {
add_stash('user', 'no_email');
return 'import';
}
}

$param->{'email'} = [@emails];

my $stash = [];
my $processed = 0;
foreach my $email (@emails) {
$log->syslog('info', 'do_invite working on %s', $emails[0]);
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'invite',
email => $email,
sender => $param->{'user'}{'email'},
md5_check => 1,
scenario_context => {
email => $email,
sender => $param->{'user'}{'email'},
remote_host => $param->{'remote_host'},
remote_addr => $param->{'remote_addr'}
},
stash => $stash,
);
$spindle and $processed += $spindle->spin;
}
unless ($processed) {
return $in{'previous_action'} || 'review';
}

foreach my $report (@$stash) {
if ($report->[1] eq 'notice') {
add_stash('notice', @{$report}[2, 3]);
} else {
add_stash(@{$report}[1 .. 3]);
}
}
unless (@$stash) {
add_stash('notice', 'performed');
}

return $in{'previous_action'} || 'review';
}

__END__

=encoding utf-8
Expand Down

0 comments on commit 8d7164b

Please sign in to comment.