diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/models/deploy_key.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/models/deploy_key.rb')
-rw-r--r-- | app/models/deploy_key.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb index 793ea3c29c3..db5fd167781 100644 --- a/app/models/deploy_key.rb +++ b/app/models/deploy_key.rb @@ -6,9 +6,11 @@ class DeployKey < Key has_many :deploy_keys_projects, inverse_of: :deploy_key, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :projects, through: :deploy_keys_projects + has_many :protected_branch_push_access_levels, class_name: '::ProtectedBranch::PushAccessLevel' - scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) } - scope :are_public, -> { where(public: true) } + scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where(deploy_keys_projects: { project_id: projects }) } + scope :with_write_access, -> { joins(:deploy_keys_projects).merge(DeployKeysProject.with_write_access) } + scope :are_public, -> { where(public: true) } scope :with_projects, -> { includes(deploy_keys_projects: { project: [:route, namespace: :route] }) } ignore_column :can_push, remove_after: '2019-12-15', remove_with: '12.6' @@ -54,4 +56,11 @@ class DeployKey < Key def projects_with_write_access Project.with_route.where(id: deploy_keys_projects.with_write_access.select(:project_id)) end + + def self.with_write_access_for_project(project, deploy_key: nil) + query = in_projects(project).with_write_access + query = query.where(id: deploy_key) if deploy_key + + query + end end |