Skip to content

Commit

Permalink
(no ticket) Disallow unregistering from contest in OI
Browse files Browse the repository at this point in the history
Change-Id: I62568337131e66962ae37d49bf52ad1cc938840d
  • Loading branch information
accek committed Oct 18, 2013
1 parent aad7a95 commit 3c2cdb5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions oioioi/oi/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def school_province(self, instance):
school_province.admin_order_field = 'oi_oiregistration__school__province'

def has_add_permission(self, request):
return False
return request.user.is_superuser

def has_delete_permission(self, request, obj=None):
return False
return request.user.is_superuser

def get_actions(self, request):
actions = super(OIRegistrationParticipantAdmin, self) \
Expand Down
3 changes: 3 additions & 0 deletions oioioi/oi/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def can_enter_contest(self, request):
def can_register(self, request):
return True

def can_unregister(self, request, participant):
return False

def registration_view(self, request):
participant = self._get_participant_for_form(request)

Expand Down
8 changes: 4 additions & 4 deletions oioioi/oi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_participants_accounts_menu(self):
self.assertNotIn('Register to the contest', response.content)
self.assertIn('Edit contest registration', response.content)

def test_participants_unregister(self):
def test_participants_unregister_forbidden(self):
contest = Contest.objects.get()

url = reverse('participants_unregister',
Expand All @@ -156,8 +156,8 @@ def test_participants_unregister(self):

self.client.login(username='test_user')
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(302, response.status_code)
self.assertEqual(Participant.objects.count(), 0)
self.assertEqual(403, response.status_code)
self.assertEqual(Participant.objects.count(), 1)

def test_participants_registration(self):
contest = Contest.objects.get()
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_participants_accounts_menu(self):
self.assertNotIn('Register to the contest', response.content)
self.assertNotIn('Edit contest registration', response.content)

def test_participants_unregister(self):
def test_participants_unregister_forbidden(self):
contest = Contest.objects.get()

url = reverse('participants_unregister',
Expand Down
12 changes: 11 additions & 1 deletion oioioi/participants/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def can_edit_registration(self, request, participant):
return False
return bool(request.user == participant.user)

def can_unregister(self, request, participant):
return self.can_edit_registration(request, participant)

def no_entry_view(self, request):
if self.can_register(request):
url = reverse('participants_register',
Expand Down Expand Up @@ -118,5 +121,12 @@ def registration_view(self, request):
else:
return redirect('default_contest_view',
contest_id=self.contest.id)
context = {'form': form, 'participant': participant}
can_unregister = False
if participant:
can_unregister = self.can_unregister(request, participant)
context = {
'form': form,
'participant': participant,
'can_unregister': can_unregister,
}
return TemplateResponse(request, self.registration_template, context)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2>{% trans "Register to the contest" %}</h2>
</fieldset>
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="{% trans "Submit" %}" />
{% if participant %}
{% if can_unregister %}
<a class="btn btn-danger pull-right" href="{% url 'participants_unregister' contest_id=contest.id %}">
{% trans "Unregister" %}
</a>
Expand Down
10 changes: 10 additions & 0 deletions oioioi/participants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def can_edit_registration(request):
return rcontroller.can_edit_registration(request, participant)


@make_request_condition
@request_cached
def can_unregister(request):
participant = get_participant(request)
if participant is None:
return False
rcontroller = request.contest.controller.registration_controller()
return rcontroller.can_unregister(request, participant)


@make_request_condition
@request_cached
def is_participant(request):
Expand Down
4 changes: 2 additions & 2 deletions oioioi/participants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from oioioi.contests.utils import contest_exists
from oioioi.participants.models import Participant
from oioioi.participants.utils import can_register, can_edit_registration, \
contest_has_participants
contest_has_participants, can_unregister

account_menu_registry.register('participants_registration',
_("Register to the contest"),
Expand All @@ -32,7 +32,7 @@ def registration_view(request, contest_id):


@enforce_condition(not_anonymous & contest_exists & contest_has_participants
& can_edit_registration)
& can_unregister)
def unregistration_view(request, contest_id):
if request.method == 'POST':
participant = get_object_or_404(Participant, contest=request.contest,
Expand Down

0 comments on commit 3c2cdb5

Please sign in to comment.