forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-5352][ENG-5267][ENG-5144] Messaging for Account Status Changes (…
…OSF-side) (CenterForOpenScience#10565) * Add Rabbit Queue for OSF->Addons Service communication and send user account status changes * Refactor some mailchimp stuff on the way --------- Co-authored-by: John Tordoff <>
- Loading branch information
1 parent
36a9e47
commit 3448bba
Showing
14 changed files
with
275 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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
Empty file.
This file contains 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,45 @@ | ||
import waffle | ||
from kombu import Exchange | ||
from framework.celery_tasks import app as celery_app | ||
from website import settings | ||
from osf import features | ||
from osf.utils.requests import get_current_request | ||
|
||
|
||
def publish_deactivated_user(user): | ||
_publish_user_status_change( | ||
body={ | ||
'action': 'deactivate', | ||
'user_uri': user.get_semantic_iri(), | ||
} | ||
) | ||
|
||
|
||
def publish_reactivate_user(user): | ||
_publish_user_status_change( | ||
body={ | ||
'action': 'reactivate', | ||
'user_uri': user.get_semantic_iri(), | ||
}, | ||
) | ||
|
||
|
||
def publish_merged_user(user): | ||
assert user.merged_by, 'User received merge signal, but has no `merged_by` reference.' | ||
_publish_user_status_change( | ||
body={ | ||
'action': 'merge', | ||
'into_user_uri': user.merged_by.get_semantic_iri(), | ||
'from_user_uri': user.get_semantic_iri(), | ||
}, | ||
) | ||
|
||
|
||
def _publish_user_status_change(body: dict): | ||
if settings.USE_CELERY and waffle.flag_is_active(get_current_request(), features.ENABLE_GV): | ||
with celery_app.producer_pool.acquire() as producer: | ||
producer.publish( | ||
body=body, | ||
exchange=Exchange(celery_app.conf.task_account_status_changes_queue), | ||
serializer='json' | ||
) |
This file contains 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,40 @@ | ||
from django.core.management.base import BaseCommand | ||
from osf.models import OSFUser | ||
from osf.external.messages.celery_publishers import ( | ||
publish_deactivated_user, | ||
publish_reactivate_user, | ||
publish_merged_user, | ||
) | ||
|
||
actions_to_functions = { | ||
'deactivate': publish_deactivated_user, | ||
'reactivate': publish_reactivate_user, | ||
'merge': publish_merged_user, | ||
} | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Sends a message to manage a user state, for test purposes only.' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('user_guid', type=str, help='use the guid of the user to post.') | ||
# Adding a new argument to specify the action to perform | ||
parser.add_argument( | ||
'action', | ||
type=str, | ||
help='The action to perform on the user (deactivate, reactivate, merge).', | ||
choices=['deactivate', 'reactivate', 'merge'] | ||
) | ||
|
||
def handle(self, *args, **options): | ||
user_guid = options['user_guid'] | ||
user = OSFUser.load(user_guid) | ||
action = options['action'] | ||
|
||
# Using a mapping of action to function to simplify the control flow | ||
|
||
if action in actions_to_functions: | ||
actions_to_functions[action](user) # Call the appropriate function | ||
self.stdout.write(self.style.SUCCESS(f'Successfully {action} message for user: {user._id}')) | ||
else: | ||
self.stdout.write(self.style.ERROR('Invalid action specified.')) |
This file contains 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 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 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 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
Oops, something went wrong.