diff --git a/competition/permissions.py b/competition/permissions.py index 5dc946f..39c7c26 100644 --- a/competition/permissions.py +++ b/competition/permissions.py @@ -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): diff --git a/competition/views.py b/competition/views.py index f607e43..9e57d29 100644 --- a/competition/views.py +++ b/competition/views.py @@ -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( @@ -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 = [] @@ -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( @@ -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(