Commit 662cf2ce authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-wiki-page-history' into 'master'

Fix broken Wiki Page History

This MR fixes the broken Page History on the Wiki pages. It turns out `WikiHelper` did not allow users to view different versions due to its omitting of query string parameters, which was necessary to specify different `version_id` parameters. Instead of this hacky approach, use manually-specified wildcard routes that match the ID field properly for slashes.

Closes #2104

Closes #1751

Closes #1592

Closes https://github.com/gitlabhq/gitlabhq/issues/9399

See merge request !1232
parents b9df4998 fbb891c8
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.0.0 (unreleased) v 8.0.0 (unreleased)
- Omit filename in Content-Disposition header in raw file download to avoid RFC 6266 encoding issues (Stan HU) - Omit filename in Content-Disposition header in raw file download to avoid RFC 6266 encoding issues (Stan HU)
- Fix broken Wiki Page History (Stan Hu)
- Prevent anchors from being hidden by header (Stan Hu) - Prevent anchors from being hidden by header (Stan Hu)
- Fix bug where only the first 15 Bitbucket issues would be imported (Stan Hu) - Fix bug where only the first 15 Bitbucket issues would be imported (Stan Hu)
- Sort issues by creation date in Bitbucket importer (Stan Hu) - Sort issues by creation date in Bitbucket importer (Stan Hu)
......
...@@ -5,7 +5,6 @@ class Projects::WikisController < Projects::ApplicationController ...@@ -5,7 +5,6 @@ class Projects::WikisController < Projects::ApplicationController
before_action :authorize_create_wiki!, only: [:edit, :create, :history] before_action :authorize_create_wiki!, only: [:edit, :create, :history]
before_action :authorize_admin_wiki!, only: :destroy before_action :authorize_admin_wiki!, only: :destroy
before_action :load_project_wiki before_action :load_project_wiki
include WikiHelper
def pages def pages
@wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(PER_PAGE) @wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(PER_PAGE)
......
module WikiHelper
# Rails v4.1.9+ escapes all model IDs, converting slashes into %2F. The
# only way around this is to implement our own path generators.
def namespace_project_wiki_path(namespace, project, wiki_page, *args)
slug =
case wiki_page
when Symbol
wiki_page
when String
wiki_page
else
wiki_page.slug
end
namespace_project_path(namespace, project) + "/wikis/#{slug}"
end
def edit_namespace_project_wiki_path(namespace, project, wiki_page, *args)
namespace_project_wiki_path(namespace, project, wiki_page) + '/edit'
end
def history_namespace_project_wiki_path(namespace, project, wiki_page, *args)
namespace_project_wiki_path(namespace, project, wiki_page) + '/history'
end
end
%span.pull-right %span.pull-right
- if (@page && @page.persisted?) - if (@page && @page.persisted?)
= link_to history_namespace_project_wiki_path(@project.namespace, @project, @page), class: "btn btn-grouped" do = link_to namespace_project_wiki_history_path(@project.namespace, @project, @page), class: "btn btn-grouped" do
Page History Page History
- if can?(current_user, :create_wiki, @project) - if can?(current_user, :create_wiki, @project)
= link_to edit_namespace_project_wiki_path(@project.namespace, @project, @page), class: "btn btn-grouped" do = link_to namespace_project_wiki_edit_path(@project.namespace, @project, @page), class: "btn btn-grouped" do
%i.fa.fa-pencil-square-o %i.fa.fa-pencil-square-o
Edit Edit
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
= link_to 'Home', namespace_project_wiki_path(@project.namespace, @project, :home) = link_to 'Home', namespace_project_wiki_path(@project.namespace, @project, :home)
= nav_link(path: 'wikis#pages') do = nav_link(path: 'wikis#pages') do
= link_to 'Pages', pages_namespace_project_wikis_path(@project.namespace, @project) = link_to 'Pages', namespace_project_wiki_pages_path(@project.namespace, @project)
= nav_link(path: 'wikis#git_access') do = nav_link(path: 'wikis#git_access') do
= link_to git_access_namespace_project_wikis_path(@project.namespace, @project) do = link_to namespace_project_wikis_git_access_path(@project.namespace, @project) do
%i.fa.fa-download %i.fa.fa-download
Git Access Git Access
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- if @page.historical? - if @page.historical?
.warning_message .warning_message
This is an old version of this page. This is an old version of this page.
You can view the #{link_to "most recent version", namespace_project_wiki_path(@project.namespace, @project, @page)} or browse the #{link_to "history", history_namespace_project_wiki_path(@project.namespace, @project, @page)}. You can view the #{link_to "most recent version", namespace_project_wiki_path(@project.namespace, @project, @page)} or browse the #{link_to "history", namespace_project_wiki_history_path(@project.namespace, @project, @page)}.
%hr %hr
......
...@@ -406,16 +406,20 @@ Gitlab::Application.routes.draw do ...@@ -406,16 +406,20 @@ Gitlab::Application.routes.draw do
end end
end end
resources :wikis, only: [:show, :edit, :destroy, :create], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ } do WIKI_SLUG_ID = { id: /[a-zA-Z.0-9_\-\/]+/ } unless defined? WIKI_SLUG_ID
collection do
get :pages
put ':id' => 'wikis#update'
get :git_access
end
member do scope do
get 'history' # Order matters to give priority to these matches
end get '/wikis/git_access', to: 'wikis#git_access'
get '/wikis/pages', to: 'wikis#pages', as: 'wiki_pages'
post '/wikis', to: 'wikis#create'
get '/wikis/*id/history', to: 'wikis#history', as: 'wiki_history', constraints: WIKI_SLUG_ID
get '/wikis/*id/edit', to: 'wikis#edit', as: 'wiki_edit', constraints: WIKI_SLUG_ID
get '/wikis/*id', to: 'wikis#show', as: 'wiki', constraints: WIKI_SLUG_ID
delete '/wikis/*id', to: 'wikis#destroy', constraints: WIKI_SLUG_ID
put '/wikis/*id', to: 'wikis#update', constraints: WIKI_SLUG_ID
end end
resource :repository, only: [:show, :create] do resource :repository, only: [:show, :create] do
......
...@@ -91,3 +91,15 @@ Feature: Project Wiki ...@@ -91,3 +91,15 @@ Feature: Project Wiki
And I view the page history of a Wiki page that has a path And I view the page history of a Wiki page that has a path
Then I should see a non-escaped path Then I should see a non-escaped path
And I should see the page history And I should see the page history
@javascript
Scenario: View an old page version of a Wiki page
Given I create a New page with paths
And I click on the "Pages" button
And I edit the Wiki page with a path
Then I should see a non-escaped path
And I should see the Editing page
And I change the content
Then I click on Page History
And I should see the page history
And I should see a link with a version ID
...@@ -3,7 +3,6 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps ...@@ -3,7 +3,6 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
include SharedProject include SharedProject
include SharedNote include SharedNote
include SharedPaths include SharedPaths
include WikiHelper
step 'I click on the Cancel button' do step 'I click on the Cancel button' do
page.within(:css, ".form-actions") do page.within(:css, ".form-actions") do
...@@ -165,6 +164,10 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps ...@@ -165,6 +164,10 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
click_on 'Page History' click_on 'Page History'
end end
step 'I click on Page History' do
click_on 'Page History'
end
step 'I should see the page history' do step 'I should see the page history' do
expect(page).to have_content('History for') expect(page).to have_content('History for')
end end
...@@ -174,6 +177,10 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps ...@@ -174,6 +177,10 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
click_button "Search" click_button "Search"
end end
step 'I should see a link with a version ID' do
find('a[href*="?version_id"]')
end
def wiki def wiki
@project_wiki = ProjectWiki.new(project, current_user) @project_wiki = ProjectWiki.new(project, current_user)
end end
......
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