Fix broken History button when viewing historical deleted file (#1759)
* Fix broken History button when viewing historical deleted file * Add tests
This commit is contained in:
+31
-18
@@ -440,23 +440,18 @@ module Precious
|
||||
mustache :page
|
||||
end
|
||||
|
||||
get %r{
|
||||
/history/ # match any URL beginning with /history/
|
||||
(.+?) # extract the full path (including any directories)
|
||||
/
|
||||
([0-9a-f]{40}) # match SHA
|
||||
}x do |path, version|
|
||||
wiki = wiki_new
|
||||
show_history wiki_page(path, wiki.commit_for(version), wiki)
|
||||
end
|
||||
|
||||
get '/history/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@name = wikip.fullname
|
||||
@page = wikip.page
|
||||
@page_num = [params[:page_num].to_i, 1].max
|
||||
@max_count = settings.wiki_options.fetch(:pagination_count, 10)
|
||||
unless @page.nil?
|
||||
@wiki = @page.wiki
|
||||
@versions = @page.versions(
|
||||
per_page: @max_count,
|
||||
page_num: @page_num,
|
||||
follow: settings.wiki_options.fetch(:follow_renames, true)
|
||||
)
|
||||
mustache :history
|
||||
else
|
||||
redirect to("/")
|
||||
end
|
||||
show_history wiki_page(params[:splat].first)
|
||||
end
|
||||
|
||||
get '/latest_changes' do
|
||||
@@ -603,6 +598,24 @@ module Precious
|
||||
|
||||
private
|
||||
|
||||
def show_history(wikip)
|
||||
@name = wikip.fullname
|
||||
@page = wikip.page
|
||||
@page_num = [params[:page_num].to_i, 1].max
|
||||
@max_count = settings.wiki_options.fetch(:pagination_count, 10)
|
||||
unless @page.nil?
|
||||
@wiki = @page.wiki
|
||||
@versions = @page.versions(
|
||||
per_page: @max_count,
|
||||
page_num: @page_num,
|
||||
follow: settings.wiki_options.fetch(:follow_renames, true)
|
||||
)
|
||||
mustache :history
|
||||
else
|
||||
redirect to("/")
|
||||
end
|
||||
end
|
||||
|
||||
def show_page_or_file(fullpath)
|
||||
wiki = wiki_new
|
||||
if page = wiki.page(fullpath)
|
||||
@@ -659,9 +672,9 @@ module Precious
|
||||
wiki.update_page(page, name, format, content.to_s, commit)
|
||||
end
|
||||
|
||||
def wiki_page(path, version = nil)
|
||||
def wiki_page(path, version = nil, wiki = nil)
|
||||
pathname = (Pathname.new('/') + path).cleanpath
|
||||
wiki = wiki_new
|
||||
wiki = wiki_new if wiki.nil?
|
||||
OpenStruct.new(:wiki => wiki, :page => wiki.page(pathname.to_s, version = version),
|
||||
:name => pathname.basename.sub_ext('').to_s, :path => pathname.dirname.to_s, :ext => pathname.extname, :fullname => pathname.basename.to_s, :fullpath => pathname.to_s)
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
{{#history}}
|
||||
<a
|
||||
class="btn BtnGroup-item btn-sm hide-sm hide-md"
|
||||
href="{{history_path}}/{{escaped_url_path}}"
|
||||
href="{{history_path}}/{{escaped_url_path}}/{{version}}"
|
||||
id="minibutton-history"
|
||||
>
|
||||
History
|
||||
|
||||
@@ -4,8 +4,8 @@ module Precious
|
||||
include HasPage
|
||||
include HasMath
|
||||
|
||||
attr_reader :content, :page, :header, :footer, :preview, :historical
|
||||
|
||||
attr_reader :content, :page, :header, :footer, :preview, :historical, :version
|
||||
|
||||
VALID_COUNTER_STYLES = ['decimal', 'decimal-leading-zero', 'arabic-indic', 'armenian', 'upper-armenian',
|
||||
'lower-armenian', 'bengali', 'cambodian', 'khmer', 'cjk-decimal', 'devanagari', 'georgian', 'gujarati', 'gurmukhi',
|
||||
'hebrew', 'kannada', 'lao', 'malayalam', 'mongolian', 'myanmar', 'oriya', 'persian', 'lower-roman', 'upper-roman',
|
||||
|
||||
Binary file not shown.
@@ -3,3 +3,5 @@
|
||||
f403b791119f8232b7cb0ba455c624ac6435f433 ed6c9f63b98acf73c25b5ffbb38da557d3682023 bootstraponline <cafe@bootstraponline.com> 1336421777 -0600 commit: Add header.
|
||||
ed6c9f63b98acf73c25b5ffbb38da557d3682023 084a558a1fb3cded23129e2dfad3a17d07d73fd3 Daniel Kimsey <dekimsey@ufl.edu> 1354899095 -0500 push
|
||||
084a558a1fb3cded23129e2dfad3a17d07d73fd3 02796b1450691f90db5d6dc6a816a4980ce80d07 Dawa Ometto <dawa.ometto@phil.uu.nl> 1538516954 +0200 push
|
||||
02796b1450691f90db5d6dc6a816a4980ce80d07 db8b297cf5a31b46ac24500edfdbd0d3d8eed4eb Nikita Ivanov <nikita.vyach.ivanov@gmail.com> 1640368693 +0500 commit: Created C (markdown)
|
||||
db8b297cf5a31b46ac24500edfdbd0d3d8eed4eb c736e410f98df7a1173a540364dbb8a18274273e Nikita Ivanov <nikita.vyach.ivanov@gmail.com> 1640368721 +0500 commit: Deleted C.md
|
||||
|
||||
@@ -3,3 +3,5 @@
|
||||
f403b791119f8232b7cb0ba455c624ac6435f433 ed6c9f63b98acf73c25b5ffbb38da557d3682023 bootstraponline <cafe@bootstraponline.com> 1336421777 -0600 commit: Add header.
|
||||
ed6c9f63b98acf73c25b5ffbb38da557d3682023 084a558a1fb3cded23129e2dfad3a17d07d73fd3 Daniel Kimsey <dekimsey@ufl.edu> 1354899095 -0500 push
|
||||
084a558a1fb3cded23129e2dfad3a17d07d73fd3 02796b1450691f90db5d6dc6a816a4980ce80d07 Dawa Ometto <dawa.ometto@phil.uu.nl> 1538516954 +0200 push
|
||||
02796b1450691f90db5d6dc6a816a4980ce80d07 db8b297cf5a31b46ac24500edfdbd0d3d8eed4eb Nikita Ivanov <nikita.vyach.ivanov@gmail.com> 1640368693 +0500 commit: Created C (markdown)
|
||||
db8b297cf5a31b46ac24500edfdbd0d3d8eed4eb c736e410f98df7a1173a540364dbb8a18274273e Nikita Ivanov <nikita.vyach.ivanov@gmail.com> 1640368721 +0500 commit: Deleted C.md
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
x¥ŽK
|
||||
Â0@]÷³Ê¤ù4A7n¼Ã$3±AÓJ‰ooñ
|
||||
.ß[<^œKÉ:‹»ºˆ€Öɸ€bY¥Á¡öI'Rh¢Ø8hSô¨4Só¢E¦
|
||||
|è†>&KZã(vÆ"
|
||||
'Œ¬Ù‹°‘ÐлŽó·üÈ•àºÒ4¯p˜~Ø®Šc›òt/”ŸmœË”3¨�ï;{ܲÍf·Ý*‡š‹<¥
|
||||
ù-üš…Q×
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
02796b1450691f90db5d6dc6a816a4980ce80d07
|
||||
c736e410f98df7a1173a540364dbb8a18274273e
|
||||
|
||||
+8
-1
@@ -171,7 +171,7 @@ EOF
|
||||
assert_equal 'sidebar', side_2.raw_data
|
||||
assert_equal 'def', side_2.version.message
|
||||
assert_not_equal side_1.version.sha, side_2.version.sha
|
||||
assert_equal commits+1, @wiki.repo.commits('master').size
|
||||
assert_equal commits, @wiki.repo.commits('master').size
|
||||
end
|
||||
|
||||
test "renames page" do
|
||||
@@ -668,6 +668,13 @@ EOF
|
||||
assert_equal last_response.status, 302
|
||||
end
|
||||
|
||||
test "view deleted page in history" do
|
||||
get 'C/db8b297cf5a31b46ac24500edfdbd0d3d8eed4eb'
|
||||
|
||||
assert last_response.ok?
|
||||
assert_match /This page will be deleted in the next commit :\(/, last_response.body
|
||||
end
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user