From cde0cc0dd65e93b5e488f065d146768333aca33c Mon Sep 17 00:00:00 2001 From: Faraphel Date: Fri, 8 Dec 2023 19:21:29 +0100 Subject: [PATCH] fixed typo --- Palto/Palto/api/v1/serializers.py | 24 ++++++++++++------------ Palto/Palto/models.py | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Palto/Palto/api/v1/serializers.py b/Palto/Palto/api/v1/serializers.py index d283e43..e5fcd45 100644 --- a/Palto/Palto/api/v1/serializers.py +++ b/Palto/Palto/api/v1/serializers.py @@ -25,31 +25,31 @@ class ModelSerializerContrains(serializers.ModelSerializer): def create(self, validated_data): # get the fields that this user can modify - field_contrains = self.Meta.model.user_fields_contrains(self.context["request"].user) + field_contrains = self.Meta.model.user_fields_contraints(self.context["request"].user) - # for every constrains - for field, constrains in field_contrains.items(): - # check if the value is in the constrains. + # for every constraints + for field, constraints in field_contrains.items(): + # check if the value is in the constraints. value = validated_data.get(field) - if value is not None and value not in constrains: + if value is not None and value not in constraints: raise PermissionDenied(f"You are not allowed to use this value for the field {field}.") return super().create(validated_data) def update(self, instance, validated_data): # get the fields that this user can modify - field_contrains = self.Meta.model.user_fields_contrains(self.context["request"].user) + field_contrains = self.Meta.model.user_fields_contraints(self.context["request"].user) - # for every constrains - for field, constrains in field_contrains.items(): - # check if the value of the request is in the constrains. + # for every constraints + for field, constraints in field_contrains.items(): + # check if the value of the request is in the constraints. value = validated_data.get(field) - if value is not None and value not in constrains: + if value is not None and value not in constraints: raise PermissionDenied(f"You are not allowed to use this value for the field {field}.") - # check if the value of the already existing instance is in the constrains. + # check if the value of the already existing instance is in the constraints. value = getattr(instance, field, None) - if value is not None and value not in constrains: + if value is not None and value not in constraints: raise PermissionDenied(f"You are not allowed to use this value for the field {field}.") # check that the user is managing the department diff --git a/Palto/Palto/models.py b/Palto/Palto/models.py index 215499b..5399a6b 100644 --- a/Palto/Palto/models.py +++ b/Palto/Palto/models.py @@ -30,7 +30,7 @@ class ModelPermissionHelper: return user.is_superuser @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: """ Return the list of fields in that model that the user can modify """ @@ -232,7 +232,7 @@ class StudentGroup(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -315,7 +315,7 @@ class TeachingUnit(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -386,7 +386,7 @@ class StudentCard(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -480,7 +480,7 @@ class TeachingSession(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -611,7 +611,7 @@ class Attendance(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -751,7 +751,7 @@ class Absence(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {} @@ -831,7 +831,7 @@ class AbsenceAttachment(models.Model, ModelPermissionHelper): return True @classmethod - def user_fields_contrains(cls, user: "User") -> dict[str, QuerySet]: + def user_fields_contraints(cls, user: "User") -> dict[str, QuerySet]: # if the user is admin, no contrains if user.is_superuser: return {}