Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2019-01-15 20:57:17 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2019-01-16 20:54:05 +0300
commitab94a5a53712740df3836413bf26e4856b5f7cb2 (patch)
treeb712300e7011586c86a833232b9afed3c0332f96 /spec/models/group_spec.rb
parentf821a53b45d4b521ffb734b3b843f48e0d1ecfcd (diff)
Return max group access level in the projects API
Currently if a project is inside a nested group and a user doesn't have specific permissions for that group but does have permissions on a parent group the `GET /projects/:id` API call will return the following permissions: ```json permissions: { project_access: null, group_access: null } ``` It could also happen that the group specific permissions are of lower level than the ones the user has in parent groups. This patch makes it so that the permission returned for `group_access` is the highest from amongst the hierarchy, which is (ostensibly) the information that the API user is interested in for that field.
Diffstat (limited to 'spec/models/group_spec.rb')
-rw-r--r--spec/models/group_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index e63881242f6..9dc32a815d8 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -722,6 +722,42 @@ describe Group do
end
end
+ describe '#highest_group_member', :nested_groups do
+ let(:nested_group) { create(:group, parent: group) }
+ let(:nested_group_2) { create(:group, parent: nested_group) }
+ let(:user) { create(:user) }
+
+ subject(:highest_group_member) { nested_group_2.highest_group_member(user) }
+
+ context 'when the user is not a member of any group in the hierarchy' do
+ it 'returns nil' do
+ expect(highest_group_member).to be_nil
+ end
+ end
+
+ context 'when the user is only a member of one group in the hierarchy' do
+ before do
+ nested_group.add_developer(user)
+ end
+
+ it 'returns that group member' do
+ expect(highest_group_member.access_level).to eq(Gitlab::Access::DEVELOPER)
+ end
+ end
+
+ context 'when the user is a member of several groups in the hierarchy' do
+ before do
+ group.add_owner(user)
+ nested_group.add_developer(user)
+ nested_group_2.add_maintainer(user)
+ end
+
+ it 'returns the group member with the highest access level' do
+ expect(highest_group_member.access_level).to eq(Gitlab::Access::OWNER)
+ end
+ end
+ end
+
describe '#has_parent?' do
context 'when the group has a parent' do
it 'should be truthy' do