Merge pull request #1719 from normanjaeckel/AssignmentRESTReq
Added error message if a new cnadidate is already nominated.
This commit is contained in:
commit
e046dd5302
@ -162,14 +162,15 @@ class AssignmentViewSet(ModelViewSet):
|
|||||||
detail = _('You can not nominate someone to this election because it is finished.')
|
detail = _('You can not nominate someone to this election because it is finished.')
|
||||||
raise ValidationError({'detail': detail})
|
raise ValidationError({'detail': detail})
|
||||||
if assignment.phase == assignment.PHASE_VOTING and not request.user.has_perm('assignments.can_manage'):
|
if assignment.phase == assignment.PHASE_VOTING and not request.user.has_perm('assignments.can_manage'):
|
||||||
# To nominate other during voting you have to be a manager.
|
# To nominate another user during voting you have to be a manager.
|
||||||
self.permission_denied(request)
|
self.permission_denied(request)
|
||||||
if not request.user.has_perm('assignments.can_manage'):
|
if not request.user.has_perm('assignments.can_manage'):
|
||||||
if assignment.is_blocked(user):
|
if assignment.is_blocked(user):
|
||||||
raise ValidationError({'detail': _('User %s does not want to be a candidate. Only a manager can do this.') % user})
|
raise ValidationError({'detail': _('User %s does not want to be a candidate. Only a manager can do this.') % user})
|
||||||
if assignment.is_elected(user):
|
if assignment.is_elected(user):
|
||||||
raise ValidationError({'detail': _('User %s is already elected.') % user})
|
raise ValidationError({'detail': _('User %s is already elected.') % user})
|
||||||
# If the user is already a candidate he can be nominated nevertheless.
|
if assignment.is_candidate(user):
|
||||||
|
raise ValidationError({'detail': _('User %s is already nominated.') % user})
|
||||||
assignment.set_candidate(user)
|
assignment.set_candidate(user)
|
||||||
return _('User %s was nominated successfully.') % user
|
return _('User %s was nominated successfully.') % user
|
||||||
|
|
||||||
|
@ -151,8 +151,7 @@ class CandidatureOther(TestCase):
|
|||||||
reverse('assignment-candidature-other', args=[self.assignment.pk]),
|
reverse('assignment-candidature-other', args=[self.assignment.pk]),
|
||||||
{'user': self.user.pk})
|
{'user': self.user.pk})
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 400)
|
||||||
self.assertTrue(Assignment.objects.get(pk=self.assignment.pk).candidates.filter(username='test_user_eeheekai4Phue6cahtho').exists())
|
|
||||||
|
|
||||||
def test_nominate_other_when_finished(self):
|
def test_nominate_other_when_finished(self):
|
||||||
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
||||||
|
Loading…
Reference in New Issue
Block a user