diff options
-rw-r--r-- | config/routes/repository.rb | 2 | ||||
-rw-r--r-- | db/migrate/20190826100605_add_group_column_to_events.rb | 14 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | spec/routing/project_routing_spec.rb | 70 |
4 files changed, 80 insertions, 8 deletions
diff --git a/config/routes/repository.rb b/config/routes/repository.rb index b89e1c7f9af..093b86f3259 100644 --- a/config/routes/repository.rb +++ b/config/routes/repository.rb @@ -65,7 +65,7 @@ scope format: false do resources :protected_tags, only: [:index, :show, :create, :update, :destroy] end - scope constraints: { id: /.+/ } do + scope constraints: { id: /[^\0]+/ } do scope controller: :blob do get '/new/*id', action: :new, as: :new_blob post '/create/*id', action: :create, as: :create_blob diff --git a/db/migrate/20190826100605_add_group_column_to_events.rb b/db/migrate/20190826100605_add_group_column_to_events.rb index cd7b2b1d96a..dfc9d8cbdf1 100644 --- a/db/migrate/20190826100605_add_group_column_to_events.rb +++ b/db/migrate/20190826100605_add_group_column_to_events.rb @@ -1,9 +1,19 @@ # frozen_string_literal: true class AddGroupColumnToEvents < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + DOWNTIME = false - def change - add_reference :events, :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade } + disable_ddl_transaction! + + def up + add_column(:events, :group_id, :bigint) unless column_exists?(:events, :group_id) + add_concurrent_index(:events, :group_id) + add_concurrent_foreign_key(:events, :namespaces, column: :group_id, on_delete: :cascade) + end + + def down + remove_column(:events, :group_id) if column_exists?(:events, :group_id) end end diff --git a/db/schema.rb b/db/schema.rb index 6ddfb8bcb39..70f3a42e7f8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -3864,7 +3864,7 @@ ActiveRecord::Schema.define(version: 2019_09_05_223900) do add_foreign_key "epics", "users", column: "assignee_id", name: "fk_dccd3f98fc", on_delete: :nullify add_foreign_key "epics", "users", column: "author_id", name: "fk_3654b61b03", on_delete: :cascade add_foreign_key "epics", "users", column: "closed_by_id", name: "fk_aa5798e761", on_delete: :nullify - add_foreign_key "events", "namespaces", column: "group_id", on_delete: :cascade + add_foreign_key "events", "namespaces", column: "group_id", name: "fk_61fbf6ca48", on_delete: :cascade add_foreign_key "events", "projects", on_delete: :cascade add_foreign_key "events", "users", column: "author_id", name: "fk_edfd187b6f", on_delete: :cascade add_foreign_key "external_pull_requests", "projects", on_delete: :cascade diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 8a3de2a52fc..7e2d70d6eb5 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -530,15 +530,22 @@ describe 'project routing' do end end - # project_blame GET /:project_id/blame/:id(.:format) blame#show {id: /.+/, project_id: /[^\/]+/} + # project_blame GET /:project_id/blame/:id(.:format) blame#show {id: /[^\0]+/, project_id: /[^\/]+/} describe Projects::BlameController, 'routing' do it 'to #show' do expect(get('/gitlab/gitlabhq/blame/master/app/models/project.rb')).to route_to('projects/blame#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') expect(get('/gitlab/gitlabhq/blame/master/files.scss')).to route_to('projects/blame#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/files.scss') + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/blame/master/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/blame', action: 'show', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "master/#{newline_file}" }) end end - # project_blob GET /:project_id/blob/:id(.:format) blob#show {id: /.+/, project_id: /[^\/]+/} + # project_blob GET /:project_id/blob/:id(.:format) blob#show {id: /[^\0]+/, project_id: /[^\/]+/} describe Projects::BlobController, 'routing' do it 'to #show' do expect(get('/gitlab/gitlabhq/blob/master/app/models/project.rb')).to route_to('projects/blob#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') @@ -547,28 +554,56 @@ describe 'project routing' do expect(get('/gitlab/gitlabhq/blob/master/files.scss')).to route_to('projects/blob#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/files.scss') expect(get('/gitlab/gitlabhq/blob/master/blob/index.js')).to route_to('projects/blob#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/blob/index.js') expect(get('/gitlab/gitlabhq/blob/blob/master/blob/index.js')).to route_to('projects/blob#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'blob/master/blob/index.js') + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/blob/blob/master/blob/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/blob', action: 'show', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "blob/master/blob/#{newline_file}" }) end end - # project_tree GET /:project_id/tree/:id(.:format) tree#show {id: /.+/, project_id: /[^\/]+/} + # project_tree GET /:project_id/tree/:id(.:format) tree#show {id: /[^\0]+/, project_id: /[^\/]+/} describe Projects::TreeController, 'routing' do it 'to #show' do expect(get('/gitlab/gitlabhq/tree/master/app/models/project.rb')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb') expect(get('/gitlab/gitlabhq/tree/master/files.scss')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/files.scss') expect(get('/gitlab/gitlabhq/tree/master/tree/files')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/tree/files') expect(get('/gitlab/gitlabhq/tree/tree/master/tree/files')).to route_to('projects/tree#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'tree/master/tree/files') + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/tree/master/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/tree', action: 'show', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "master/#{newline_file}" }) end end - # project_find_file GET /:namespace_id/:project_id/find_file/*id(.:format) projects/find_file#show {:id=>/.+/, :namespace_id=>/[a-zA-Z.0-9_\-]+/, :project_id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/, :format=>/html/} + # project_find_file GET /:namespace_id/:project_id/find_file/*id(.:format) projects/find_file#show {:id=>/[^\0]+/, :namespace_id=>/[a-zA-Z.0-9_\-]+/, :project_id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/, :format=>/html/} # project_files GET /:namespace_id/:project_id/files/*id(.:format) projects/find_file#list {:id=>/(?:[^.]|\.(?!json$))+/, :namespace_id=>/[a-zA-Z.0-9_\-]+/, :project_id=>/[a-zA-Z.0-9_\-]+(?<!\.atom)/, :format=>/json/} describe Projects::FindFileController, 'routing' do it 'to #show' do expect(get('/gitlab/gitlabhq/find_file/master')).to route_to('projects/find_file#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master') + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/find_file/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/find_file', action: 'show', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "#{newline_file}" }) end it 'to #list' do expect(get('/gitlab/gitlabhq/files/master.json')).to route_to('projects/find_file#list', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master.json') + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/files/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/find_file', action: 'list', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "#{newline_file}" }) end end @@ -578,6 +613,13 @@ describe 'project routing' do route_to('projects/blob#edit', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb')) + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/edit/master/docs/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/blob', action: 'edit', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "master/docs/#{newline_file}" }) end it 'to #preview' do @@ -585,6 +627,26 @@ describe 'project routing' do route_to('projects/blob#preview', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb')) + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/edit/master/docs/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/blob', action: 'edit', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "master/docs/#{newline_file}" }) + end + end + + # project_raw GET /:project_id/raw/:id(.:format) raw#show {id: /[^\0]+/, project_id: /[^\/]+/} + describe Projects::RawController, 'routing' do + it 'to #show' do + newline_file = "new\n\nline.txt" + url_encoded_newline_file = ERB::Util.url_encode(newline_file) + assert_routing({ path: "/gitlab/gitlabhq/raw/master/#{url_encoded_newline_file}", + method: :get }, + { controller: 'projects/raw', action: 'show', + namespace_id: 'gitlab', project_id: 'gitlabhq', + id: "master/#{newline_file}" }) end end |