-
Notifications
You must be signed in to change notification settings - Fork 359
[ENG-8830] PROVIDER_MODERATOR_ADDED email #11288
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
Merged
Johnetordoff
merged 3 commits into
CenterForOpenScience:add-new-notifications-data-model
from
Ostap-Zherebetskyi:fix/provider_moderator_email
Sep 9, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
83 changes: 83 additions & 0 deletions
83
api_tests/mailhog/provider/test_registration_provider_moderator.py
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import pytest | ||
| from waffle.testutils import override_switch | ||
| from osf import features | ||
| from django.test import RequestFactory | ||
|
|
||
| from osf_tests.factories import ( | ||
| AuthUserFactory, | ||
| RegistrationProviderFactory | ||
| ) | ||
| from admin_tests.utilities import setup_view | ||
| from admin.providers.views import AddAdminOrModerator | ||
|
|
||
| from django.contrib.messages.storage.fallback import FallbackStorage | ||
| from osf.migrations import update_provider_auth_groups | ||
| from tests.utils import get_mailhog_messages, delete_mailhog_messages | ||
| from osf.models import NotificationType | ||
|
|
||
| pytestmark = pytest.mark.django_db | ||
|
|
||
|
|
||
| @pytest.mark.urls('admin.base.urls') | ||
| class TestEditModerators: | ||
|
|
||
| @pytest.fixture() | ||
| def req(self, user): | ||
| req = RequestFactory().get('/fake_path') | ||
| req.user = user | ||
| return req | ||
|
|
||
| @pytest.fixture() | ||
| def provider(self): | ||
| provider = RegistrationProviderFactory() | ||
| update_provider_auth_groups() | ||
| return provider | ||
|
|
||
| @pytest.fixture() | ||
| def user(self): | ||
| return AuthUserFactory() | ||
|
|
||
| @pytest.fixture() | ||
| def add_moderator_view(self, req, provider): | ||
| view = AddAdminOrModerator() | ||
| view = setup_view(view, req) | ||
| view.kwargs = {'provider_id': provider.id} | ||
| return view | ||
|
|
||
| @override_switch(features.ENABLE_MAILHOG, active=True) | ||
| def test_post_add(self, add_moderator_view, req, user, provider): | ||
| delete_mailhog_messages() | ||
|
|
||
| req.POST = { | ||
| 'csrfmiddlewaretoken': 'fake csfr', | ||
| 'add-moderators-form': [user._id], | ||
| 'moderator': ['Add Moderator'] | ||
| } | ||
|
|
||
| # django.contrib.messages has a bug which effects unittests | ||
| # more info here -> https://code.djangoproject.com/ticket/17971 | ||
| setattr(req, 'session', 'session') | ||
| messages = FallbackStorage(req) | ||
| setattr(req, '_messages', messages) | ||
|
|
||
| res = add_moderator_view.post(req) | ||
| assert res.status_code == 302 | ||
| assert user in provider.get_group('moderator').user_set.all() | ||
|
|
||
| # try to add the same user, but another group | ||
| req.POST = { | ||
| 'csrfmiddlewaretoken': 'fake csfr', | ||
| 'add-moderators-form': [user._id], | ||
| 'admin': ['Add Admin'] | ||
| } | ||
| res = add_moderator_view.post(req) | ||
| assert res.status_code == 302 | ||
| assert user in provider.get_group('moderator').user_set.all() | ||
| assert user not in provider.get_group('admin').user_set.all() | ||
| res = get_mailhog_messages() | ||
| assert res['count'] == 1 | ||
| assert res['items'][0]['Content']['Headers']['To'][0] == user.username | ||
| assert res['items'][0]['Content']['Headers']['Subject'][0] == NotificationType.objects.get( | ||
| name=NotificationType.Type.PROVIDER_MODERATOR_ADDED | ||
| ).subject | ||
| delete_mailhog_messages() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.