#31 API POST Compensation
* adds initialize_objects to an abstractmethod of the super class to be implemented in subclasses * differentiates error messages if intervention does not exist or is just not shared with the user
This commit is contained in:
parent
fa01733815
commit
08ab36ffda
@ -134,3 +134,18 @@ class AbstractModelAPISerializer:
|
|||||||
id=id,
|
id=id,
|
||||||
users__in=[user]
|
users__in=[user]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def initialize_objects(self, json_model, user):
|
||||||
|
""" Initializes all needed objects from the json_model data
|
||||||
|
|
||||||
|
Does not persist data to the DB!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
json_model (dict): The json data
|
||||||
|
user (User): The API user
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
obj (Intervention)
|
||||||
|
"""
|
||||||
|
raise NotImplementedError("Must be implemented in subclasses")
|
||||||
|
@ -81,8 +81,10 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1):
|
|||||||
"""
|
"""
|
||||||
intervention = Intervention.objects.get(
|
intervention = Intervention.objects.get(
|
||||||
id=intervention_id,
|
id=intervention_id,
|
||||||
users__in=[user],
|
|
||||||
)
|
)
|
||||||
|
is_shared = intervention.is_shared_with(user)
|
||||||
|
if not is_shared:
|
||||||
|
raise PermissionError("Intervention not shared with user")
|
||||||
obj.intervention = intervention
|
obj.intervention = intervention
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user