Commit 470f9064facd7a5452947ea7d3b650ea885c2195
Exists in
master
and in
4 other branches
Merge pull request #4206 from babatakao/authorize_all_teams_to_admin
Authorize all teams to admin: fix 500 error on showing team page.
Showing
4 changed files
with
25 additions
and
4 deletions
Show diff stats
app/models/ability.rb
| ... | ... | @@ -146,7 +146,7 @@ class Ability |
| 146 | 146 | rules = [] |
| 147 | 147 | |
| 148 | 148 | # Only group owner and administrators can manage team |
| 149 | - if team.owner == user || team.admin?(user) || user.admin? | |
| 149 | + if user.admin? || team.owner == user || team.admin?(user) | |
| 150 | 150 | rules << [ :manage_user_team ] |
| 151 | 151 | end |
| 152 | 152 | ... | ... |
app/models/user.rb
| ... | ... | @@ -247,8 +247,12 @@ class User < ActiveRecord::Base |
| 247 | 247 | end |
| 248 | 248 | |
| 249 | 249 | def authorized_teams |
| 250 | - @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq | |
| 251 | - UserTeam.where(id: @team_ids) | |
| 250 | + if admin? | |
| 251 | + UserTeam.scoped | |
| 252 | + else | |
| 253 | + @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq | |
| 254 | + UserTeam.where(id: @team_ids) | |
| 255 | + end | |
| 252 | 256 | end |
| 253 | 257 | |
| 254 | 258 | # Team membership in authorized projects | ... | ... |
app/models/user_team.rb
spec/models/user_spec.rb
| ... | ... | @@ -148,6 +148,23 @@ describe User do |
| 148 | 148 | it { @user.owned_groups.should == [@group] } |
| 149 | 149 | end |
| 150 | 150 | |
| 151 | + describe 'teams' do | |
| 152 | + before do | |
| 153 | + ActiveRecord::Base.observers.enable(:user_observer) | |
| 154 | + @admin = create :user, admin: true | |
| 155 | + @user1 = create :user | |
| 156 | + @user2 = create :user | |
| 157 | + @team = create :user_team, owner: @user1 | |
| 158 | + end | |
| 159 | + | |
| 160 | + it { @admin.authorized_teams.should == [@team] } | |
| 161 | + it { @user1.authorized_teams.should == [@team] } | |
| 162 | + it { @user2.authorized_teams.should be_empty } | |
| 163 | + it { @admin.should be_can(:manage_user_team, @team) } | |
| 164 | + it { @user1.should be_can(:manage_user_team, @team) } | |
| 165 | + it { @user2.should_not be_can(:manage_user_team, @team) } | |
| 166 | + end | |
| 167 | + | |
| 151 | 168 | describe 'namespaced' do |
| 152 | 169 | before do |
| 153 | 170 | ActiveRecord::Base.observers.enable(:user_observer) | ... | ... |