comparison app/controllers/attachments_controller.rb @ 257:3ecf99348b9f feature_80

* Enable toggling file active state through the files interface
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 04 Mar 2011 12:46:26 +0000
parents 513646585e45
children 350acce374a2
comparison
equal deleted inserted replaced
256:e0dc03c8d745 257:3ecf99348b9f
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 class AttachmentsController < ApplicationController 18 class AttachmentsController < ApplicationController
19
19 before_filter :find_project 20 before_filter :find_project
20 before_filter :file_readable, :read_authorize, :except => :destroy 21 before_filter :file_readable, :read_authorize, :except => :destroy
21 before_filter :delete_authorize, :only => :destroy 22 before_filter :delete_authorize, :only => :destroy
23 before_filter :active_authorize, :only => :toggle_active
22 24
23 verify :method => :post, :only => :destroy 25 verify :method => :post, :only => :destroy
24 26
25 def show 27 def show
26 if @attachment.is_diff? 28 if @attachment.is_diff?
52 redirect_to :back 54 redirect_to :back
53 rescue ::ActionController::RedirectBackError 55 rescue ::ActionController::RedirectBackError
54 redirect_to :controller => 'projects', :action => 'show', :id => @project 56 redirect_to :controller => 'projects', :action => 'show', :id => @project
55 end 57 end
56 58
59 def toggle_active
60 @attachment.active = !@attachment.active?
61 @attachment.save!
62 render :layout => false
63 end
64
57 private 65 private
58 def find_project 66 def find_project
59 @attachment = Attachment.find(params[:id]) 67 @attachment = Attachment.find(params[:id])
60 # Show 404 if the filename in the url is wrong 68 # Show 404 if the filename in the url is wrong
61 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename 69 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
75 83
76 def delete_authorize 84 def delete_authorize
77 @attachment.deletable? ? true : deny_access 85 @attachment.deletable? ? true : deny_access
78 end 86 end
79 87
88 def active_authorize
89 true
90 end
91
80 def detect_content_type(attachment) 92 def detect_content_type(attachment)
81 content_type = attachment.content_type 93 content_type = attachment.content_type
82 if content_type.blank? 94 if content_type.blank?
83 content_type = Redmine::MimeType.of(attachment.filename) 95 content_type = Redmine::MimeType.of(attachment.filename)
84 end 96 end