summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-11-21 16:26:12 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-11-23 12:59:13 +0200
commit2ea5ef0ba4ee00b5551b88a6b9a68e045bf4b3f4 (patch)
tree4acb1567e751c407089f6f150fd8860b2478f762 /app
parent747959a832bddcdffba3e7c687b66904e8c6dbf9 (diff)
downloadgitlab-ce-2ea5ef0ba4ee00b5551b88a6b9a68e045bf4b3f4.tar.gz
Update ProjectTeam#fetch_members to use project authorizationsfix/drop-project-authorized-for-user
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/project_team.rb60
2 files changed, 8 insertions, 53 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 5d475c25e4a..bd9fcb2f3b7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -127,6 +127,7 @@ class Project < ActiveRecord::Base
has_many :protected_branches, dependent: :destroy
has_many :project_authorizations, dependent: :destroy
+ has_many :authorized_users, through: :project_authorizations, source: :user, class_name: 'User'
has_many :project_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source
alias_method :members, :project_members
has_many :users, through: :project_members
diff --git a/app/models/project_team.rb b/app/models/project_team.rb
index 1d0e97396f3..8a53e974b6f 100644
--- a/app/models/project_team.rb
+++ b/app/models/project_team.rb
@@ -80,19 +80,19 @@ class ProjectTeam
alias_method :users, :members
def guests
- @guests ||= fetch_members(:guests)
+ @guests ||= fetch_members(Gitlab::Access::GUEST)
end
def reporters
- @reporters ||= fetch_members(:reporters)
+ @reporters ||= fetch_members(Gitlab::Access::REPORTER)
end
def developers
- @developers ||= fetch_members(:developers)
+ @developers ||= fetch_members(Gitlab::Access::DEVELOPER)
end
def masters
- @masters ||= fetch_members(:masters)
+ @masters ||= fetch_members(Gitlab::Access::MASTER)
end
def import(source_project, current_user = nil)
@@ -185,59 +185,13 @@ class ProjectTeam
private
def fetch_members(level = nil)
- project_members = project.members
- group_members = group ? group.members : []
+ members = project.authorized_users
+ members = members.where(project_authorizations: { access_level: level }) if level
- if level
- project_members = project_members.public_send(level)
- group_members = group_members.public_send(level) if group
- end
-
- user_ids = project_members.pluck(:user_id)
-
- invited_members = fetch_invited_members(level)
- user_ids.push(*invited_members.map(&:user_id)) if invited_members.any?
-
- user_ids.push(*group_members.pluck(:user_id)) if group
-
- User.where(id: user_ids)
+ members
end
def group
project.group
end
-
- def project_shared_with_group?
- project.invited_groups.any? && project.allowed_to_share_with_group?
- end
-
- def fetch_invited_members(level = nil)
- invited_members = []
-
- return invited_members unless project_shared_with_group?
-
- project.project_group_links.includes(group: [:group_members]).each do |link|
- invited_group_members = link.group.members
-
- if level
- numeric_level = GroupMember.access_level_roles[level.to_s.singularize.titleize]
-
- # If we're asked for a level that's higher than the group's access,
- # there's nothing left to do
- next if numeric_level > link.group_access
-
- # Make sure we include everyone _above_ the requested level as well
- invited_group_members =
- if numeric_level == link.group_access
- invited_group_members.where("access_level >= ?", link.group_access)
- else
- invited_group_members.public_send(level)
- end
- end
-
- invited_members << invited_group_members
- end
-
- invited_members.flatten.compact
- end
end