Commit 6f900028 authored by Etienne Baqué's avatar Etienne Baqué

Applied reviewer suggestions

parent d1ff11b5
...@@ -53,7 +53,9 @@ class AutocompleteController < ApplicationController ...@@ -53,7 +53,9 @@ class AutocompleteController < ApplicationController
end end
def deploy_keys_with_owners def deploy_keys_with_owners
render json: DeployKeySerializer.new.represent(DeployKey.with_write_access_for_project(project), { with_owner: true, user: current_user }) deploy_keys = DeployKey.with_write_access_for_project(project)
render json: DeployKeySerializer.new.represent(deploy_keys, { with_owner: true, user: current_user })
end end
private private
......
...@@ -8,7 +8,7 @@ class DeployKey < Key ...@@ -8,7 +8,7 @@ class DeployKey < Key
has_many :projects, through: :deploy_keys_projects has_many :projects, through: :deploy_keys_projects
scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where(deploy_keys_projects: { project_id: projects }) } scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where(deploy_keys_projects: { project_id: projects }) }
scope :with_write_access, -> { joins(:deploy_keys_projects).where(deploy_keys_projects: { can_push: true }) } scope :with_write_access, -> { joins(:deploy_keys_projects).merge(DeployKeysProject.with_write_access) }
scope :are_public, -> { where(public: true) } scope :are_public, -> { where(public: true) }
scope :with_projects, -> { includes(deploy_keys_projects: { project: [:route, namespace: :route] }) } scope :with_projects, -> { includes(deploy_keys_projects: { project: [:route, namespace: :route] }) }
...@@ -57,8 +57,8 @@ class DeployKey < Key ...@@ -57,8 +57,8 @@ class DeployKey < Key
end end
def self.with_write_access_for_project(project, deploy_key: nil) def self.with_write_access_for_project(project, deploy_key: nil)
query = in_projects(project&.id).with_write_access query = in_projects(project).with_write_access
query = query.where(id: deploy_key.id) if deploy_key query = query.where(id: deploy_key) if deploy_key
query query
end end
......
...@@ -59,14 +59,14 @@ RSpec.describe DeployKey, :mailer do ...@@ -59,14 +59,14 @@ RSpec.describe DeployKey, :mailer do
it 'only returns deploy keys with write access' do it 'only returns deploy keys with write access' do
create(:deploy_keys_project, project: project) create(:deploy_keys_project, project: project)
expect(subject).to contain_exactly(deploy_key) is_expected.to contain_exactly(deploy_key)
end end
it 'returns deploy keys only for this project' do it 'returns deploy keys only for this project' do
other_project = create(:project) other_project = create(:project)
create(:deploy_keys_project, :write_access, project: other_project) create(:deploy_keys_project, :write_access, project: other_project)
expect(subject).to contain_exactly(deploy_key) is_expected.to contain_exactly(deploy_key)
end end
context 'and a specific deploy key is passed in' do context 'and a specific deploy key is passed in' do
......
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