summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-06 07:14:50 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-06 07:14:50 -0700
commit470f9064facd7a5452947ea7d3b650ea885c2195 (patch)
treeab3d74d5b33442a22297852752e6535bbc145415
parentcf9a366e22f731118b19de8a9922fb8df20e86a3 (diff)
parent86a262de1af7f34629276f584a7af45fcd08b871 (diff)
downloadgitlab-ce-470f9064facd7a5452947ea7d3b650ea885c2195.tar.gz
Merge pull request #4206 from babatakao/authorize_all_teams_to_admin
Authorize all teams to admin: fix 500 error on showing team page.
-rw-r--r--app/models/ability.rb2
-rw-r--r--app/models/user.rb8
-rw-r--r--app/models/user_team.rb2
-rw-r--r--spec/models/user_spec.rb17
4 files changed, 25 insertions, 4 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 13fbc114629..0b6314cd555 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -146,7 +146,7 @@ class Ability
rules = []
# Only group owner and administrators can manage team
- if team.owner == user || team.admin?(user) || user.admin?
+ if user.admin? || team.owner == user || team.admin?(user)
rules << [ :manage_user_team ]
end
diff --git a/app/models/user.rb b/app/models/user.rb
index a1244f9a489..3f51d7a9938 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -247,8 +247,12 @@ class User < ActiveRecord::Base
end
def authorized_teams
- @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq
- UserTeam.where(id: @team_ids)
+ if admin?
+ UserTeam.scoped
+ else
+ @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq
+ UserTeam.where(id: @team_ids)
+ end
end
# Team membership in authorized projects
diff --git a/app/models/user_team.rb b/app/models/user_team.rb
index 364ea0d7dd1..a036cedc4c7 100644
--- a/app/models/user_team.rb
+++ b/app/models/user_team.rb
@@ -111,6 +111,6 @@ class UserTeam < ActiveRecord::Base
end
def admin?(member)
- user_team_user_relationships.with_user(member).first.group_admin?
+ user_team_user_relationships.with_user(member).first.try(:group_admin?)
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index f0a6012d0c2..4dd2048ccad 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -148,6 +148,23 @@ describe User do
it { @user.owned_groups.should == [@group] }
end
+ describe 'teams' do
+ before do
+ ActiveRecord::Base.observers.enable(:user_observer)
+ @admin = create :user, admin: true
+ @user1 = create :user
+ @user2 = create :user
+ @team = create :user_team, owner: @user1
+ end
+
+ it { @admin.authorized_teams.should == [@team] }
+ it { @user1.authorized_teams.should == [@team] }
+ it { @user2.authorized_teams.should be_empty }
+ it { @admin.should be_can(:manage_user_team, @team) }
+ it { @user1.should be_can(:manage_user_team, @team) }
+ it { @user2.should_not be_can(:manage_user_team, @team) }
+ end
+
describe 'namespaced' do
before do
ActiveRecord::Base.observers.enable(:user_observer)