-
Notifications
You must be signed in to change notification settings - Fork 443
First version of moderation emails #9587
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
base: main
Are you sure you want to change the base?
Conversation
ede5484
to
7141ba1
Compare
7141ba1
to
d67bafa
Compare
@@ -58,6 +58,10 @@ def includeme(config): # noqa: PLR0915 | |||
"admin.email.preview.mention_notification", | |||
"/admin/email/preview/mention-notification", | |||
) | |||
config.add_route( |
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.
New route to preview the email.
@@ -26,23 +46,27 @@ def set_status( | |||
annotation: Annotation, | |||
status: ModerationStatus | None, | |||
user: User | None = None, | |||
) -> None: | |||
) -> ModerationLog | None: |
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.
Refactor this method to return the resulting log entry.
report_exception(err) | ||
|
||
@staticmethod | ||
def email_subject(group_name: str, new_status: ModerationStatus) -> str: |
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.
Using regular python (instead of template logic) for these.
Easier to test them IMO.
@@ -0,0 +1,722 @@ | |||
<!doctype html> |
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 consider using a base template for these like in LMS.
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.
If it's looking the same as for mention emails, yes, I think we should extract a common layout at some point.
from .base import ModelFactory | ||
|
||
|
||
class ModerationLog(ModelFactory): |
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.
Missing factory for this model.
return f"Your comment in {group_name} is pending approval" | ||
|
||
msg = f"Unexpected moderation status change to {new_status}" # pragma: no cover | ||
raise ValueError(msg) |
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.
This shouldn't be possible because we check the states for which we send emails but just in case we make a mistake we don't want to send an email with an empty subject or description.
return { | ||
"user_display_name": "Jane Doe", | ||
"status_change_description": AnnotationModerationService.email_status_change_description( | ||
"GROUP NAME", ModerationStatus.APPROVED |
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.
These would be nicer if we had a simple dropdown to be able to preview different statuses.
Added a card to the board to track that.
h/models/notification.py
Outdated
@@ -20,6 +20,7 @@ class EmailTag(StrEnum): | |||
RESET_PASSWORD = "reset_password" # noqa: S105 | |||
MENTION_NOTIFICATION = "mention_notification" | |||
TEST = "test" | |||
MODERATED = "moderated_notification" |
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.
New email tag.
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.
The rest of the entries seem to be nouns. Maybe this one should be MODERATION
instead of MODERATED
?
user_id=author.userid, type_=Subscriptions.Type.MODERATED | ||
), | ||
), | ||
"preferences_url": request.route_url("account_notifications"), |
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.
This URL still doesn't list this type of email, added a card to the board about it.
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.
Looks good in general, but I suggested we use nouns as in "moderation" or "annotation moderation" instead of "moderated" or "moderated annotation" in various places.
It sounds more natural and is more consistent with other types of events and notifications.
h/models/notification.py
Outdated
@@ -20,6 +20,7 @@ class EmailTag(StrEnum): | |||
RESET_PASSWORD = "reset_password" # noqa: S105 | |||
MENTION_NOTIFICATION = "mention_notification" | |||
TEST = "test" | |||
MODERATED = "moderated_notification" |
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.
The rest of the entries seem to be nouns. Maybe this one should be MODERATION
instead of MODERATED
?
return f"Your comment in {group_name} has been declined" | ||
|
||
if new_status == ModerationStatus.APPROVED: | ||
return f"Your comment in {group_name} has been approved" | ||
|
||
if new_status == ModerationStatus.PENDING: | ||
return f"Your comment in {group_name} is pending approval" | ||
|
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.
Should we say "comment" or "annotation"?
I know we use the "comment" terminology in other places, but maybe it's worth discussing with the wider group. It should not block merging this PR though.
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.
You're right, I didn't address this in a comment.
TLDR (IMO): we can merge this version, and I’ll link to this comment from the board. I already have a vague "Send moderation emails in non-pre-moderated groups" card there, but I reckon most of the work there will be this issue.
The "comment" wording is what bioRxiv wants, so we’ll start with that. This PR only sends emails for pre-moderated groups, which are only offered to bioRxiv, so this will work for them.
Of course, we’ll want to send these in all cases eventually, so we have a few options:
-
Use the "comment" wording everywhere.
I don't like this. It would be odd if this were the only place where annotations become comments. -
Convince bioRxiv to use “annotation” instead.
I don't think this is likely. -
Use the "comment" wording everywhere, but just for "page notes".
Not ideal to use bothpage note
andcomment
for the same thing, but this would be easy to implement. -
Use different templates or a conditional to show
comment
for bioRxiv andannotation
for others.
While this seems like the obvious solution, I’m not sure how we’d determine this—by authority? Organization? The group the annotation is in?
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.
Following my previous comments, maybe this file should be named annotation_moderation_notification.html.jinja2
@@ -0,0 +1,722 @@ | |||
<!doctype html> |
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.
If it's looking the same as for mention emails, yes, I think we should extract a common layout at some point.
1c8384b
to
e9e353c
Compare
- Templates for moderation emails - Emit a ModerationEvent on the set_status view - Preview moderation emails on the admin pages
e9e353c
to
95971a3
Compare
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.
👍🏼
Send emails on moderation status changes
Docs
Follow up tasks (in the project board)
Testing
Check the email template render in http://localhost:5000/admin/email
In a pre moderated group, create an annotation (or grab the ID of an existing one), with curl we can test the email sending:
In the console you'll see traces of the email being "sent":