Commit 59981576 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Include `can_leave` for a group

parent ab1568057242
......@@ -43,7 +43,7 @@ def permission
# 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 @@ def leave_path
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 @@
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