diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 09b7678..a565c01 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -47,7 +47,8 @@ class DocumentsController < ApplicationController end def new - @document = @project.documents.build(params[:document]) + @document = @project.documents.build + @document.safe_attributes = params[:document] if request.post? and @document.save attachments = Attachment.attach_files(@document, params[:attachments]) render_attachment_warning_if_needed(@document) @@ -58,7 +59,8 @@ class DocumentsController < ApplicationController def edit @categories = DocumentCategory.active #TODO: use it in the views - if request.post? and @document.update_attributes(params[:document]) + @document.safe_attributes = params[:document] + if request.post? and @document.save flash[:notice] = l(:notice_successful_update) redirect_to :action => 'show', :id => @document end diff --git a/app/models/document.rb b/app/models/document.rb index f8ea92a..f18f19b 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Document < ActiveRecord::Base + include Redmine::SafeAttributes belongs_to :project belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" acts_as_attachable :delete_permission => :manage_documents @@ -32,6 +33,8 @@ class Document < ActiveRecord::Base named_scope :visible, lambda {|*args| { :include => :project, :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } } + safe_attributes 'category_id', 'title', 'description' + def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_documents, project) end