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

(AB) add an invite feature to WWSympa #1849

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions default/web_tt2/import.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
[% END ~%]
<input class="MainMenuLinks" type="submit" name="action_import"
value="[%|loc%]Add subscribers[%END%]" />
or <input class="MainMenuLinks" type="submit"
name="action_invite" value="Invite" />
</div>
</form>
<!-- end import.tt2 -->
2 changes: 2 additions & 0 deletions default/web_tt2/review.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<div>
<input class="MainMenuLinks" type="submit"
name="action_add" value="[%|loc%]Add[%END%]" />
or <input class="MainMenuLinks" type="submit"
name="action_invite" value="Invite" />
</div>
</fieldset>
</form>
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 @@ -16641,6 +16642,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