Skip to content

Commit

Permalink
Implement leave project
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Dec 5, 2024
1 parent 9648de4 commit 46196fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class ProjectMembershipAdmin(admin.ModelAdmin):
list_filter = (
AutocompleteFilterFactory('Project', 'project'),
)
list_display = ['project', 'member']
list_display = ['project', 'member', 'role', 'added_by']

def get_readonly_fields(self, request, obj=None):
# editing an existing object
Expand Down
10 changes: 7 additions & 3 deletions apps/project/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,13 @@ def validate(self, data):
project=self.project,
)
if membership.count() == 1:
raise serializers.ValidationError('Cannot leave the project')
if membership.filter(role=ProjectRole.get_owner_role()).count() == 1:
raise serializers.ValidationError('Cannot leave the project')
raise serializers.ValidationError('Last member of project can\'t leave')

if (
membership.filter(role=ProjectRole.get_owner_role()).count() == 1 and
membership.member == self.current_user
):
raise serializers.ValidationError('Last owner of project can\'t leave')
return data

def create(self, data):
Expand Down

0 comments on commit 46196fe

Please sign in to comment.