BigW Consortium Gitlab

Commit 59981576 by Bob Van Landuyt

Include `can_leave` for a group

parent 6388b8fe
......@@ -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
......
......@@ -83,6 +83,12 @@ describe GroupChildEntity do
end
end
it 'allows an owner to leave when there is another one' do
object.add_owner(create(:user))
expect(json[:can_leave]).to be_truthy
end
it_behaves_like 'group child json'
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment