summaryrefslogtreecommitdiff
path: root/app/serializers/group_child_entity.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-09-12 10:51:34 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 22:49:41 +0200
commit5998157618eafb69f6980f41639a7b485fe2467f (patch)
tree1c3235903eb02e89a41f61e4695c19e3cf712de1 /app/serializers/group_child_entity.rb
parent6388b8feec28b0f0ca2f9e6d9c5c7b4e404fed2f (diff)
downloadgitlab-ce-5998157618eafb69f6980f41639a7b485fe2467f.tar.gz
Include `can_leave` for a group
Diffstat (limited to 'app/serializers/group_child_entity.rb')
-rw-r--r--app/serializers/group_child_entity.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/serializers/group_child_entity.rb b/app/serializers/group_child_entity.rb
index ab0d8a32312..1940bc07eab 100644
--- a/app/serializers/group_child_entity.rb
+++ b/app/serializers/group_child_entity.rb
@@ -43,7 +43,7 @@ class GroupChildEntity < Grape::Entity
# Group only attributes
expose :children_count, :leave_path, :parent_id, :number_projects_with_delimiter,
- :number_users_with_delimiter, :project_count, :subgroup_count,
+ :number_users_with_delimiter, :project_count, :subgroup_count, :can_leave,
unless: lambda { |_instance, _options| project? }
def children_finder
@@ -66,6 +66,14 @@ class GroupChildEntity < Grape::Entity
leave_group_group_members_path(object)
end
+ def can_leave
+ if membership = object.members_and_requesters.find_by(user: request.current_user)
+ can?(request.current_user, :destroy_group_member, membership)
+ else
+ false
+ end
+ end
+
def number_projects_with_delimiter
number_with_delimiter(project_count)
end