Commit 86a262de authored by babatakao's avatar babatakao

Authorize all teams to admin: fix 500 error on showing team page.

500 error was occured in the following steps:

1. user1 creates new team "team1".
2. Assign team1 to project1.
3. Sign in as admin. This admin is not a member of team1.
4. Open project1 team setting page (/project1/team).
5. Click "team1" link in "Assigned teams" area.
6. 500 error.

Fixed this issue.
parent b9d989dc
......@@ -125,7 +125,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
......
......@@ -245,9 +245,13 @@ class User < ActiveRecord::Base
end
def authorized_teams
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
def tm_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
......@@ -126,6 +126,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