@@ -78,18 +78,19 @@ def validate(self, data):
78
78
else :
79
79
# Only one proposal...
80
80
object_proposals = [project_obj .title ]
81
+ if not object_proposals :
82
+ raise PermissionDenied (
83
+ detail = "Authority cannot be granted - the object is not a part of any Project"
84
+ )
81
85
82
86
# Now we have the proposals (Project titles) the object belongs to,
83
87
# has the user been associated (in IPSpyB) with any of them?
84
88
# We can always see (GET) objects that are open to the public.
85
89
restrict_public = False if self .context ['request' ].method == 'GET' else True # type: ignore [attr-defined]
86
- if (
87
- object_proposals
88
- and not _ISPYB_SAFE_QUERY_SET .user_is_member_of_any_given_proposals (
89
- user = user ,
90
- proposals = object_proposals ,
91
- restrict_public_to_membership = restrict_public ,
92
- )
90
+ if not _ISPYB_SAFE_QUERY_SET .user_is_member_of_any_given_proposals (
91
+ user = user ,
92
+ proposals = object_proposals ,
93
+ restrict_public_to_membership = restrict_public ,
93
94
):
94
95
raise PermissionDenied (
95
96
detail = "Your authority to access this object has not been given"
@@ -556,17 +557,7 @@ class Meta:
556
557
557
558
558
559
# (POST, PUT, PATCH)
559
- class SessionProjectWriteSerializer (ValidateProjectMixin , serializers .ModelSerializer ):
560
- # def validate_target(self, value):
561
- # user = self.context['request'].user
562
- # if not user or not user.is_authenticated:
563
- # raise serializers.ValidationError("You must be logged in to create objects")
564
- # if not _ISPYB_SAFE_QUERY_SET.user_is_member_of_target(user, value):
565
- # raise serializers.ValidationError(
566
- # "You have not been given access the object's Target"
567
- # )
568
- # return value
569
-
560
+ class SessionProjectWriteSerializer (serializers .ModelSerializer ):
570
561
class Meta :
571
562
model = models .SessionProject
572
563
fields = '__all__'
0 commit comments