Skip to content

Commit bfbc302

Browse files
alanbchristieAlan Christie
and
Alan Christie
authored
Relaxes authentication for SessionProject (#644)
* refactor: Explicit error is there are no Projects * chore: Removed commented-out code * fix: Relaxed suth for SessionProject --------- Co-authored-by: Alan Christie <alan.christie@matildapeak.com>
1 parent 6675729 commit bfbc302

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

viewer/permissions.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ def has_object_permission(self, request, view, obj):
5353
else:
5454
# Only one proposal...
5555
object_proposals = [attr_value.title]
56+
if not object_proposals:
57+
raise PermissionDenied(
58+
detail="Authority cannot be granted - the object is not a part of any Project"
59+
)
5660
# Now we have the proposals the object belongs to
5761
# has the user been associated (in IPSpyB) with any of them?
58-
if (
59-
object_proposals
60-
and not _ISPYB_SAFE_QUERY_SET.user_is_member_of_any_given_proposals(
61-
user=request.user, proposals=object_proposals
62-
)
62+
if not _ISPYB_SAFE_QUERY_SET.user_is_member_of_any_given_proposals(
63+
user=request.user, proposals=object_proposals
6364
):
6465
raise PermissionDenied(
6566
detail="Your authority to access this object has not been given"

viewer/serializers.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,19 @@ def validate(self, data):
7878
else:
7979
# Only one proposal...
8080
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+
)
8185

8286
# Now we have the proposals (Project titles) the object belongs to,
8387
# has the user been associated (in IPSpyB) with any of them?
8488
# We can always see (GET) objects that are open to the public.
8589
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,
9394
):
9495
raise PermissionDenied(
9596
detail="Your authority to access this object has not been given"
@@ -556,17 +557,7 @@ class Meta:
556557

557558

558559
# (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):
570561
class Meta:
571562
model = models.SessionProject
572563
fields = '__all__'

viewer/views.py

-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ class SessionProjectView(
919919
queryset = models.SessionProject.objects.filter()
920920
filter_permissions = "target__project_id"
921921
filterset_fields = '__all__'
922-
permission_classes = [IsObjectProposalMember]
923922

924923
def get_serializer_class(self):
925924
if self.request.method in ['GET']:

0 commit comments

Comments
 (0)