Unify deletion routes. Closes #1332.
This commit is contained in:
+16
-25
@@ -153,7 +153,7 @@ module Precious
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do
|
||||
post %r{/(delete|rename|edit|create)/custom\.(js|css)} do
|
||||
forbid('Changing this resource is not allowed.')
|
||||
end
|
||||
|
||||
@@ -229,18 +229,6 @@ module Precious
|
||||
end
|
||||
end
|
||||
|
||||
post '/deleteFile/*' do
|
||||
forbid unless @allow_editing
|
||||
wiki = wiki_new
|
||||
filepath = params[:splat].first
|
||||
unless filepath.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Deleted #{filepath}"
|
||||
wiki.delete_file(filepath, commit)
|
||||
end
|
||||
|
||||
redirect_to('/pages')
|
||||
end
|
||||
|
||||
post '/rename/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@@ -296,20 +284,23 @@ module Precious
|
||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||
end
|
||||
|
||||
get '/delete/*' do
|
||||
forbid unless @allow_editing
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
name = join_page_name(wikip.name, wikip.ext)
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
unless page.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Destroyed #{name} (#{page.format})"
|
||||
wiki.delete_page(page, commit)
|
||||
end
|
||||
|
||||
redirect to('/')
|
||||
post '/delete/*' do
|
||||
$stderr.puts "[DELETE] DELETE WAS CALLED"
|
||||
forbid unless @allow_editing
|
||||
wiki = wiki_new
|
||||
filepath = params[:splat].first
|
||||
$stderr.puts "[DELETE] for file #{filepath}"
|
||||
unless filepath.nil?
|
||||
commit = commit_message
|
||||
commit[:message] = "Deleted #{filepath}"
|
||||
$stderr.puts "[DELETE] About to call wiki.delete_file"
|
||||
wiki.delete_file(filepath, commit)
|
||||
end
|
||||
$stderr.puts "[DELETE] dunzo"
|
||||
redirect_to('/pages')
|
||||
end
|
||||
|
||||
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
|
||||
@@ -47,8 +47,12 @@ $(document).ready(function() {
|
||||
$('#delete-link').click( function(e) {
|
||||
var ok = confirm($(this).data('confirm'));
|
||||
if ( ok ) {
|
||||
var loc = '<%= delete_path %>/' + pageFullPath;
|
||||
window.location = loc;
|
||||
$.post('<%=delete_path %>/' + pageFullPath,
|
||||
{},
|
||||
function (result) {
|
||||
// page successfully deleted, return to landing page
|
||||
window.location = '/';
|
||||
});
|
||||
}
|
||||
// Don't navigate on cancel.
|
||||
e.preventDefault();
|
||||
|
||||
@@ -10,7 +10,6 @@ module Precious
|
||||
upload_file: 'uploadFile',
|
||||
create: 'create',
|
||||
delete: 'delete',
|
||||
delete_file: 'deleteFile',
|
||||
edit: 'edit',
|
||||
pages: 'pages',
|
||||
history: 'history',
|
||||
|
||||
@@ -31,7 +31,7 @@ module Precious
|
||||
|
||||
|
||||
def delete_file(url)
|
||||
%Q(<form method="POST" action="#{delete_file_path}#{url}" onsubmit="return confirm('Do you really want to delete the file #{URI.decode(url)}?');"><button type="submit" name="delete" value="true">Delete</button></form>)
|
||||
%Q(<form method="POST" action="#{delete_path}#{url}" onsubmit="return confirm('Do you really want to delete the file #{URI.decode(url)}?');"><button type="submit" name="delete" value="true">Delete</button></form>)
|
||||
end
|
||||
|
||||
def files_folders
|
||||
|
||||
+3
-3
@@ -298,7 +298,7 @@ context "Frontend" do
|
||||
@wiki.clear_cache
|
||||
get "/gollum/create/TT"
|
||||
assert last_response.ok?
|
||||
get '/gollum/delete/_Template'
|
||||
post '/gollum/delete/_Template'
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
@@ -379,7 +379,7 @@ context "Frontend" do
|
||||
page = @wiki.page(name)
|
||||
assert_equal 'abc', page.raw_data
|
||||
|
||||
get '/gollum/delete/' + name
|
||||
post "/gollum/delete/#{page.filename}"
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
@@ -515,7 +515,7 @@ context "Frontend" do
|
||||
end
|
||||
end
|
||||
|
||||
['deleteFile', 'rename', 'edit', 'create'].each do |route|
|
||||
['delete', 'rename', 'edit', 'create'].each do |route|
|
||||
['.css', '.js'].each do |ext|
|
||||
post "/gollum/#{route}/custom#{ext}"
|
||||
assert_equal 403, last_response.status, "post /gollum/#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||
|
||||
Reference in New Issue
Block a user