Commit 9b6c513b authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-group-convenience-methods' into 'master'

Add `Group#add_*` convenience methods

Encapsulates the logic for `Gitlab::Access::WHATEVER` levels.

See merge request !1111
parents 4b7c2f0b fb6dc1f0
...@@ -76,8 +76,24 @@ class Group < Namespace ...@@ -76,8 +76,24 @@ class Group < Namespace
add_users([user], access_level, current_user) add_users([user], access_level, current_user)
end end
def add_guest(user, current_user = nil)
add_user(user, Gitlab::Access::GUEST, current_user)
end
def add_reporter(user, current_user = nil)
add_user(user, Gitlab::Access::REPORTER, current_user)
end
def add_developer(user, current_user = nil)
add_user(user, Gitlab::Access::DEVELOPER, current_user)
end
def add_master(user, current_user = nil)
add_user(user, Gitlab::Access::MASTER, current_user)
end
def add_owner(user, current_user = nil) def add_owner(user, current_user = nil)
self.add_user(user, Gitlab::Access::OWNER, current_user) add_user(user, Gitlab::Access::OWNER, current_user)
end end
def has_owner?(user) def has_owner?(user)
......
...@@ -58,7 +58,7 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps ...@@ -58,7 +58,7 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps
end end
step 'we have user "John Doe" in group' do step 'we have user "John Doe" in group' do
current_group.add_user(user_john, Gitlab::Access::REPORTER) current_group.add_reporter(user_john)
end end
step 'I remove user "John Doe" from group' do step 'I remove user "John Doe" from group' do
......
...@@ -79,7 +79,7 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps ...@@ -79,7 +79,7 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps
project.team << [user, :developer] project.team << [user, :developer]
group = create(:group) group = create(:group)
group.add_user(user, Gitlab::Access::DEVELOPER) group.add_developer(user)
end end
step 'click on "Mike" link' do step 'click on "Mike" link' do
......
...@@ -19,7 +19,7 @@ class Spinach::Features::ExploreGroups < Spinach::FeatureSteps ...@@ -19,7 +19,7 @@ class Spinach::Features::ExploreGroups < Spinach::FeatureSteps
step '"John Doe" is owner of group "TestGroup"' do step '"John Doe" is owner of group "TestGroup"' do
group = Group.find_by(name: "TestGroup") || create(:group, name: "TestGroup") group = Group.find_by(name: "TestGroup") || create(:group, name: "TestGroup")
user = create(:user, name: "John Doe") user = create(:user, name: "John Doe")
group.add_user(user, Gitlab::Access::OWNER) group.add_owner(user)
end end
step 'I visit group "TestGroup" page' do step 'I visit group "TestGroup" page' do
......
...@@ -6,7 +6,7 @@ class Spinach::Features::Invites < Spinach::FeatureSteps ...@@ -6,7 +6,7 @@ class Spinach::Features::Invites < Spinach::FeatureSteps
step '"John Doe" has invited "user@example.com" to group "Owned"' do step '"John Doe" has invited "user@example.com" to group "Owned"' do
user = User.find_by(name: "John Doe") user = User.find_by(name: "John Doe")
group = Group.find_by(name: "Owned") group = Group.find_by(name: "Owned")
group.add_user("user@example.com", Gitlab::Access::DEVELOPER, user) group.add_developer("user@example.com", user)
end end
step 'I visit the invitation page' do step 'I visit the invitation page' do
......
...@@ -39,7 +39,7 @@ describe ProjectsFinder do ...@@ -39,7 +39,7 @@ describe ProjectsFinder do
end end
context 'authenticated, group member' do context 'authenticated, group member' do
before { group.add_user(user, Gitlab::Access::DEVELOPER) } before { group.add_developer(user) }
subject { ProjectsFinder.new.execute(user, group: group) } subject { ProjectsFinder.new.execute(user, group: group) }
......
...@@ -77,7 +77,7 @@ module Gitlab::Markdown ...@@ -77,7 +77,7 @@ module Gitlab::Markdown
context 'that the current user can read' do context 'that the current user can read' do
before do before do
group.add_user(user, Gitlab::Access::DEVELOPER) group.add_developer(user)
end end
it 'links to the Group' do it 'links to the Group' do
......
...@@ -101,7 +101,7 @@ describe SystemHook do ...@@ -101,7 +101,7 @@ describe SystemHook do
it 'group member create hook' do it 'group member create hook' do
group = create(:group) group = create(:group)
user = create(:user) user = create(:user)
group.add_user(user, Gitlab::Access::MASTER) group.add_master(user)
expect(WebMock).to have_requested(:post, @system_hook.url).with( expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /user_add_to_group/, body: /user_add_to_group/,
headers: { 'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook' } headers: { 'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook' }
...@@ -111,7 +111,7 @@ describe SystemHook do ...@@ -111,7 +111,7 @@ describe SystemHook do
it 'group member destroy hook' do it 'group member destroy hook' do
group = create(:group) group = create(:group)
user = create(:user) user = create(:user)
group.add_user(user, Gitlab::Access::MASTER) group.add_master(user)
group.group_members.destroy_all group.group_members.destroy_all
expect(WebMock).to have_requested(:post, @system_hook.url).with( expect(WebMock).to have_requested(:post, @system_hook.url).with(
body: /user_remove_from_group/, body: /user_remove_from_group/,
......
...@@ -37,9 +37,9 @@ describe ProjectTeam do ...@@ -37,9 +37,9 @@ describe ProjectTeam do
let(:project) { create(:empty_project, group: group) } let(:project) { create(:empty_project, group: group) }
before do before do
group.add_user(master, Gitlab::Access::MASTER) group.add_master(master)
group.add_user(reporter, Gitlab::Access::REPORTER) group.add_reporter(reporter)
group.add_user(guest, Gitlab::Access::GUEST) group.add_guest(guest)
# If user is a group and a project member - GitLab uses highest permission # If user is a group and a project member - GitLab uses highest permission
# So we add group guest as master and add group master as guest # So we add group guest as master and add group master as guest
......
...@@ -135,7 +135,7 @@ describe API::API, api: true do ...@@ -135,7 +135,7 @@ describe API::API, api: true do
it "should not remove a group if not an owner" do it "should not remove a group if not an owner" do
user4 = create(:user) user4 = create(:user)
group1.add_user(user4, Gitlab::Access::MASTER) group1.add_master(user4)
delete api("/groups/#{group1.id}", user3) delete api("/groups/#{group1.id}", user3)
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
......
...@@ -17,7 +17,7 @@ class MarkdownFeature ...@@ -17,7 +17,7 @@ class MarkdownFeature
def group def group
unless @group unless @group
@group = create(:group) @group = create(:group)
@group.add_user(user, Gitlab::Access::DEVELOPER) @group.add_developer(user)
end end
@group @group
......
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