Skip to content

Commit

Permalink
Add mutation of leave project
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Dec 5, 2024
1 parent 047c53d commit 9791709
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
3 changes: 0 additions & 3 deletions apps/project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
ProjectOrganization,
ProjectChangeLog,
ProjectPinned,
ProjectJoinRequest
)
TRIGGER_LIMIT = 5

Expand Down Expand Up @@ -230,14 +229,12 @@ def get_readonly_fields(self, request, obj=None):
return self.readonly_fields



@admin.register(ProjectJoinRequest)
class ProjectJoinAdmin(admin.ModelAdmin):
search_fields = ['project__title']
autocomplete_fields = ('requested_by', 'responded_by', 'project')
list_display = ['project', 'requested_by', 'responded_by', 'status']


def get_readonly_fields(self, request, obj=None):
# editing an existing object
if obj:
Expand Down
7 changes: 3 additions & 4 deletions apps/project/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
UserPinnedProjectSerializer,
BulkProjectPinnedSerializer,
UserProjectLeaveSerializer

)
from .schema import (
ProjectDetailType,
Expand Down Expand Up @@ -359,11 +358,13 @@ class LeaveProject(ProjectScopeMixin, graphene.Mutation):
@classmethod
def mutate(cls, root, info, **kwargs):
project = info.context.active_project
serializer = UserProjectLeaveSerializer(data ={} ,context={'request': info.context.request})
serializer = UserProjectLeaveSerializer(data={}, context={'request': info.context.request})
if serializer.is_valid():
serializer.save()
return LeaveProject(ok=True, result=project)
return LeaveProject(ok=False, errors=serializer.errors)


class ProjectMutationType(
# --Begin Project Scoped Mutation
LeadMutation,
Expand Down Expand Up @@ -395,7 +396,6 @@ class Meta:
assisted_tagging = graphene.Field(AssistedTaggingMutationType)
leave_project = LeaveProject.Field()


@staticmethod
def get_custom_node(_, info, id):
try:
Expand Down Expand Up @@ -473,7 +473,6 @@ def mutate(root, info, id):
return DeleteUserPinnedProject(result=root, errors=None, ok=True)



class Mutation(object):
project_create = CreateProject.Field()
join_project = CreateProjectJoin.Field()
Expand Down
7 changes: 3 additions & 4 deletions apps/project/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from .activity import project_activity_log



class SimpleProjectSerializer(RemoveNullFieldsMixin,
serializers.ModelSerializer):
class Meta:
Expand Down Expand Up @@ -970,11 +969,11 @@ def validate(self, data):
)
if membership.count() == 1:
raise serializers.ValidationError('Cannot leave the project')
if membership.filter(role == ProjectRole.get_owner_role()).count() == 1:
if membership.filter(role=ProjectRole.get_owner_role()).count() == 1:
raise serializers.ValidationError('Cannot leave the project')
return data

def create(self, data):
ProjectJoinRequest.objects.filter(project=self.project, requested_by=self.current_user).delete()
ProjectMembership.objects.filter(project=self.project, member=self.current_user).delete()
return data
return data

0 comments on commit 9791709

Please sign in to comment.