Exemple #1
0
    def clean(self, value):
        user = self._user
        assert user is not None

        value = super().clean(value=value)
        validators.validate_linkable_entity(user.linked_contact, user)

        return value
Exemple #2
0
        def clean_my_participation(self):
            my_participation = self.cleaned_data['my_participation']

            if my_participation[0]:
                user = self.user
                validators.validate_linkable_entity(user.linked_contact, user)

            return my_participation
    def test_validate_linkable_entity_allowed(self):
        user = self.login(is_superuser=False)
        a = FakeContact.objects.create(last_name='Doe',
                                       first_name='John',
                                       user=self.other_user)

        self._set_user_credentials(user, EntityCredentials.LINK,
                                   SetCredentials.ESET_ALL)

        with self.assertNoException():
            validators.validate_linkable_entity(a, user)
    def test_validate_linkable_entity_notallowed_all(self):
        user = self.login(is_superuser=False)
        a = FakeContact.objects.create(last_name='Doe',
                                       first_name='John',
                                       user=self.other_user)

        self._set_user_credentials(user, EntityCredentials.VIEW,
                                   SetCredentials.ESET_ALL)

        with self.assertRaises(ValidationError) as e:
            validators.validate_linkable_entity(a, user)

        self.assertEqual(e.exception.code, 'linknotallowed')
    def test_validate_linkable_entity_anonymous(self):
        other_user = CremeUser.objects.create(username='******')
        a = FakeContact.objects.create(last_name='Doe',
                                       first_name='John',
                                       user=other_user)

        user = get_user(self.client)
        self.assertTrue(user.is_anonymous)

        with self.assertRaises(ValidationError) as e:
            validators.validate_linkable_entity(a, user)

        self.assertEqual(
            e.exception.message,
            _('Not authenticated user is not allowed to link entities'))
        self.assertEqual(e.exception.code, 'linknotallowed')
Exemple #6
0
 def clean_customers_managed_orga(this):
     return validators.validate_linkable_entity(
         entity=this.cleaned_data['customers_managed_orga'],
         user=this.user,
     )
Exemple #7
0
 def clean_customers_managed_orga(self):
     return validators.validate_linkable_entity(
         entity=self.cleaned_data['customers_managed_orga'],
         user=self.user,
     )
Exemple #8
0
    def clean_emitter(self):
        self.instance.emitter = emitter = \
            validate_linkable_entity(self.cleaned_data['emitter'], self.user)

        return emitter
Exemple #9
0
 def post_clean_instance(self, *, instance, value, form):
     if value:
         instance.emitter = validate_linkable_entity(
             entity=value,
             user=form.user,
         )