Skip to content

Commit

Permalink
fix pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed May 31, 2024
1 parent 324556c commit e951e78
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 41 deletions.
6 changes: 3 additions & 3 deletions apps/analysis_framework/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
AnalysisFrameworkMembership,
)
from .serializers import (
AnalysisFrameworkCloneGlSerializer,
AnalysisFrameworkCloneSerializer,
AnalysisFrameworkGqlSerializer as AnalysisFrameworkSerializer,
AnalysisFrameworkMembershipGqlSerializer as AnalysisFrameworkMembershipSerializer,
)
Expand All @@ -39,7 +39,7 @@

AnalysisFrameworkCloneInputType = generate_input_type_for_serializer(
'AnalysisFrameworkCloneInputType',
serializer_class=AnalysisFrameworkCloneGlSerializer,
serializer_class=AnalysisFrameworkCloneSerializer,
)


Expand Down Expand Up @@ -107,7 +107,7 @@ class Arguments:
data = AnalysisFrameworkCloneInputType(required=True)

result = graphene.Field(AnalysisFrameworkDetailType)
serializer_class = AnalysisFrameworkCloneGlSerializer
serializer_class = AnalysisFrameworkCloneSerializer
permissions = [AfP.Permission.CAN_CLONE_FRAMEWORK]


Expand Down
23 changes: 6 additions & 17 deletions apps/analysis_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,26 +710,15 @@ def create(self, validated_data):
return super().create(validated_data)


class AnalysisFrameworkCloneGlSerializer(serializers.Serializer):
class AnalysisFrameworkCloneSerializer(serializers.Serializer):
title = serializers.CharField(required=True)
description = serializers.CharField(required=False)
project = serializers.IntegerField(required=False)
project = serializers.PrimaryKeyRelatedField(queryset=Project.objects.all(), required=False)

class Meta:
model = AnalysisFramework
fields = ('title', 'description', 'project')

def validate(self, validated_data):
project_id = validated_data.get('project')
# Check if project exists and user has access to it
if project_id is not None:
project = Project.objects.filter(id=project_id).first()
if project is None:
raise serializers.ValidationError('Invalid project ID')
if not project.can_modify(self.context['request'].user):
raise serializers.ValidationError('User does not have permission to modify the project')
validated_data['project'] = project
return validated_data
def validate_project(self, project):
if not project.can_modify(self.context['request'].user):
raise serializers.ValidationError('User does not have permission to modify the project')
return project

def create(self, validated_data):
af = self.context['request'].active_af
Expand Down
18 changes: 0 additions & 18 deletions apps/analysis_framework/tests/snapshots/snap_test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@

snapshots = Snapshot()

snapshots['TestAnalysisFrameworkMutationSnapShotTestCase::test_analysis_framework_clone success'] = {
'data': {
'__typename': 'Mutation',
'analysisFramework': {
'analysisFrameworkClone': {
'errors': None,
'ok': True,
'result': {
'clonedFrom': '1',
'description': 'Af description',
'id': '2',
'title': 'AF (TEST)'
}
}
}
}
}

snapshots['TestAnalysisFrameworkMutationSnapShotTestCase::test_analysis_framework_create errors'] = {
'data': {
'__typename': 'Mutation',
Expand Down
9 changes: 7 additions & 2 deletions apps/analysis_framework/tests/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,13 @@ def test_analysis_framework_clone(self):

member_user = UserFactory.create()
non_member_user = UserFactory.create()
low_permission_user = UserFactory.create()

project = ProjectFactory.create()
project.add_member(member_user)
project.add_member(low_permission_user)
af = AnalysisFrameworkFactory.create(created_by=member_user, title='AF Orginal')
af.add_member(member_user)
af.add_member(member_user, role=self.af_owner)

minput = dict(
title='AF (TEST)',
Expand All @@ -825,7 +827,6 @@ def _query_check(**kwargs):
# ---------- With login (with access member)
self.force_login(member_user)
response = _query_check()
self.assertMatchSnapshot(response, 'success')
self.assertEqual(response['data']['analysisFramework']['analysisFrameworkClone']['result']['clonedFrom'], str(af.id))

# adding project to the input
Expand All @@ -835,6 +836,10 @@ def _query_check(**kwargs):
self.force_login(non_member_user)
_query_check(assert_for_error=True)

# with Login (project member with no permission on AF)
self.force_login(low_permission_user)
_query_check(assert_for_error=True)

# With Login (project member)
self.force_login(member_user)
response = _query_check()['data']['analysisFramework']
Expand Down
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type AnalysisAutomaticSummaryType {
input AnalysisFrameworkCloneInputType {
title: String!
description: String
project: Int
project: ID
}

type AnalysisFrameworkDetailType {
Expand Down

0 comments on commit e951e78

Please sign in to comment.