summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-10-11 14:25:17 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-11-18 20:25:45 +0200
commitfd05e26618dd0c123ca476b6f5a3d85f1cfe397a (patch)
tree39a4ac60382ca7ce8d46e3745ba8a381580d6314 /app/models/group.rb
parentaea8baed3093c513560e9ac5ac0c5c99508d3001 (diff)
downloadgitlab-ce-fd05e26618dd0c123ca476b6f5a3d85f1cfe397a.tar.gz
Precalculate user's authorized projects in database
Closes #23150
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index d9e90cd256a..73b0f1c6572 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -5,6 +5,7 @@ class Group < Namespace
include Gitlab::VisibilityLevel
include AccessRequestable
include Referable
+ include SelectForProjectAuthorization
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source
alias_method :members, :group_members
@@ -61,6 +62,14 @@ class Group < Namespace
def visible_to_user(user)
where(id: user.authorized_groups.select(:id).reorder(nil))
end
+
+ def select_for_project_authorization
+ if current_scope.joins_values.include?(:shared_projects)
+ select("members.user_id, projects.id AS project_id, project_group_links.group_access")
+ else
+ super
+ end
+ end
end
def to_reference(_from_project = nil)
@@ -176,4 +185,8 @@ class Group < Namespace
def system_hook_service
SystemHooksService.new
end
+
+ def refresh_members_authorized_projects
+ UserProjectAccessChangedService.new(users.pluck(:id)).execute
+ end
end