Mercurial > hg > soundsoftware-site
comparison app/controllers/attachments_controller.rb @ 1116:bb32da3bea34 redmine-2.2-integration
Merge from live
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 14:41:20 +0000 |
parents | 433d4f72a19b 19884e9d5eff |
children | 2f6e71e31b55 |
comparison
equal
deleted
inserted
replaced
1115:433d4f72a19b | 1116:bb32da3bea34 |
---|---|
18 class AttachmentsController < ApplicationController | 18 class AttachmentsController < ApplicationController |
19 before_filter :find_project, :except => :upload | 19 before_filter :find_project, :except => :upload |
20 before_filter :file_readable, :read_authorize, :only => [:show, :download, :thumbnail] | 20 before_filter :file_readable, :read_authorize, :only => [:show, :download, :thumbnail] |
21 before_filter :delete_authorize, :only => :destroy | 21 before_filter :delete_authorize, :only => :destroy |
22 before_filter :authorize_global, :only => :upload | 22 before_filter :authorize_global, :only => :upload |
23 before_filter :active_authorize, :only => :toggle_active | |
24 | |
25 include AttachmentsHelper | |
26 helper :attachments | |
23 | 27 |
24 accept_api_auth :show, :download, :upload | 28 accept_api_auth :show, :download, :upload |
25 | 29 |
26 def show | 30 def show |
27 respond_to do |format| | 31 respond_to do |format| |
46 format.api | 50 format.api |
47 end | 51 end |
48 end | 52 end |
49 | 53 |
50 def download | 54 def download |
51 if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project) | 55 # cc: formerly this happened only if "@attachment.container.is_a?(Version)" |
56 # or Project. Not good for us, we want to tally all downloads [by humans] | |
57 if not user_is_search_bot? | |
52 @attachment.increment_download | 58 @attachment.increment_download |
53 end | 59 end |
54 | 60 |
55 if stale?(:etag => @attachment.digest) | 61 if stale?(:etag => @attachment.digest) |
56 # images are sent inline | 62 # images are sent inline |
104 # Make sure association callbacks are called | 110 # Make sure association callbacks are called |
105 @attachment.container.attachments.delete(@attachment) | 111 @attachment.container.attachments.delete(@attachment) |
106 redirect_to_referer_or project_path(@project) | 112 redirect_to_referer_or project_path(@project) |
107 end | 113 end |
108 | 114 |
115 def toggle_active | |
116 @attachment.active = !@attachment.active? | |
117 @attachment.save! | |
118 render :layout => false | |
119 end | |
120 | |
109 private | 121 private |
110 def find_project | 122 def find_project |
111 @attachment = Attachment.find(params[:id]) | 123 @attachment = Attachment.find(params[:id]) |
112 # Show 404 if the filename in the url is wrong | 124 # Show 404 if the filename in the url is wrong |
113 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename | 125 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename |
127 | 139 |
128 def delete_authorize | 140 def delete_authorize |
129 @attachment.deletable? ? true : deny_access | 141 @attachment.deletable? ? true : deny_access |
130 end | 142 end |
131 | 143 |
144 def active_authorize | |
145 true | |
146 end | |
147 | |
132 def detect_content_type(attachment) | 148 def detect_content_type(attachment) |
133 content_type = attachment.content_type | 149 content_type = attachment.content_type |
134 if content_type.blank? | 150 if content_type.blank? |
135 content_type = Redmine::MimeType.of(attachment.filename) | 151 content_type = Redmine::MimeType.of(attachment.filename) |
136 end | 152 end |