Open Salo15 opened 5 years ago
I'm glad to find this issue already existing - it is very strange to not have the invite function in the WWSympa interface! So we added one, and I will offer our patch here, but I'm sure Soji will want to improve it in various ways (for example, we were not able to get the confirmation step working the way it does when adding or removing subscribers). I hope this is helpful somehow.
Obviously the biggest patch is to wwsympa.fcgi
itself, but you also need to add the feature to the review.tt2
and import.tt2
templates. Individual context diffs for each file, starting from the Sympa 6.2.72 code:
*** review.tt2.orig Wed May 29 10:02:57 2024
--- review.tt2 Wed May 29 10:02:02 2024
***************
*** 101,106 ****
--- 101,108 ----
<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>
*** import.tt2.orig Wed May 29 10:03:07 2024
--- import.tt2 Wed May 29 10:04:15 2024
***************
*** 16,21 ****
--- 16,23 ----
[% 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 -->
*** wwsympa.fcgi.orig Wed May 29 09:51:06 2024
--- wwsympa.fcgi Wed May 29 09:59:45 2024
***************
*** 291,296 ****
--- 291,299 ----
'set_lang' => 'do_set_lang',
'attach' => 'do_attach',
'stats' => 'do_stats',
+ #---acb: add web-based invite
+ 'invite' => 'do_invite',
+ #---acb end
'viewlogs' => 'do_viewlogs',
'wsdl' => 'do_wsdl',
'sync_include' => 'do_sync_include',
***************
*** 16896,16901 ****
--- 16899,16981 ----
close $fh;
}
+ #---acb: need a web invite function
+ # (code mostly stolen 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';
+ }
+ #---acb end
__END__
Hi @adam12b1 , thank you for improvement! Could you please submit a pull request?
Hi @adam12b1 , thank you for improvement! Could you please submit a pull request?
Oh, thank you for the response, yes I will... I just have to figure out how to do that! I'm not a real developer. :) But I will work on it when I have some time.
@adam12b1 , now you have your own fork and you're a real developer!
You'd be better to create a branch for PR on your fork and to work there. See also documentation on GitHub.
Thank you @ikedas for the guidance, I think maybe I got it right now?
Please let me know if there are any other conventions I should follow for PR, as I have a big stack of other bug fixes and features to submit when I have time.... :)
The invitation mechanism should also be able to be initiated from the advertising side.
Expected Behavior
On the Sympa website of a list, it should be possible to invite users to the list (of course only for those users who have permission to invite users to the list).
Current Behavior
The Invite mechanism can only be used by email command. Or is it already possible to invite users via the website and I just haven't found this function yet (in version 6.2.16)?
Possible Solution
Alternatively, it should be possible to send Sympa commands via the website.
Context
We have received several requests from users how to invite users to a list via the website.