Skip to content

Commit

Permalink
Kontrola permissions pre vytvorenie presunuta na spravne miesto (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe authored Apr 13, 2024
1 parent cc586bd commit 6b9be65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 0 additions & 3 deletions competition/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return True

if request.method == 'POST':
return view.get_serializer().Meta.model.can_user_create(request.user, request.data)

return request.user.is_authenticated and request.user.is_staff

def has_object_permission(self, request, view, obj):
Expand Down
20 changes: 14 additions & 6 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ def perform_create(self, serializer):
Volá sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit problem v danej sutazi
"""
series = serializer.validated_data['series']
if series.can_user_modify(self.request.user):
if Problem.can_user_create(self.request.user, serializer.validated_data):
serializer.save()
else:
raise exceptions.PermissionDenied(
Expand Down Expand Up @@ -455,6 +454,17 @@ class SeriesViewSet(ModelViewSetWithSerializerContext):
permission_classes = (CompetitionRestrictedPermission,)
http_method_names = ['get', 'head', 'put', 'patch', "post"]

def perform_create(self, serializer):
"""
Vola sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit semester v danej sutazi
"""
if Series.can_user_create(self.request.user, serializer.validated_data):
serializer.save()
else:
raise exceptions.PermissionDenied(
'Nedostatočné práva na vytvorenie tohoto objektu')

@staticmethod
def __create_result_json(series: Series) -> dict:
results = []
Expand Down Expand Up @@ -793,8 +803,7 @@ def perform_create(self, serializer):
Vola sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit event v danej sutazi
"""
competition = serializer.validated_data['competition']
if competition.can_user_modify(self.request.user):
if Event.can_user_create(self.request.user, serializer.validated_data):
serializer.save()
else:
raise exceptions.PermissionDenied(
Expand Down Expand Up @@ -874,8 +883,7 @@ def perform_create(self, serializer):
Vola sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit publication v danom evente
'''
event = serializer.validated_data['event']
if event.can_user_modify(self.request.user):
if Publication.can_user_create(self.request.user, serializer.validated_data):
serializer.save()
else:
raise exceptions.PermissionDenied(
Expand Down

0 comments on commit 6b9be65

Please sign in to comment.