def add_authorizer(self, user, node, approved=False, save=False): """Add an admin user to this Sanction's approval state. :param User user: User to add. :param Node registration: The pending registration node. :param bool approved: Whether `user` has approved. :param bool save: Whether to save this object. """ valid = self._validate_authorizer(user) if valid and user._id not in self.approval_state: self.approval_state[user._id] = { 'has_approved': approved, 'node_id': node._id, 'approval_token': tokens.encode({ 'user_id': user._id, 'sanction_id': self._id, 'action': 'approve_{}'.format(self.SHORT_NAME) }), 'rejection_token': tokens.encode({ 'user_id': user._id, 'sanction_id': self._id, 'action': 'reject_{}'.format(self.SHORT_NAME) }), } if save: self.save() return True return False
def setUp(self): super(RegistrationRetractionApprovalDisapprovalViewsTestCase, self).setUp() self.user = AuthUserFactory() self.registered_from = ProjectFactory(is_public=True, creator=self.user) self.registration = RegistrationFactory(is_public=True, project=self.registered_from) self.registration.retract_registration(self.user) self.registration.save() self.approval_token = self.registration.retraction.approval_state[self.user._id]['approval_token'] self.rejection_token = self.registration.retraction.approval_state[self.user._id]['rejection_token'] self.corrupt_token = fake.sentence() self.token_without_sanction = tokens.encode({ 'action': 'approve_retraction', 'user_id': self.user._id, 'sanction_id': 'invalid id' })
from tests.factories import (AuthUserFactory, EmbargoFactory, NodeFactory, ProjectFactory, RegistrationFactory, UserFactory, UnconfirmedUserFactory) from framework.exceptions import PermissionsError from modularodm.exceptions import ValidationValueError from website.exceptions import ( InvalidSanctionRejectionToken, InvalidSanctionApprovalToken, NodeStateError, ) from website import tokens from website.models import Embargo, Node from website.project.model import ensure_schemas DUMMY_TOKEN = tokens.encode({'dummy': 'token'}) class RegistrationEmbargoModelsTestCase(OsfTestCase): def setUp(self): super(RegistrationEmbargoModelsTestCase, self).setUp() self.user = UserFactory() self.project = ProjectFactory(creator=self.user) self.registration = RegistrationFactory(project=self.project) self.embargo = EmbargoFactory(user=self.user) self.valid_embargo_end_date = datetime.datetime.utcnow( ) + datetime.timedelta(days=3) # Node#_initiate_embargo tests def test__initiate_embargo_saves_embargo(self): initial_count = Embargo.find().count()
) from tests import utils from framework.exceptions import PermissionsError, HTTPError from framework.auth import Auth from website.exceptions import ( InvalidSanctionRejectionToken, InvalidSanctionApprovalToken, NodeStateError, ) from website import tokens from osf.models import AbstractNode from osf.models.sanctions import PreregCallbackMixin, Embargo from website.util import permissions from osf.models import Registration, Contributor, OSFUser, SpamStatus DUMMY_TOKEN = tokens.encode({ 'dummy': 'token' }) class RegistrationEmbargoModelsTestCase(OsfTestCase): def setUp(self): super(RegistrationEmbargoModelsTestCase, self).setUp() self.user = UserFactory() self.project = ProjectFactory(creator=self.user) self.registration = RegistrationFactory(project=self.project) self.embargo = EmbargoFactory(user=self.user) self.valid_embargo_end_date = timezone.now() + datetime.timedelta(days=3) # Node#_initiate_embargo tests def test__initiate_embargo_saves_embargo(self): initial_count = Embargo.objects.all().count()
NodeFactory, ProjectFactory, RegistrationFactory, UserFactory, UnconfirmedUserFactory, ) from framework.exceptions import PermissionsError from modularodm.exceptions import ValidationValueError from website.exceptions import InvalidSanctionRejectionToken, InvalidSanctionApprovalToken, NodeStateError from website import tokens from website.models import Embargo, Node from website.project.model import ensure_schemas DUMMY_TOKEN = tokens.encode({"dummy": "token"}) class RegistrationEmbargoModelsTestCase(OsfTestCase): def setUp(self): super(RegistrationEmbargoModelsTestCase, self).setUp() self.user = UserFactory() self.project = ProjectFactory(creator=self.user) self.registration = RegistrationFactory(project=self.project) self.embargo = EmbargoFactory(user=self.user) self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3) # Node#_initiate_embargo tests def test__initiate_embargo_saves_embargo(self): initial_count = Embargo.find().count() self.registration._initiate_embargo(self.user, self.valid_embargo_end_date, for_existing_registration=True)
def test_encode(self): assert_equal(encode(self.payload), self.encoded_token)