localgovdrupal / localgov_workflows

Default editorial workflow for LocalGov Drupal content.
GNU General Public License v2.0
0 stars 1 forks source link

Send review notifications to service contacts #74

Closed stephen-cox closed 3 months ago

stephen-cox commented 7 months ago

Adds a service contact entity that can be associated with nodes and sends notifications to service contact when content passes it's needs review date.

Fixes #12

stephen-cox commented 4 months ago

To test this PR:

Install and enable the localgov_workflows_notifications module:

composer require localgovdrupal/localgov_workflows:"dev-feature/1.x/12-review-emails as 1.2.3"
drush en localgov_workflows_notifications localgov_review_date

Create some service contacts at /admin/content/localgov-service-contact and then associate them with a node.

On the node, check the 'content reviewed' box and set the review date to yesterday.

Then run:

drush sset localgov_workflows_notifications.last_email_run 0
drush cron
finnlewis commented 4 months ago

@Adnan-cds is half way through reviewing this.... others encouraged to help review.

Adnan-cds commented 4 months ago

Results from testing so far:

stephen-cox commented 3 months ago

Thanks for looking @Adnan-cds

I would have just used Drupal's user accounts as Service contacts instead of adding a new Entity type

This came out of the discussion early on. Some councils have all their users in the site, some don't. This should cover both setups.

None of the user roles has any of the Service contact management permissions. Perhaps the "Editor" and "User manager" role should be given some permissions.

Good catch. Will add permissions. Certainly to the editor role. Not sure about the user manager, as this user currently only has permissions to create users with certain roles.

Will need an install hook to add the permissions to editors.

The UX would be better if there were a visual clue to indicate it is either a Drupal user or an external user.

Do you have anything in mind for this? I have added some text to explain it and disabled the other fields once text is added to one field, but not sure what else can be added to make this clear.

I'll address the bugs this morning.

stephen-cox commented 3 months ago

@Adnan-cds

I have added a hook to add permissions to view and manage service contacts. Editors have permissions to manage them. Authors and contributors have permissions to view them so they can be added and removed from content.

Under Claro, the Service contact widget is overstretched

I'm not seeing this on a fresh LGD install. Can you provide more information on your install?

image

It would be good if the helptext of the Service contact widget in node edit forms briefly explains what it is for.

I've updated the message to 'Associate service contacts with this content by searching by name or email.'

After adding a Service contact to an unpublished Guide page and then setting its review date to yesterday, drush cron suffered a PHP error :(

Unfortunately, I'm not seeing this either with a fresh install and the demo module. I assume you're testing this on an existing site.

The error message indicates an issue with the Review Date entity. If there's no entity associated with the review date then the getEntity command fails as it returns NULL. As we're checking for this anyway, I have updated the code to allow NULL returns, which should fix the error you're seeing.

Can you test again with the latest changes?

Adnan-cds commented 3 months ago

I have added a hook to add permissions to view and manage service contacts. Editors have permissions to manage them. Authors and contributors have permissions to view them so they can be added and removed from content.

Thanks. Looks good.

Under Claro, the Service contact widget is overstretched I'm not seeing this on a fresh LGD install. Can you provide more information on your install?

This is no longer happening. Thanks again :)

It would be good if the helptext of the Service contact widget in node edit forms briefly explains what it is for. I've updated the message to 'Associate service contacts with this content by searching by name or email.'

Thanks. It still doesn't fully hint at what these Service contacts are for. Adding another sentence such as "They will receive review reminders" may bring more clarity.

After adding a Service contact to an unpublished Guide page and then setting its review date to yesterday, drush cron suffered a PHP error :( The error message indicates an issue with the Review Date entity. If there's no entity associated with the review date then the getEntity command fails as it returns NULL. As we're checking for this anyway, I have updated the code to allow NULL returns, which should fix the error you're seeing.

No fatal error any more. Thanks a lot :)

Can you test again with the latest changes?

It works!

Adnan-cds commented 3 months ago

The UX would be better if there were a visual clue to indicate it is either a Drupal user or an external user. Do you have anything in mind for this?

Something like the following would be good. But this is not a must-have. Once the question of whether or not to bundle Symfony mailer with this change is resolved, I am happy for it to be merged. screenshot-service-contact-add-form-ux-improvement-proposal

finnlewis commented 3 months ago

Sounds like https://www.drupal.org/project/symfony_mailer is the way... and allows people full flexibility over how they configure the transport.

I will test and have a think reflecting on the comments above.

Questions:

  1. do we force people to use Symfony Mailer?
  2. If so, do we include it as a part of the localgov profile or localgov_core for consistency?
  3. Do we write some code to accommodate people who are using other emailing solutions?
finnlewis commented 3 months ago

Worth testing with

Adnan-cds commented 3 months ago

Worth testing with

Installed the new localgov_workflows_notifications submodule on an existing site that's been using the smtp module and symfony_mailer has indeed taken over from the smtp module.

On the upside, the Webform module whitelists symfony_mailer for sending out attachments. So there should not be any loss of functionality for Webforms at least.

finnlewis commented 3 months ago

Can we add a check / warning with

Such that: if any of these modules are installed: (smtp / mailsystem / phpmailer) - warn the user that we will install symfony_mailer and we are taking over.

Or, notify the user (developer) on install, regarding of the other modules installed?

stephen-cox commented 3 months ago

@finnlewis @Adnan-cds There's now a warning message if enabling this and a conflicting module is already enabled:

https://github.com/localgovdrupal/localgov_workflows/blob/f7b720b067db7576f8c43ee0fc1743c422573cd6/modules/localgov_workflows_notifications/localgov_workflows_notifications.install#L13-L25

And a warning added to the top of the README

https://github.com/localgovdrupal/localgov_workflows/blob/e6d90c1413e2ddc443ef0a9a07de03c5453c050b/modules/localgov_workflows_notifications/README.md?plain=1#L7-L17

Do you think this sufficient warning about the potential email changes?

Adnan-cds commented 3 months ago

Do you think this sufficient warning about the potential email changes?

I can live with this. Thanks for this. I will test again and see how it goes.