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
Implements possibility to unsubscribe from email reports #13214
Conversation
Thanks for the PR! Feedback after a quick review:
|
@mattab I'll implement a Nonce in the unsubscription form, that should help avoiding iterating automatically over possible tokens (which have up to 100 chars). For sure we could also update the subscription when the reports are added/updated. I've Implemented it that way to ensure a subscription is created/available if an email is sent. Otherwise it might happen that for example third party plugins somehow manipulate reports without calling a method that updates the subscriptions. |
Came up w/ one question that probably only @mattab can answer: Is it important for admins to see who unsubscribed? |
@diosmosis Thought about that as well. Will add an event triggered when someone unsubscribes from a report. That way we can at least show it in the Activity Log |
It may be needed to keep trace of those who unsubscribed. Would it maybe work to have a column in the table "subscribed" or so and set it to 0 when not? This way we could have the data who has unsubscribed, which later we may show in the UI maybe. But probably only showing this info in the activity log is required for now? |
@mattab I've pushed an update. The table now also includes two columns with timestamps for subscription and unsubscription date. When someone unsubscribes the unsubscription date will be set, and the token will be nulled. If the email is readded in the report this entry will be overwritten with a new one (with unset unsubscribe date). That way we could later show a list of emails that unsubscribed or maybe even block readding unsubscribed emails in report admin. |
|
||
public function unsubscribe($token) | ||
{ | ||
$details = $this->getSubscription($token); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here need to check that the subscription details are returned?
Request::processRequest('ScheduledReports.updateReport', [ | ||
'idReport' => $report['idreport'], | ||
'idSite' => $report['idsite'], | ||
'description' => $report['description'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed to pass again all the other values like description, period, hour, etc. except idReport/idSite/parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. the parameters are all required for the update method. See https://github.com/matomo-org/matomo/blob/3.x-dev/plugins/ScheduledReports/API.php#L139
|
||
public function updateReportSubscriptions($idReport, $emails) | ||
{ | ||
$availableSubscriptions = $this->getReportSubscriptions($idReport); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe return an error if subscription not found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. the method is also used to initially set the subscriptions.
</div> | ||
<nav> | ||
<div class="nav-wrapper"> | ||
<span id="logo" class="brand-logo center"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to not duplicate the logo include code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could extract it into another template and include it into both. but we also have similar implementations in all layout.twig files (morpheus, updater, ...)
Update looks great @sgiehl 👍 Just left a few comments, let me know if these could be applied soon? |
|
||
foreach ($subscriptions as $subscription) { | ||
$tokens[$subscription['email']] = $subscription['token']; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this could be shortened to $tokens = array_column($subscriptions, 'token', 'email');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really important, just fyi
return reset($reports); | ||
}); | ||
|
||
if (empty($report)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case where there's no report for a subscription, should the subscription be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: think this is an edge case, so could put this in a new ticket if important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
* Implements possibility to unsubscribe from reports * Use a nonce for better security * post event if someone unsubscribes * various improvements and tests * store information about unsubscribed reports until they are resubscribed * code improvements
This is a POC for report unsubscriptions. Maybe someone could have a look if the implementation is fine that way.
Would add tests and some more doc blocks and so on after a first review...
fixes #2197