Commit 86a262de1af7f34629276f584a7af45fcd08b871
1 parent
b9d989dc
Exists in
master
and in
4 other branches
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.
Showing
4 changed files
with
25 additions
and
4 deletions
Show diff stats
app/models/ability.rb
... | ... | @@ -125,7 +125,7 @@ class Ability |
125 | 125 | rules = [] |
126 | 126 | |
127 | 127 | # Only group owner and administrators can manage team |
128 | - if team.owner == user || team.admin?(user) || user.admin? | |
128 | + if user.admin? || team.owner == user || team.admin?(user) | |
129 | 129 | rules << [ :manage_user_team ] |
130 | 130 | end |
131 | 131 | ... | ... |
app/models/user.rb
... | ... | @@ -245,8 +245,12 @@ class User < ActiveRecord::Base |
245 | 245 | end |
246 | 246 | |
247 | 247 | def authorized_teams |
248 | - @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq | |
249 | - UserTeam.where(id: @team_ids) | |
248 | + if admin? | |
249 | + UserTeam.scoped | |
250 | + else | |
251 | + @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq | |
252 | + UserTeam.where(id: @team_ids) | |
253 | + end | |
250 | 254 | end |
251 | 255 | |
252 | 256 | # Team membership in authorized projects | ... | ... |
app/models/user_team.rb
spec/models/user_spec.rb
... | ... | @@ -126,6 +126,23 @@ describe User do |
126 | 126 | it { @user.owned_groups.should == [@group] } |
127 | 127 | end |
128 | 128 | |
129 | + describe 'teams' do | |
130 | + before do | |
131 | + ActiveRecord::Base.observers.enable(:user_observer) | |
132 | + @admin = create :user, admin: true | |
133 | + @user1 = create :user | |
134 | + @user2 = create :user | |
135 | + @team = create :user_team, owner: @user1 | |
136 | + end | |
137 | + | |
138 | + it { @admin.authorized_teams.should == [@team] } | |
139 | + it { @user1.authorized_teams.should == [@team] } | |
140 | + it { @user2.authorized_teams.should be_empty } | |
141 | + it { @admin.should be_can(:manage_user_team, @team) } | |
142 | + it { @user1.should be_can(:manage_user_team, @team) } | |
143 | + it { @user2.should_not be_can(:manage_user_team, @team) } | |
144 | + end | |
145 | + | |
129 | 146 | describe 'namespaced' do |
130 | 147 | before do |
131 | 148 | ActiveRecord::Base.observers.enable(:user_observer) | ... | ... |