Merge pull request #1719 from normanjaeckel/AssignmentRESTReq

Added error message if a new cnadidate is already nominated.
This commit is contained in:
Oskar Hahn 2015-11-29 22:22:36 +01:00
commit e046dd5302
2 changed files with 4 additions and 4 deletions

View File

@ -162,14 +162,15 @@ class AssignmentViewSet(ModelViewSet):
detail = _('You can not nominate someone to this election because it is finished.')
raise ValidationError({'detail': detail})
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)
if not request.user.has_perm('assignments.can_manage'):
if assignment.is_blocked(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):
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)
return _('User %s was nominated successfully.') % user

View File

@ -151,8 +151,7 @@ class CandidatureOther(TestCase):
reverse('assignment-candidature-other', args=[self.assignment.pk]),
{'user': self.user.pk})
self.assertEqual(response.status_code, 200)
self.assertTrue(Assignment.objects.get(pk=self.assignment.pk).candidates.filter(username='test_user_eeheekai4Phue6cahtho').exists())
self.assertEqual(response.status_code, 400)
def test_nominate_other_when_finished(self):
self.assignment.set_phase(Assignment.PHASE_FINISHED)