# Redmine - project management software# Copyright (C) 2006-2008 Jean-Philippe Lang## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.classAttachmentsController<ApplicationControllerbefore_filter:find_projectbefore_filter:read_authorize,:except=>:destroybefore_filter:delete_authorize,:only=>:destroyverify:method=>:post,:only=>:destroydefshowif@attachment.is_diff?@diff=File.new(@attachment.diskfile,"rb").readrender:action=>'diff'elsif@attachment.is_text?@content=File.new(@attachment.diskfile,"rb").readrender:action=>'file'elsedownloadendenddefdownloadif@attachment.container.is_a?(Version)||@attachment.container.is_a?(Project)@attachment.increment_downloadend# images are sent inlinesend_file@attachment.diskfile,:filename=>filename_for_content_disposition(@attachment.filename),:type=>@attachment.content_type,:disposition=>(@attachment.image??'inline':'attachment')enddefdestroy# Make sure association callbacks are called@attachment.container.attachments.delete(@attachment)redirect_to:backrescue::ActionController::RedirectBackErrorredirect_to:controller=>'projects',:action=>'show',:id=>@projectendprivatedeffind_project@attachment=Attachment.find(params[:id])# Show 404 if the filename in the url is wrongraiseActiveRecord::RecordNotFoundifparams[:filename]&¶ms[:filename]!=@attachment.filename@project=@attachment.projectrescueActiveRecord::RecordNotFoundrender_404enddefread_authorize@attachment.visible??true:deny_accessenddefdelete_authorize@attachment.deletable??true:deny_accessendend