diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-12-09 16:54:46 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-12-09 16:54:46 +0000 |
commit | 5d2899ee1b3e00d0cf43521182b1244dfc3cfe9f (patch) | |
tree | eb64711c0150fafb698da9d92eb0d6735a5461cf /app/controllers | |
parent | 2b6e332318a3e0a9489d20280010bb2d00206d95 (diff) | |
download | redmine-5d2899ee1b3e00d0cf43521182b1244dfc3cfe9f.tar.gz redmine-5d2899ee1b3e00d0cf43521182b1244dfc3cfe9f.zip |
AttachmentsController now handles attachments deletion.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2116 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/attachments_controller.rb | 33 | ||||
-rw-r--r-- | app/controllers/documents_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/issues_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/versions_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/wiki_controller.rb | 9 |
5 files changed, 27 insertions, 39 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 788bab94d..2851f91a6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# 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 @@ -17,7 +17,11 @@ class AttachmentsController < ApplicationController before_filter :find_project - + before_filter :read_authorize, :except => :destroy + before_filter :delete_authorize, :only => :destroy + + verify :method => :post, :only => :destroy + def show if @attachment.is_diff? @diff = File.new(@attachment.diskfile, "rb").read @@ -37,19 +41,32 @@ class AttachmentsController < ApplicationController send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), :type => @attachment.content_type, :disposition => (@attachment.image? ? 'inline' : 'attachment') + end - + + def destroy + # Make sure association callbacks are called + @attachment.container.attachments.delete(@attachment) + redirect_to :back + rescue ::ActionController::RedirectBackError + redirect_to :controller => 'projects', :action => 'show', :id => @project + end + private def find_project @attachment = Attachment.find(params[:id]) # Show 404 if the filename in the url is wrong raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename - @project = @attachment.project - permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym - allowed = User.current.allowed_to?(permission, @project) - allowed ? true : (User.current.logged? ? render_403 : require_login) rescue ActiveRecord::RecordNotFound render_404 end + + def read_authorize + @attachment.visible? ? true : deny_access + end + + def delete_authorize + @attachment.deletable? ? true : deny_access + end end diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index dbf9cd8e5..c6c93f9df 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -70,11 +70,6 @@ class DocumentsController < ApplicationController Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added') redirect_to :action => 'show', :id => @document end - - def destroy_attachment - @document.attachments.find(params[:attachment_id]).destroy - redirect_to :action => 'show', :id => @document - end private def find_project diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 916229cbc..b5009ce3f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -18,7 +18,7 @@ class IssuesController < ApplicationController menu_item :new_issue, :only => :new - before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment] + before_filter :find_issue, :only => [:show, :edit, :reply] before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] before_filter :find_project, :only => [:new, :update_form, :preview] before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu] @@ -313,17 +313,6 @@ class IssuesController < ApplicationController @issues.each(&:destroy) redirect_to :action => 'index', :project_id => @project end - - def destroy_attachment - a = @issue.attachments.find(params[:attachment_id]) - a.destroy - journal = @issue.init_journal(User.current) - journal.details << JournalDetail.new(:property => 'attachment', - :prop_key => a.id, - :old_value => a.filename) - journal.save - redirect_to :action => 'show', :id => @issue - end def gantt @gantt = Redmine::Helpers::Gantt.new(params) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 3a2221761..c269432f3 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -37,12 +37,6 @@ class VersionsController < ApplicationController redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project end - def destroy_file - @version.attachments.find(params[:attachment_id]).destroy - flash[:notice] = l(:notice_successful_delete) - redirect_to :controller => 'projects', :action => 'list_files', :id => @project - end - def status_by respond_to do |format| format.html { render :action => 'show' } diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 04bc33a82..221f4aa81 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -20,7 +20,7 @@ require 'diff' class WikiController < ApplicationController before_filter :find_wiki, :authorize - verify :method => :post, :only => [:destroy, :destroy_attachment, :protect], :redirect_to => { :action => :index } + verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index } helper :attachments include AttachmentsHelper @@ -187,13 +187,6 @@ class WikiController < ApplicationController redirect_to :action => 'index', :page => @page.title end - def destroy_attachment - @page = @wiki.find_page(params[:page]) - return render_403 unless editable? - @page.attachments.find(params[:attachment_id]).destroy - redirect_to :action => 'index', :page => @page.title - end - private def find_wiki |