summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2017-06-21 12:18:27 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2017-06-21 12:18:27 +0000
commit7d0d6a8245361db0863d0258ffc9d3b669c6477d (patch)
tree80817ebee63dd6229f81d247d5592d0ad1e471be
parent090ed087f0aba10dff142e48d97259fec28b89bb (diff)
parent853d06b99f4ea5ab718f15c03bfed42288d527d4 (diff)
downloadgitlab-ce-7d0d6a8245361db0863d0258ffc9d3b669c6477d.tar.gz
Merge branch 'master' into 'fix/gb/improve-build-stage-reference-migration'
# Conflicts: # db/schema.rb
-rw-r--r--app/controllers/projects/deploy_keys_controller.rb4
-rw-r--r--changelogs/unreleased/33878_fix_edit_deploy_key.yml4
-rw-r--r--db/fixtures/development/19_environments.rb2
-rw-r--r--db/migrate/20170619144837_add_index_for_head_pipeline_merge_request.rb15
-rw-r--r--db/schema.rb1
-rw-r--r--lib/api/deploy_keys.rb2
-rw-r--r--lib/gitlab/regex.rb2
-rw-r--r--spec/features/projects/settings/repository_settings_spec.rb17
-rw-r--r--spec/lib/gitlab/regex_spec.rb12
-rw-r--r--spec/requests/api/deploy_keys_spec.rb10
10 files changed, 64 insertions, 5 deletions
diff --git a/app/controllers/projects/deploy_keys_controller.rb b/app/controllers/projects/deploy_keys_controller.rb
index 7f1469e107d..c2e621fa190 100644
--- a/app/controllers/projects/deploy_keys_controller.rb
+++ b/app/controllers/projects/deploy_keys_controller.rb
@@ -6,7 +6,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
before_action :authorize_admin_project!
before_action :authorize_update_deploy_key!, only: [:edit, :update]
- layout "project_settings"
+ layout 'project_settings'
def index
respond_to do |format|
@@ -66,7 +66,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
protected
def deploy_key
- @deploy_key ||= @project.deploy_keys.find(params[:id])
+ @deploy_key ||= DeployKey.find(params[:id])
end
def create_params
diff --git a/changelogs/unreleased/33878_fix_edit_deploy_key.yml b/changelogs/unreleased/33878_fix_edit_deploy_key.yml
new file mode 100644
index 00000000000..bc47d522240
--- /dev/null
+++ b/changelogs/unreleased/33878_fix_edit_deploy_key.yml
@@ -0,0 +1,4 @@
+---
+title: Fix edit button for deploy keys available from other projects
+merge_request: 12301
+author: Alexander Randa
diff --git a/db/fixtures/development/19_environments.rb b/db/fixtures/development/19_environments.rb
index 93214b9d3e7..c1bbc9af6d6 100644
--- a/db/fixtures/development/19_environments.rb
+++ b/db/fixtures/development/19_environments.rb
@@ -33,7 +33,7 @@ class Gitlab::Seeder::Environments
create_deployment!(
merge_request.source_project,
- "review/#{merge_request.source_branch}",
+ "review/#{merge_request.source_branch.gsub(/[^a-zA-Z0-9]/, '')}",
merge_request.source_branch,
merge_request.diff_head_sha
)
diff --git a/db/migrate/20170619144837_add_index_for_head_pipeline_merge_request.rb b/db/migrate/20170619144837_add_index_for_head_pipeline_merge_request.rb
new file mode 100644
index 00000000000..02863bee082
--- /dev/null
+++ b/db/migrate/20170619144837_add_index_for_head_pipeline_merge_request.rb
@@ -0,0 +1,15 @@
+class AddIndexForHeadPipelineMergeRequest < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :merge_requests, :head_pipeline_id
+ end
+
+ def down
+ remove_concurrent_index :merge_requests, :head_pipeline_id if index_exists?(:merge_requests, :head_pipeline_id)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ec1329892eb..028556bdccf 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -777,6 +777,7 @@ ActiveRecord::Schema.define(version: 20170621102400) do
add_index "merge_requests", ["created_at"], name: "index_merge_requests_on_created_at", using: :btree
add_index "merge_requests", ["deleted_at"], name: "index_merge_requests_on_deleted_at", using: :btree
add_index "merge_requests", ["description"], name: "index_merge_requests_on_description_trigram", using: :gin, opclasses: {"description"=>"gin_trgm_ops"}
+ add_index "merge_requests", ["head_pipeline_id"], name: "index_merge_requests_on_head_pipeline_id", using: :btree
add_index "merge_requests", ["milestone_id"], name: "index_merge_requests_on_milestone_id", using: :btree
add_index "merge_requests", ["source_branch"], name: "index_merge_requests_on_source_branch", using: :btree
add_index "merge_requests", ["source_project_id"], name: "index_merge_requests_on_source_project_id", using: :btree
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb
index 7cdee8aced7..d5c2f3d5094 100644
--- a/lib/api/deploy_keys.rb
+++ b/lib/api/deploy_keys.rb
@@ -86,7 +86,7 @@ module API
at_least_one_of :title, :can_push
end
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)
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index e4d2a992470..b706434217d 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -43,7 +43,7 @@ module Gitlab
end
def environment_name_regex_message
- "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.' and spaces"
+ "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces"
end
def kubernetes_namespace_regex
diff --git a/spec/features/projects/settings/repository_settings_spec.rb b/spec/features/projects/settings/repository_settings_spec.rb
index 2956ef73746..35cd0d6e832 100644
--- a/spec/features/projects/settings/repository_settings_spec.rb
+++ b/spec/features/projects/settings/repository_settings_spec.rb
@@ -65,6 +65,23 @@ feature 'Repository settings', feature: true do
expect(page).to have_content('Write access allowed')
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
project.deploy_keys << private_deploy_key
visit namespace_project_settings_repository_path(project.namespace, project)
diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb
index 0bee892fe0c..979f4fefcb6 100644
--- a/spec/lib/gitlab/regex_spec.rb
+++ b/spec/lib/gitlab/regex_spec.rb
@@ -21,6 +21,18 @@ describe Gitlab::Regex, lib: true do
end
describe '.environment_slug_regex' do
+ subject { described_class.environment_name_regex }
+
+ it { is_expected.to match('foo') }
+ it { is_expected.to match('foo-1') }
+ it { is_expected.to match('FOO') }
+ it { is_expected.to match('foo/1') }
+ it { is_expected.to match('foo.1') }
+ it { is_expected.not_to match('9&foo') }
+ it { is_expected.not_to match('foo-^') }
+ end
+
+ describe '.environment_slug_regex' do
subject { described_class.environment_slug_regex }
it { is_expected.to match('foo') }
diff --git a/spec/requests/api/deploy_keys_spec.rb b/spec/requests/api/deploy_keys_spec.rb
index 9c260f88f56..32439981b60 100644
--- a/spec/requests/api/deploy_keys_spec.rb
+++ b/spec/requests/api/deploy_keys_spec.rb
@@ -160,6 +160,16 @@ describe API::DeployKeys do
expect(json_response['title']).to eq('new title')
expect(json_response['can_push']).to eq(true)
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
describe 'DELETE /projects/:id/deploy_keys/:key_id' do