-
Notifications
You must be signed in to change notification settings - Fork 351
[ENG-9793] update unregistered contributor notifications and email templates #11462
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
Open
Ostap-Zherebetskyi
wants to merge
1
commit into
CenterForOpenScience:feature/notification-refactor-p2-s
Choose a base branch
from
Ostap-Zherebetskyi:fix/invite_unreg_emails
base: feature/notification-refactor-p2-s
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1463,7 +1463,7 @@ def test_add_unregistered_contributor_sends_email( | |
| auth=user.auth | ||
| ) | ||
| assert len(notifications['emits']) == 1 | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT | ||
| assert res.status_code == 201 | ||
|
|
||
| def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_preprint_contribs): | ||
|
|
@@ -1483,7 +1483,7 @@ def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_pr | |
| ) | ||
| assert res.status_code == 201 | ||
| assert len(notifications['emits']) == 1 | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT | ||
|
|
||
| def test_add_contributor_invalid_send_email_param(self, app, user, url_preprint_contribs): | ||
| url = f'{url_preprint_contribs}?send_email=true' | ||
|
|
@@ -1564,23 +1564,7 @@ def test_contributor_added_signal_not_specified(self, app, user, url_preprint_co | |
| ) | ||
| assert res.status_code == 201 | ||
| assert len(notifications['emits']) == 1 | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT | ||
|
|
||
| def test_contributor_added_not_sent_if_unpublished(self, app, user, preprint_unpublished): | ||
| res = app.post_json_api( | ||
| f'/{API_BASE}preprints/{preprint_unpublished._id}/contributors/?send_email=preprint', | ||
| { | ||
| 'data': { | ||
| 'type': 'contributors', | ||
| 'attributes': { | ||
| 'full_name': 'Jalen Hurt', | ||
| 'email': '[email protected]' | ||
| } | ||
| } | ||
| }, | ||
| auth=user.auth | ||
| ) | ||
| assert res.status_code == 201 | ||
| assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT | ||
|
|
||
| @pytest.mark.django_db | ||
| class TestPreprintContributorBulkCreate(NodeCRUDTestCase): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1499,7 +1499,7 @@ def add_contributors( | |
| auth=None, | ||
| log=True, | ||
| save=False, | ||
| notification_type=NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT | ||
| notification_type=False, | ||
| ): | ||
| """Add multiple contributors | ||
|
|
||
|
|
@@ -1592,6 +1592,19 @@ def add_unregistered_contributor( | |
| else: | ||
| raise e | ||
|
|
||
| if notification_type is None: | ||
| from osf.models import AbstractNode, Preprint, DraftRegistration | ||
|
|
||
| if isinstance(self, AbstractNode): | ||
| notification_type = NotificationType.Type.USER_INVITE_DEFAULT | ||
| elif isinstance(self, Preprint): | ||
| if self.provider.is_default: | ||
| notification_type = NotificationType.Type.USER_INVITE_OSF_PREPRINT | ||
| else: | ||
| notification_type = NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT | ||
| elif isinstance(self, DraftRegistration): | ||
| notification_type = NotificationType.Type.USER_INVITE_DRAFT_REGISTRATION | ||
|
Comment on lines
+1598
to
+1606
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove "unused" comments in the types definition for these ones. |
||
|
|
||
| self.add_contributor( | ||
| contributor, | ||
| permissions=permissions, | ||
|
|
@@ -1610,7 +1623,7 @@ def add_contributor_registered_or_not(self, | |
| user_id=None, | ||
| full_name=None, | ||
| email=None, | ||
| notification_type=None, | ||
| notification_type=False, | ||
| permissions=None, | ||
| bibliographic=True, | ||
| index=None): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -916,7 +916,8 @@ def test_add_contributors(self, node, auth): | |
| {'user': user1, 'permissions': ADMIN, 'visible': True}, | ||
| {'user': user2, 'permissions': WRITE, 'visible': False} | ||
| ], | ||
| auth=auth | ||
| auth=auth, | ||
| notification_type=None | ||
| ) | ||
| last_log = node.logs.all().order_by('-date')[0] | ||
| assert ( | ||
|
|
@@ -1114,7 +1115,8 @@ def test_remove_contributors(self, node, auth): | |
| {'user': user1, 'permissions': permissions.WRITE, 'visible': True}, | ||
| {'user': user2, 'permissions': permissions.WRITE, 'visible': True} | ||
| ], | ||
| auth=auth | ||
| auth=auth, | ||
| notification_type=None | ||
| ) | ||
| assert user1 in node.contributors | ||
| assert user2 in node.contributors | ||
|
|
@@ -1232,7 +1234,7 @@ class TestNodeAddContributorRegisteredOrNot: | |
| def test_add_contributor_user_id(self, user, node): | ||
| registered_user = UserFactory() | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), user_id=registered_user._id) | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), user_id=registered_user._id, notification_type=None) | ||
| contributor = contributor_obj.user | ||
| assert contributor in node.contributors | ||
| assert contributor.is_registered is True | ||
|
|
@@ -1241,7 +1243,7 @@ def test_add_contributor_registered_or_not_unreg_user_without_unclaimed_records( | |
| unregistered_user = UnregUserFactory() | ||
| unregistered_user.save() | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), email=unregistered_user.email, full_name=unregistered_user.fullname) | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), email=unregistered_user.email, full_name=unregistered_user.fullname, notification_type=None) | ||
|
|
||
| contributor = contributor_obj.user | ||
| assert contributor in node.contributors | ||
|
|
@@ -1260,22 +1262,22 @@ def test_add_contributor_invalid_user_id(self, user, node): | |
|
|
||
| def test_add_contributor_fullname_email(self, user, node): | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='Jane Doe', email='[email protected]') | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='Jane Doe', email='[email protected]', notification_type=None) | ||
| contributor = contributor_obj.user | ||
| assert contributor in node.contributors | ||
| assert contributor.is_registered is False | ||
|
|
||
| def test_add_contributor_fullname(self, user, node): | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='Jane Doe') | ||
| with capture_notifications(expect_none=True): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='Jane Doe', notification_type=None) | ||
| contributor = contributor_obj.user | ||
| assert contributor in node.contributors | ||
| assert contributor.is_registered is False | ||
|
|
||
| def test_add_contributor_fullname_email_already_exists(self, user, node): | ||
| registered_user = UserFactory() | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='F Mercury', email=registered_user.username) | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='F Mercury', email=registered_user.username, notification_type=None) | ||
| contributor = contributor_obj.user | ||
| assert contributor in node.contributors | ||
| assert contributor.is_registered is True | ||
|
|
@@ -1284,7 +1286,7 @@ def test_add_contributor_fullname_email_exists_as_secondary(self, user, node): | |
| registered_user = UserFactory() | ||
| secondary_email = '[email protected]' | ||
| Email.objects.create(address=secondary_email, user=registered_user) | ||
| with capture_notifications(): | ||
| with capture_notifications(expect_none=True): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name='F Mercury', email=secondary_email) | ||
| contributor = contributor_obj.user | ||
| assert contributor == registered_user | ||
|
|
@@ -1295,7 +1297,7 @@ def test_add_contributor_unregistered(self, user, node): | |
| unregistered_user = UnregUserFactory() | ||
| unregistered_user.save() | ||
| with capture_notifications(): | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name=unregistered_user.fullname, email=unregistered_user.email) | ||
| contributor_obj = node.add_contributor_registered_or_not(auth=Auth(user), full_name=unregistered_user.fullname, email=unregistered_user.email, notification_type=None) | ||
| contributor = contributor_obj.user | ||
| assert contributor == unregistered_user | ||
| assert contributor in node.contributors | ||
|
|
@@ -1345,8 +1347,7 @@ def test_add_contributors_sends_contributor_added_signal(self, node, auth): | |
| 'permissions': permissions.WRITE | ||
| }] | ||
| with capture_signals() as mock_signals: | ||
| with capture_notifications(): | ||
| node.add_contributors(contributors=contributors, auth=auth) | ||
| node.add_contributors(contributors=contributors, auth=auth) | ||
| node.save() | ||
| assert node.is_contributor(user) | ||
| assert mock_signals.signals_sent() == {contributor_added} | ||
|
|
@@ -2612,7 +2613,8 @@ def test_contributor_set_visibility_validation(self, node, user, auth): | |
| [ | ||
| {'user': reg_user1, 'permissions': ADMIN, 'visible': True}, | ||
| {'user': reg_user2, 'permissions': ADMIN, 'visible': False}, | ||
| ] | ||
| ], | ||
| notification_type=None | ||
| ) | ||
| with pytest.raises(ValueError) as e: | ||
| node.set_visible(user=reg_user1, visible=False, auth=None) | ||
|
|
@@ -3364,7 +3366,8 @@ def test_move_contributor(self, user, node, auth): | |
| {'user': user1, 'permissions': WRITE, 'visible': True}, | ||
| {'user': user2, 'permissions': WRITE, 'visible': True} | ||
| ], | ||
| auth=auth | ||
| auth=auth, | ||
| notification_type=None | ||
| ) | ||
|
|
||
| user_contrib_id = node.contributor_set.get(user=user).id | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
False: we don't want user to receive any emailsNone: we will just wait for the caller to provide the template