comparison app/controllers/attachments_controller.rb @ 599:251b380117ce feature_227

Introduce a new latest_downloads plugin to manage active and shortcut for attachments. Add a table for attachment active/shortcut data. Move existing active-handler code into the new plugin (but still using the "old" active column in the attachments table). Note the files_controller stuff doesn't actually work here.
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 16 Aug 2011 17:01:19 +0100
parents 350acce374a2
children
comparison
equal deleted inserted replaced
590:3ebf9b76e57f 599:251b380117ce
18 class AttachmentsController < ApplicationController 18 class AttachmentsController < ApplicationController
19 19
20 before_filter :find_project 20 before_filter :find_project
21 before_filter :file_readable, :read_authorize, :except => :destroy 21 before_filter :file_readable, :read_authorize, :except => :destroy
22 before_filter :delete_authorize, :only => :destroy 22 before_filter :delete_authorize, :only => :destroy
23 before_filter :active_authorize, :only => :toggle_active
24 23
25 verify :method => :post, :only => :destroy 24 verify :method => :post, :only => :destroy
26 25
27 def show 26 def show
28 if @attachment.is_diff? 27 if @attachment.is_diff?
54 redirect_to :back 53 redirect_to :back
55 rescue ::ActionController::RedirectBackError 54 rescue ::ActionController::RedirectBackError
56 redirect_to :controller => 'projects', :action => 'show', :id => @project 55 redirect_to :controller => 'projects', :action => 'show', :id => @project
57 end 56 end
58 57
59 def toggle_active
60 @attachment.active = !@attachment.active?
61 @attachment.save!
62 render :layout => false
63 end
64
65 private 58 private
66 def find_project 59 def find_project
67 @attachment = Attachment.find(params[:id]) 60 @attachment = Attachment.find(params[:id])
68 # Show 404 if the filename in the url is wrong 61 # Show 404 if the filename in the url is wrong
69 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename 62 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
83 76
84 def delete_authorize 77 def delete_authorize
85 @attachment.deletable? ? true : deny_access 78 @attachment.deletable? ? true : deny_access
86 end 79 end
87 80
88 def active_authorize
89 true
90 end
91
92 def detect_content_type(attachment) 81 def detect_content_type(attachment)
93 content_type = attachment.content_type 82 content_type = attachment.content_type
94 if content_type.blank? 83 if content_type.blank?
95 content_type = Redmine::MimeType.of(attachment.filename) 84 content_type = Redmine::MimeType.of(attachment.filename)
96 end 85 end