Commit 6a3da45a authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '33878-fix-edit-deploy-key' into 'master'

Fix edit button for deploy keys available from other projects

Closes #33878

See merge request !12301
parents 4b0b2f15 c7bcebd5
...@@ -6,7 +6,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -6,7 +6,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
before_action :authorize_admin_project! before_action :authorize_admin_project!
before_action :authorize_update_deploy_key!, only: [:edit, :update] before_action :authorize_update_deploy_key!, only: [:edit, :update]
layout "project_settings" layout 'project_settings'
def index def index
respond_to do |format| respond_to do |format|
...@@ -66,7 +66,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -66,7 +66,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
protected protected
def deploy_key def deploy_key
@deploy_key ||= @project.deploy_keys.find(params[:id]) @deploy_key ||= DeployKey.find(params[:id])
end end
def create_params def create_params
......
---
title: Fix edit button for deploy keys available from other projects
merge_request: 12301
author: Alexander Randa
...@@ -86,7 +86,7 @@ module API ...@@ -86,7 +86,7 @@ module API
at_least_one_of :title, :can_push at_least_one_of :title, :can_push
end end
put ":id/deploy_keys/:key_id" do put ":id/deploy_keys/:key_id" do
key = user_project.deploy_keys.find(params.delete(:key_id)) key = DeployKey.find(params.delete(:key_id))
authorize!(:update_deploy_key, key) authorize!(:update_deploy_key, key)
......
...@@ -65,6 +65,23 @@ feature 'Repository settings', feature: true do ...@@ -65,6 +65,23 @@ feature 'Repository settings', feature: true do
expect(page).to have_content('Write access allowed') expect(page).to have_content('Write access allowed')
end end
scenario 'edit a deploy key from projects user has access to' do
project2 = create(:project_empty_repo)
project2.team << [user, role]
project2.deploy_keys << private_deploy_key
visit namespace_project_settings_repository_path(project.namespace, project)
find('li', text: private_deploy_key.title).click_link('Edit')
fill_in 'deploy_key_title', with: 'updated_deploy_key'
check 'deploy_key_can_push'
click_button 'Save changes'
expect(page).to have_content('updated_deploy_key')
expect(page).to have_content('Write access allowed')
end
scenario 'remove an existing deploy key' do scenario 'remove an existing deploy key' do
project.deploy_keys << private_deploy_key project.deploy_keys << private_deploy_key
visit namespace_project_settings_repository_path(project.namespace, project) visit namespace_project_settings_repository_path(project.namespace, project)
......
...@@ -160,6 +160,16 @@ describe API::DeployKeys do ...@@ -160,6 +160,16 @@ describe API::DeployKeys do
expect(json_response['title']).to eq('new title') expect(json_response['title']).to eq('new title')
expect(json_response['can_push']).to eq(true) expect(json_response['can_push']).to eq(true)
end end
it 'updates a private ssh key from projects user has access with correct attributes' do
create(:deploy_keys_project, project: project2, deploy_key: private_deploy_key)
put api("/projects/#{project.id}/deploy_keys/#{private_deploy_key.id}", admin), { title: 'new title', can_push: true }
expect(json_response['id']).to eq(private_deploy_key.id)
expect(json_response['title']).to eq('new title')
expect(json_response['can_push']).to eq(true)
end
end end
describe 'DELETE /projects/:id/deploy_keys/:key_id' do describe 'DELETE /projects/:id/deploy_keys/:key_id' 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