Merge pull request #1336 from gollum/unify_deletion_routes

Unify deletion routes. Implement ajax deletion for /pages. Closes #1332.
This commit is contained in:
Bart Kamphorst
2018-10-19 21:41:33 +02:00
committed by GitHub
5 changed files with 38 additions and 32 deletions
+11 -25
View File
@@ -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,18 @@ 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
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
end
get '/create/*' do
forbid unless @allow_editing
@@ -44,15 +44,36 @@ function abspath(path, name){
// ua
$(document).ready(function() {
// for deleting the current page
$('#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();
} );
// for deleting files and pages from the overview
$('.delete-file').click( function(e) {
var ok = confirm($(this).data('confirm'));
if ( ok ) {
var element = $(this);
$.post('<%=delete_path %>' + $(this).data('file-path'),
{},
function (result) {
// file successfully deleted, stay on overview but remove element from DOM
element.closest("li").remove();
});
}
// Don't navigate on cancel.
e.preventDefault();
} );
var nodeSelector = {
node1: null,
-1
View File
@@ -10,7 +10,6 @@ module Precious
upload_file: 'uploadFile',
create: 'create',
delete: 'delete',
delete_file: 'deleteFile',
edit: 'edit',
pages: 'pages',
history: 'history',
+1 -1
View File
@@ -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(<div class="delete-file" data-file-path="#{url}" data-confirm="Are you sure you want to delete #{URI.decode(url)}?"><span><button type="submit" name="delete">Delete</button></span></div>)
end
def files_folders
+3 -3
View File
@@ -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}"