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

Implements possibility to unsubscribe from email reports #13214

Merged
merged 6 commits into from Aug 6, 2018

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Jul 26, 2018

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

@sgiehl sgiehl added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. Needs Review PRs that need a code review labels Jul 26, 2018
@sgiehl sgiehl added this to the 3.6.0 milestone Jul 26, 2018
@mattab
Copy link
Member

mattab commented Jul 26, 2018

Thanks for the PR! Feedback after a quick review:

  • overall looks good to me, maybe @diosmosis or @tsteur have further thoughts?
  • maybe we need 2 tokens in the unsubscribe URL to be secure, otherwise one could write a script looping over all possible token values and unsubscribe everyone (after a very long time)? for example a hash of the idreport could maybe do..
  • instead of updating the subscriptions when sending emails, could we have the migration script do it once, and then have the other updateReport addReport etc. APIs update the list of subscriptions?
  • left few other comments

@sgiehl
Copy link
Member Author

sgiehl commented Jul 26, 2018

@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.

@diosmosis
Copy link
Member

Came up w/ one question that probably only @mattab can answer: Is it important for admins to see who unsubscribed?

@sgiehl
Copy link
Member Author

sgiehl commented Jul 27, 2018

@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

@mattab
Copy link
Member

mattab commented Jul 27, 2018

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?

@sgiehl sgiehl changed the title [POC] Implements possibility to unsubscribe from reports Implements possibility to unsubscribe from reports Aug 1, 2018
@sgiehl sgiehl removed the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Aug 1, 2018
@sgiehl
Copy link
Member Author

sgiehl commented Aug 1, 2018

@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);
Copy link
Member

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'],
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

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">
Copy link
Member

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?

Copy link
Member Author

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, ...)

@mattab
Copy link
Member

mattab commented Aug 2, 2018

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'];
}
Copy link
Member

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');

Copy link
Member

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)) {
Copy link
Member

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?

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@diosmosis diosmosis merged commit 70ca09f into 3.x-dev Aug 6, 2018
@diosmosis diosmosis deleted the subscriptions branch August 6, 2018 00:58
@mattab mattab added Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. labels Aug 28, 2018
@mattab mattab changed the title Implements possibility to unsubscribe from reports Implements possibility to unsubscribe from email reports Aug 28, 2018
InfinityVoid pushed a commit to InfinityVoid/matomo that referenced this pull request Oct 11, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to unsubscribe from Email reports (pdf, html, csv)
3 participants