Commit 7d57b96e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Update authorized/owned resources with new group permissions

parent 5bed576a
...@@ -71,7 +71,9 @@ class User < ActiveRecord::Base ...@@ -71,7 +71,9 @@ class User < ActiveRecord::Base
has_many :keys, dependent: :destroy has_many :keys, dependent: :destroy
# Groups # Groups
has_many :groups, class_name: "Group", foreign_key: :owner_id has_many :own_groups, class_name: "Group", foreign_key: :owner_id
has_many :users_groups, dependent: :destroy
has_many :groups, through: :users_groups
# Teams # Teams
has_many :own_teams, dependent: :destroy, class_name: "UserTeam", foreign_key: :owner_id has_many :own_teams, dependent: :destroy, class_name: "UserTeam", foreign_key: :owner_id
...@@ -230,7 +232,7 @@ class User < ActiveRecord::Base ...@@ -230,7 +232,7 @@ class User < ActiveRecord::Base
# Groups where user is an owner # Groups where user is an owner
def owned_groups def owned_groups
groups own_groups
end end
def owned_teams def owned_teams
...@@ -239,14 +241,14 @@ class User < ActiveRecord::Base ...@@ -239,14 +241,14 @@ class User < ActiveRecord::Base
# Groups user has access to # Groups user has access to
def authorized_groups def authorized_groups
@group_ids ||= (groups.pluck(:id) + authorized_projects.pluck(:namespace_id)) @group_ids ||= (groups.pluck(:id) + own_groups.pluck(:id) + authorized_projects.pluck(:namespace_id))
Group.where(id: @group_ids) Group.where(id: @group_ids)
end end
# Projects user has access to # Projects user has access to
def authorized_projects def authorized_projects
@project_ids ||= (owned_projects.pluck(:id) + projects.pluck(:id)).uniq @project_ids ||= (owned_projects.pluck(:id) + groups.map(&:projects).flatten.map(&:id) + projects.pluck(:id)).uniq
Project.where(id: @project_ids) Project.where(id: @project_ids)
end end
......
- can_manage_group = current_user.can? :manage_group, @group - can_manage_group = current_user.can? :manage_group, @group
.row .row
.span6 .span6
- if can_manage_group
= render "new_group_member" = render "new_group_member"
- else
.light-well
%h4.nothing_here_message
Only group owners can manage group members
.span6 .span6
.ui-box .ui-box
%h5.title %h5.title
......
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