Preliminary (?) Interface for Deleting Uploaded Files.
The simplest thing which could possibly work ...
This commit is contained in:
parent
1b8bf36702
commit
5700d4513f
6 changed files with 76 additions and 6 deletions
|
@ -12,11 +12,7 @@ class FileController < ApplicationController
|
||||||
def file
|
def file
|
||||||
@file_name = params['id']
|
@file_name = params['id']
|
||||||
if params['file']
|
if params['file']
|
||||||
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
return unless is_post
|
||||||
headers['Allow'] = 'POST'
|
|
||||||
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
# form supplied
|
# form supplied
|
||||||
new_file = @web.wiki_files.create(params['file'])
|
new_file = @web.wiki_files.create(params['file'])
|
||||||
if new_file.valid?
|
if new_file.valid?
|
||||||
|
@ -38,6 +34,29 @@ class FileController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete
|
||||||
|
@file_name = params['id']
|
||||||
|
file = WikiFile.find_by_file_name(@file_name)
|
||||||
|
unless file
|
||||||
|
flash[:error] = "File '#{@file_name}' not found."
|
||||||
|
redirect_to_page(@page_name)
|
||||||
|
end
|
||||||
|
system_password = params['system_password']
|
||||||
|
if system_password
|
||||||
|
return unless is_post
|
||||||
|
# form supplied
|
||||||
|
if wiki.authenticate(system_password)
|
||||||
|
file.destroy
|
||||||
|
flash[:info] = "File '#{@file_name}' deleted."
|
||||||
|
else
|
||||||
|
flash[:error] = "System Password incorrect."
|
||||||
|
end
|
||||||
|
redirect_to_page(@page_name)
|
||||||
|
else
|
||||||
|
# no system password supplied, display the form
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def cancel_upload
|
def cancel_upload
|
||||||
return_to_last_remembered
|
return_to_last_remembered
|
||||||
|
@ -75,6 +94,15 @@ class FileController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def is_post
|
||||||
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
||||||
|
headers['Allow'] = 'POST'
|
||||||
|
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
def import_from_archive(archive)
|
def import_from_archive(archive)
|
||||||
logger.info "Importing pages from #{archive}"
|
logger.info "Importing pages from #{archive}"
|
||||||
zip = Zip::ZipInputStream.open(archive)
|
zip = Zip::ZipInputStream.open(archive)
|
||||||
|
|
18
app/views/file/delete.html.erb
Normal file
18
app/views/file/delete.html.erb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<%-
|
||||||
|
@title = "Delete #{@file_name}"
|
||||||
|
@hide_navigation = true
|
||||||
|
-%>
|
||||||
|
|
||||||
|
<%= error_messages_for 'delete' %>
|
||||||
|
|
||||||
|
<% form_tag({ :controller => 'file', :web => @web_name, :action => 'delete' },
|
||||||
|
{'accept-charset' => 'utf-8' }) do %>
|
||||||
|
<div class="inputFieldWithPrompt">
|
||||||
|
<%= hidden_field 'file', 'file_name' %>
|
||||||
|
<label for="system_password">Enter system password</label>
|
||||||
|
<input type="password" class="disableAutoComplete" id="system_password"
|
||||||
|
name="system_password" />
|
||||||
|
<input type="submit" value="Delete" /><br/>
|
||||||
|
or go <%= link_to "back", :back %> to the page you came from.
|
||||||
|
</div>
|
||||||
|
<%- end -%>
|
|
@ -17,6 +17,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
connect_to_web map, ':web/edit_web', :controller => 'admin', :action => 'edit_web'
|
connect_to_web map, ':web/edit_web', :controller => 'admin', :action => 'edit_web'
|
||||||
connect_to_web map, ':web/remove_orphaned_pages', :controller => 'admin', :action => 'remove_orphaned_pages'
|
connect_to_web map, ':web/remove_orphaned_pages', :controller => 'admin', :action => 'remove_orphaned_pages'
|
||||||
connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category'
|
connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category'
|
||||||
|
connect_to_web map, ':web/file/delete/:id', :controller => 'file', :action => 'delete', :requirements => {:id => /[-._\w]+/}, :id => nil
|
||||||
connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil
|
connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil
|
||||||
connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import'
|
connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import'
|
||||||
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'
|
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'
|
||||||
|
|
|
@ -105,7 +105,7 @@ module WikiChunk
|
||||||
|
|
||||||
unless defined? WIKI_LINK
|
unless defined? WIKI_LINK
|
||||||
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/
|
WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/
|
||||||
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic))$', 0)
|
LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(delete))$', 0)
|
||||||
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0)
|
ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0)
|
||||||
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0)
|
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0)
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,8 @@ class AbstractUrlGenerator
|
||||||
file_link(mode, name, text, web.address, known_page, description)
|
file_link(mode, name, text, web.address, known_page, description)
|
||||||
when :pic
|
when :pic
|
||||||
pic_link(mode, name, text, web.address, known_page)
|
pic_link(mode, name, text, web.address, known_page)
|
||||||
|
when :delete
|
||||||
|
delete_link(mode, name, web.address, known_page)
|
||||||
else
|
else
|
||||||
raise "Unknown link type: #{link_type}"
|
raise "Unknown link type: #{link_type}"
|
||||||
end
|
end
|
||||||
|
@ -129,4 +131,14 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_link(mode, name, web_address, known_file)
|
||||||
|
href = @controller.url_for :controller => 'file', :web => web_address,
|
||||||
|
:action => 'delete', :id => name
|
||||||
|
if mode == :show and known_file
|
||||||
|
%{<span class="deleteWikiWord"><a href="#{href}">Delete #{name}</a></span>}
|
||||||
|
else
|
||||||
|
%{<span class="deleteWikiWord">[[#{name}:delete]]</span>}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,6 +88,17 @@ background-color:#DDD;
|
||||||
background-color:#FFF;
|
background-color:#FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.deleteWikiWord {
|
||||||
|
background-color:#FDD;
|
||||||
|
border: 2px solid red;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.deleteWikiWord:hover, .deleteWikiWord a:hover {
|
||||||
|
background-color:#FAA;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
form#navigationSearchForm {
|
form#navigationSearchForm {
|
||||||
display:inline;
|
display:inline;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue