Commit 470f9064 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #4206 from babatakao/authorize_all_teams_to_admin

Authorize all teams to admin: fix 500 error on showing team page.
parents cf9a366e 86a262de
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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)
......
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