Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions osf/models/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ def terminate_embargo(self, forced=False):
self.refresh_from_db()
if self.is_pending_embargo_termination:
self.embargo_termination_approval.accept()
# accept() above updates moderation_state through a different in-memory
# Registration; refresh again or set_privacy() below will overwrite it
self.refresh_from_db()

for node in self.node_and_primary_descendants():
node.set_privacy(
Expand Down
12 changes: 11 additions & 1 deletion osf_tests/test_sanctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils import timezone
from transitions import MachineError

from osf.models import NodeLog
from osf.models import NodeLog, Registration
from osf.exceptions import NodeStateError
from osf_tests import factories
from osf_tests.utils import mock_archive
Expand Down Expand Up @@ -74,6 +74,16 @@ def test_terminate_embargo_log_is_nouser(self, node, user, registration):
assert last_log.action == NodeLog.EMBARGO_TERMINATED
assert last_log.user is None

def test_terminate_embargo_on_fresh_object_with_pending_termination_sets_correct_state(self, registration, user):
with capture_notifications():
registration.request_embargo_termination(user)
assert registration.is_pending_embargo_termination is True
fresh_registration = Registration.objects.get(pk=registration.pk)
fresh_registration.terminate_embargo()
assert fresh_registration.is_public is True
assert fresh_registration.is_embargoed is False
assert fresh_registration.moderation_state == 'accepted'


@pytest.mark.django_db
class TestRegistrationEmbargoTermination:
Expand Down