Preliminary (?) Interface for Deleting Uploaded Files.

The simplest thing which could possibly work ...
master
Jacques Distler 2008-12-30 03:03:02 -06:00
parent 1b8bf36702
commit 5700d4513f
6 changed files with 76 additions and 6 deletions

View File

@ -12,11 +12,7 @@ class FileController < ApplicationController
def file
@file_name = params['id']
if params['file']
unless (request.post? || ENV["RAILS_ENV"] == "test")
headers['Allow'] = 'POST'
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
return
end
return unless is_post
# form supplied
new_file = @web.wiki_files.create(params['file'])
if new_file.valid?
@ -38,6 +34,29 @@ class FileController < ApplicationController
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
return_to_last_remembered
@ -75,6 +94,15 @@ class FileController < ApplicationController
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)
logger.info "Importing pages from #{archive}"
zip = Zip::ZipInputStream.open(archive)

View 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 -%>

View File

@ -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/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/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/import/:id', :controller => 'file', :action => 'import'
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'

View File

@ -105,7 +105,7 @@ module WikiChunk
unless defined? WIKI_LINK
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)
WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0)
end

View File

@ -33,6 +33,8 @@ class AbstractUrlGenerator
file_link(mode, name, text, web.address, known_page, description)
when :pic
pic_link(mode, name, text, web.address, known_page)
when :delete
delete_link(mode, name, web.address, known_page)
else
raise "Unknown link type: #{link_type}"
end
@ -129,4 +131,14 @@ class UrlGenerator < AbstractUrlGenerator
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

View File

@ -88,6 +88,17 @@ background-color:#DDD;
background-color:#FFF;
}
.deleteWikiWord {
background-color:#FDD;
border: 2px solid red;
padding: 2px;
}
.deleteWikiWord:hover, .deleteWikiWord a:hover {
background-color:#FAA;
}
form#navigationSearchForm {
display:inline;
}