diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/ability.rb | 8 | ||||
-rw-r--r-- | app/models/project_team.rb | 16 | ||||
-rw-r--r-- | spec/models/project_team_spec.rb | 35 |
4 files changed, 49 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG index 02e2840ffec..760218690b0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ v 7.0.0 - UI improvements - Case-insensetive search for issues - Update to rails 4.1 + - Improve performance of application for projects and groups with a lot of members v 6.9.2 - Revert the commit that broke the LDAP user filter diff --git a/app/models/ability.rb b/app/models/ability.rb index 70c26caded8..df9b210dfca 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -71,16 +71,16 @@ class Ability team = project.team # Rules based on role in project - if team.masters.include?(user) + if team.master?(user) rules += project_master_rules - elsif team.developers.include?(user) + elsif team.developer?(user) rules += project_dev_rules - elsif team.reporters.include?(user) + elsif team.reporter?(user) rules += project_report_rules - elsif team.guests.include?(user) + elsif team.guest?(user) rules += project_guest_rules end diff --git a/app/models/project_team.rb b/app/models/project_team.rb index eca13e56061..639f78dcd3f 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -117,6 +117,22 @@ class ProjectTeam false end + def guest?(user) + find_tm(user.id).access_field == Gitlab::Access::GUEST + end + + def reporter?(user) + find_tm(user.id).access_field == Gitlab::Access::REPORTER + end + + def developer?(user) + find_tm(user.id).access_field == Gitlab::Access::DEVELOPER + end + + def master?(user) + find_tm(user.id).access_field == Gitlab::Access::MASTER + end + private def fetch_members(level = nil) diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index 3e3543e85e1..1a7e3cd94b4 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -1,15 +1,36 @@ require "spec_helper" describe ProjectTeam do - let(:team) { create(:project).team } + let(:group) { create(:group) } + let(:project) { create(:empty_project, group: group) } - describe "Respond to" do - subject { team } + let(:master) { create(:user) } + let(:reporter) { create(:user) } + let(:guest) { create(:user) } + let(:nonmember) { create(:user) } - it { should respond_to(:developers) } - it { should respond_to(:masters) } - it { should respond_to(:reporters) } - it { should respond_to(:guests) } + before do + group.add_user(master, Gitlab::Access::MASTER) + group.add_user(reporter, Gitlab::Access::REPORTER) + group.add_user(guest, Gitlab::Access::GUEST) + + # Add group guest as master to this project + # to test project access priority over group members + project.team << [guest, :master] + end + + describe 'members collection' do + it { team.masters.should include(master) } + it { team.masters.should include(guest) } + it { team.masters.should_not include(reporter) } + it { team.masters.should_not include(nonmember) } + end + + describe 'access methods' do + it { team.master?(master).should be_true } + it { team.master?(guest).should be_true } + it { team.master?(reporter).should be_false } + it { team.master?(nonmember).should be_false } end end |