Skip to content

Commit

Permalink
Merge branch 'feature/b-and-i-25-01' of https://github.com/CenterForO…
Browse files Browse the repository at this point in the history
…penScience/osf.io into log-add-curator

* 'feature/b-and-i-25-01' of https://github.com/CenterForOpenScience/osf.io:
  update email copy
  refactor tests an clean-up tests, split up cases stop pointless reloads
  send email notifications when changing affiliations, split up test files
  fix issue with requested permissions not being passed into state machine add contributor method
  allow email to be sent with placeholder text for project requests and move language from settings to language module
  no message
  add resubmit/update ability for node requests
  • Loading branch information
Johnetordoff committed Jan 30, 2025
2 parents c32f321 + 0574587 commit 35f958a
Show file tree
Hide file tree
Showing 13 changed files with 1,097 additions and 736 deletions.
68 changes: 42 additions & 26 deletions api/requests/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import IntegrityError
from django.db import IntegrityError, transaction
from rest_framework import exceptions
from rest_framework import serializers as ser

Expand All @@ -18,7 +18,7 @@
)
from osf.utils.workflows import DefaultStates, RequestTypes, NodeRequestTypes
from osf.utils import permissions as osf_permissions
from website import settings
from website import language, settings
from website.mails import send_mail, NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST

from rest_framework.exceptions import PermissionDenied, ValidationError
Expand Down Expand Up @@ -186,20 +186,21 @@ def make_node_institutional_access_request(self, node, validated_data) -> NodeRe
if not recipient.is_affiliated_with_institution(institution):
raise PermissionDenied(f"User {recipient._id} is not affiliated with the institution.")

if validated_data['comment']:
send_mail(
to_addr=recipient.username,
mail=NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST,
user=recipient,
sender=sender,
bcc_addr=[sender.username] if validated_data['bcc_sender'] else None,
reply_to=sender.username if validated_data['reply_to'] else None,
recipient=recipient,
comment=validated_data['comment'],
institution=institution,
osf_url=settings.DOMAIN,
node=node_request.target,
)
comment = validated_data.get('comment', '').strip() or language.EMPTY_REQUEST_INSTITUTIONAL_ACCESS_REQUEST_TEXT

send_mail(
to_addr=recipient.username,
mail=NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST,
user=recipient,
sender=sender,
bcc_addr=[sender.username] if validated_data['bcc_sender'] else None,
reply_to=sender.username if validated_data['reply_to'] else None,
recipient=recipient,
comment=comment,
institution=institution,
osf_url=settings.DOMAIN,
node=node_request.target,
)

return node_request

Expand All @@ -209,17 +210,32 @@ def _create_node_request(self, node, validated_data) -> NodeRequest:
comment = validated_data.get('comment', '')
requested_permissions = validated_data.get('requested_permissions')
try:
node_request = NodeRequest.objects.create(
target=node,
creator=creator,
comment=comment,
machine_state=DefaultStates.INITIAL.value,
request_type=request_type,
requested_permissions=requested_permissions,
)
node_request.save()
with transaction.atomic():
node_request = NodeRequest.objects.create(
target=node,
creator=creator,
comment=comment,
machine_state=DefaultStates.INITIAL.value,
request_type=request_type,
requested_permissions=requested_permissions,
)
node_request.save()
except IntegrityError:
raise Conflict(f"Users may not have more than one {request_type} request per node.")
# if INSTITUTIONAL_REQUEST updates and restarts the request
with transaction.atomic():
if request_type == NodeRequestTypes.INSTITUTIONAL_REQUEST.value:
node_request = NodeRequest.objects.filter(
target=node,
creator=creator,
request_type=NodeRequestTypes.INSTITUTIONAL_REQUEST.value,
).first()
else:
raise Conflict(f"Users may not have more than one {request_type} request per node.")
if node_request:
node_request.comment = comment
node_request.machine_state = DefaultStates.INITIAL.value
node_request.requested_permissions = requested_permissions
node_request.save()

node_request.run_submit(creator)
return node_request
Expand Down
Loading

0 comments on commit 35f958a

Please sign in to comment.