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

accessing db_additional_subscriber_fields fields in footer vs. tt2 templates #1494

Closed
igoltz opened this issue Oct 11, 2022 · 11 comments · Fixed by #1495
Closed

accessing db_additional_subscriber_fields fields in footer vs. tt2 templates #1494

igoltz opened this issue Oct 11, 2022 · 11 comments · Fixed by #1495
Labels
bug ready A PR is waiting to be merged. Close to be solved
Milestone

Comments

@igoltz
Copy link

igoltz commented Oct 11, 2022

Accessing db_additional_subscriber_fields fields in footer works but fails within tt2 templates

Version

6.2.68

Installation method

from source

Expected behavior

user.optout_uuid should be parsed and populated with data in footer and tt2 template files (e.g. welcome.tt2)

Actual behavior

user.optout_uuid returns nothing in tt2 template files

Steps to reproduce

  1. modify sympa database
alter table subscriber_table add column optout_uuid varchar(64) default(uuid());
  1. add optout_uuid to db_additional_subscriber_fields parameter in
/etc/sympa/sympa.conf

...
db_additional_subscriber_fields optout_uuid
...
  1. use new subscriber field in footer
    3.1 create/modify footer and enable it in list
/var/lib/sympa/list_data/robot/list/message_footer

...
[% wwsympa_url %][% 'auto_signoff' | url_abs([listname], {email => user.email, uuid =>user.optout_uuid}) %]
...

3.2 send mailing
Result: URL is created and uuid param is correctly filled (&uuid=123456xyz)

  1. use new subscriber field in welcome message
    4.1 modify welcome.tt2 for the list
/var/lib/sympa/list_data/robot/list/mail_tt2/welcome.tt2

...
[% wwsympa_url %][% 'auto_signoff' | url_abs([listname], {email => user.email, uuid =>user.optout_uuid}) %]
...

4.2 subscribe to list
Result: URL is created but uuid param is empty (&uuid=)

@igoltz igoltz added the bug label Oct 11, 2022
@ikedas
Copy link
Member

ikedas commented Oct 11, 2022

Just for clarification: When is the optout_uuid field in the subscriber_table set the value in each case?
In the case of footer, the subscriber has already had the row in the table and the field may be filled in advance.
But in the case of welcome message, it seems to me that the field cannot be filled, since the subscriber has not had the row in the table and the message is sent as soon as it is added.

@igoltz
Copy link
Author

igoltz commented Oct 11, 2022

That would mean the subscriber is not persisted to the database yet but the welcome message already sent out, right?
Yes this would explain the behaviour.
How to find out what exactly it the process during subscriber creation and how could the field populated before sending the welcome messag?

@ikedas
Copy link
Member

ikedas commented Oct 11, 2022

How to find out what exactly it the process during subscriber creation and how could the field populated before sending the welcome messag?

my @stash;
$list->add_list_member(
{email => $email, gecos => $comment, custom_attribute => $ca},
stash => \@stash);
foreach my $report (@stash) {
$self->add_stash($request, @$report);
if ($report->[0] eq 'intern') {
Sympa::send_notify_to_listmaster(
$list,
'mail_intern_error',
{ error => $report->[1], #FIXME: Update listmaster tt2
who => $sender,
action => 'Command process',
}
);
}
}
return undef if grep { $_->[0] eq 'user' or $_->[0] eq 'intern' } @stash;
my $user = Sympa::User->new($email);
$user->lang($list->{'admin'}{'lang'}) unless $user->lang;
$user->save;
## Now send the welcome file to the user
$request->{quiet} = ($Conf::Conf{'quiet_subscription'} eq "on")
if $Conf::Conf{'quiet_subscription'} ne "optional";
unless ($request->{quiet}) {
unless ($list->send_probe_to_user('welcome', $email)) {
$log->syslog('notice', 'Unable to send "welcome" probe to %s',
$email);
}
}

In above, add_list_member() method adds the user, i.e. adds a row for subscriber to subscriber_table, and then send_probe_to_user() method sends a message using welcome.tt2 to the subscriber who is added just now.

@igoltz
Copy link
Author

igoltz commented Oct 11, 2022

In this case the row already exists in database, the column has a default which is used on insert. Thus the field should be populated when sending the welcome message, correct?
Probably we now have to check whats happening in $list->send_probe_to_user('welcome', $email)

@ikedas
Copy link
Member

ikedas commented Oct 11, 2022

I overlooked default(). So what type and version of RDBMS you are using?

@igoltz
Copy link
Author

igoltz commented Oct 12, 2022

The database is MariaDB 10.5
Subscribers get the column filled on inserting, the value is shown in the GUI.
Maybe the user object in Sympa is not refreshed from database in the subscribe process?

@ikedas
Copy link
Member

ikedas commented Oct 12, 2022

@igoltz , I could reproduce it.

Could you please apply this patch and check if the problem solved?

And note: Subscriber's information is included in subscriber template variable. Use subscriber.optout_uuid instead of user.optout_uuid.

@igoltz
Copy link
Author

igoltz commented Oct 12, 2022

@ikedas , thank you very much. I patch and test asap!
Documentation about Sympa templates is here but probably we missed other pages. Could you please point us to them.
And whats the difference between user and subscriber? I think user is the global entry with address and maybe password, subscriber the list specific entry.

@ikedas
Copy link
Member

ikedas commented Oct 12, 2022

The variable subscriber is undocumented. However it was available before the code had been broken (See here in 6.2alpha).

I don't know why footer and template give different set of variables (it looks simply due to a lack of consideration). Such inconsistencies should be fixed in the future, but for now we'd be better just to fix the code that has not been working.

@igoltz
Copy link
Author

igoltz commented Oct 13, 2022

@ikedas
I confirm that the patch works. But one must use subscriber.optout_uuid in tt2.
May the documentation get an update about this too please. Thank you!

@ikedas ikedas added the ready A PR is waiting to be merged. Close to be solved label Nov 2, 2022
@racke racke added this to the 6.2.72 milestone Nov 5, 2022
@ikedas
Copy link
Member

ikedas commented Nov 16, 2022

The fix was merged. @igoltz , thank you for reporting bug!

A separate issue will be submitted for inconsistencies in the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ready A PR is waiting to be merged. Close to be solved
Projects
None yet
3 participants