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