Skip to content

Commit b5bdebe

Browse files
committed
more clean-up from self-CR
1 parent dcdbdc7 commit b5bdebe

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

api/nodes/serializers.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,15 +1256,11 @@ def create(self, validated_data):
12561256

12571257
try:
12581258
contributor_dict = {
1259-
'auth': auth,
1260-
'user_id': id,
1261-
'email': email,
1262-
'full_name': full_name,
1263-
'send_email': send_email,
1264-
'bibliographic': bibliographic,
1265-
'index': index,
1266-
'permissions': permissions,
1259+
'auth': auth, 'user_id': id, 'email': email, 'full_name': full_name, 'send_email': send_email,
1260+
'bibliographic': bibliographic, 'index': index,
12671261
}
1262+
1263+
contributor_dict['permissions'] = permissions
12681264
contributor_obj = node.add_contributor_registered_or_not(**contributor_dict)
12691265
except ValidationError as e:
12701266
raise exceptions.ValidationError(detail=e.messages[0])

api/nodes/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def perform_create(self, serializer):
10511051
user=user,
10521052
event_context={
10531053
'guid': node._id,
1054-
'title': node._id,
1054+
'title': node.title,
10551055
'can_change_preferences': False,
10561056
},
10571057
)
@@ -1063,7 +1063,7 @@ def perform_create(self, serializer):
10631063
user=user,
10641064
event_context={
10651065
'guid': fork._id,
1066-
'title': node._id,
1066+
'title': node.title,
10671067
'can_change_preferences': False,
10681068
},
10691069
)

api/providers/serializers.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ def create(self, validated_data):
347347

348348
if bool(get_perms(user, provider)):
349349
raise ValidationError('Specified user is already a moderator.')
350-
if 'claim_url' in context:
351-
template = NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
352-
else:
353-
template = NotificationType.Type.PROVIDER_MODERATOR_ADDED
354350

355351
perm_group = validated_data.pop('permission_group', '')
356352
if perm_group not in REVIEW_GROUPS:
@@ -362,9 +358,12 @@ def create(self, validated_data):
362358

363359
provider.add_to_group(user, perm_group)
364360
setattr(user, 'permission_group', perm_group) # Allows reserialization
365-
print(template, context)
361+
if 'claim_url' in context:
362+
notification_type = NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
363+
else:
364+
notification_type = NotificationType.Type.PROVIDER_MODERATOR_ADDED
366365
NotificationType.objects.get(
367-
name=template,
366+
name=notification_type,
368367
).emit(
369368
user=user,
370369
event_context=context,

api/providers/tasks.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,6 @@ def bulk_upload_finish_job(upload, row_count, success_count, draft_errors, appro
639639
approval_errors.sort()
640640
if not dry_run:
641641
upload.save()
642-
notification_type = None
643-
event_context = {
644-
'initiator_fullname': initiator.fullname,
645-
'auto_approval': auto_approval,
646-
'count': row_count,
647-
'pending_submissions_url': get_registration_provider_submissions_url(provider),
648-
'draft_errors': draft_errors,
649-
'approval_errors': approval_errors,
650-
'successes': success_count,
651-
'failures': len(draft_errors),
652-
'osf_support_email': settings.OSF_SUPPORT_EMAIL,
653-
}
654642

655643
if upload.state == JobState.DONE_FULL:
656644
notification_type = NotificationType.Type.USER_REGISTRATION_BULK_UPLOAD_SUCCESS_ALL
@@ -666,12 +654,22 @@ def bulk_upload_finish_job(upload, row_count, success_count, draft_errors, appro
666654
name=notification_type,
667655
).emit(
668656
user=initiator,
669-
event_context=event_context,
657+
event_context={
658+
'initiator_fullname': initiator.fullname,
659+
'auto_approval': auto_approval,
660+
'count': row_count,
661+
'pending_submissions_url': get_registration_provider_submissions_url(provider),
662+
'draft_errors': draft_errors,
663+
'approval_errors': approval_errors,
664+
'successes': success_count,
665+
'failures': len(draft_errors),
666+
'osf_support_email': settings.OSF_SUPPORT_EMAIL,
667+
},
670668
)
671669

672670
upload.email_sent = timezone.now()
673671
upload.save()
674-
logger.info(f'Notification sent to bulk upload initiator [{initiator._id}]')
672+
logger.info(f'Email sent to bulk upload initiator [{initiator._id}]')
675673

676674

677675
def handle_internal_error(initiator=None, provider=None, message=None, dry_run=True):

api/users/views.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -825,29 +825,33 @@ def get(self, request, *args, **kwargs):
825825
if not email:
826826
raise ValidationError('Request must include email in query params.')
827827

828-
institutional = bool(request.query_params.get('institutional', None))
829-
mail_template = 'forgot_password' if not institutional else 'forgot_password_institution'
830-
831828
status_message = language.RESET_PASSWORD_SUCCESS_STATUS_MESSAGE.format(email=email)
832-
kind = 'success'
833829
# check if the user exists
834830
user_obj = get_user(email=email)
831+
institutional = bool(request.query_params.get('institutional', None))
835832

836833
if user_obj:
837834
# rate limit forgot_password_post
838835
if not throttle_period_expired(user_obj.email_last_sent, settings.SEND_EMAIL_THROTTLE):
839-
status_message = 'You have recently requested to change your password. Please wait a few minutes ' \
840-
'before trying again.'
841-
kind = 'error'
842-
return Response({'message': status_message, 'kind': kind}, status=status.HTTP_429_TOO_MANY_REQUESTS)
836+
return Response(
837+
{
838+
'message': language.THROTTLE_PASSWORD_CHANGE_ERROR_MESSAGE,
839+
'kind': 'error',
840+
},
841+
status=status.HTTP_429_TOO_MANY_REQUESTS,
842+
)
843843
elif user_obj.is_active:
844844
# new random verification key (v2)
845845
user_obj.verification_key_v2 = generate_verification_key(verification_type='password')
846846
user_obj.email_last_sent = timezone.now()
847847
user_obj.save()
848848
reset_link = f'{settings.RESET_PASSWORD_URL}{user_obj._id}/{user_obj.verification_key_v2['token']}/'
849+
if institutional:
850+
notification_type = NotificationType.Type.USER_FORGOT_PASSWORD_INSTITUTION
851+
else:
852+
notification_type = NotificationType.Type.USER_FORGOT_PASSWORD
849853

850-
NotificationType.objects.get(name=mail_template).emit(
854+
NotificationType.objects.get(name=notification_type).emit(
851855
user=user_obj,
852856
message_frequency='instantly',
853857
event_context={
@@ -856,7 +860,14 @@ def get(self, request, *args, **kwargs):
856860
},
857861
)
858862

859-
return Response(status=status.HTTP_200_OK, data={'message': status_message, 'kind': kind, 'institutional': institutional})
863+
return Response(
864+
status=status.HTTP_200_OK,
865+
data={
866+
'message': status_message,
867+
'kind': 'success',
868+
'institutional': institutional,
869+
},
870+
)
860871

861872
@method_decorator(csrf_protect)
862873
def post(self, request, *args, **kwargs):

website/language.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
'you should have, please contact OSF Support. '
223223
)
224224

225+
THROTTLE_PASSWORD_CHANGE_ERROR_MESSAGE = \
226+
'You have recently requested to change your password. Please wait a few minutes before trying again.'
227+
225228
SANCTION_STATUS_MESSAGES = {
226229
'registration': {
227230
'approve': 'Your registration approval has been accepted.',

0 commit comments

Comments
 (0)