def accept_key_auth_actions
self.class.read_inheritable_attribute('accept_key_auth_actions') || []
end
+
+ # TODO: move to model
+ def attach_files(obj, files)
+ attachments = []
+ if files && files.is_a?(Array)
+ files.each do |file|
+ next unless file.size > 0
+ a = Attachment.create(:container => obj, :file => file, :author => User.current)
+ attachments << a unless a.new_record?
+ end
+ end
+ attachments
+ end
# qvalues http header parser
# code taken from webrick
end
def add_attachment
- # Save the attachments
- @attachments = []
- params[:attachments].each { |file|
- next unless file.size > 0
- a = Attachment.create(:container => @document, :file => file, :author => User.current)
- @attachments << a unless a.new_record?
- } if params[:attachments] and params[:attachments].is_a? Array
- Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added')
+ attachments = attach_files(@document, params[:attachments])
+ Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
redirect_to :action => 'show', :id => @document
end
def add_note
journal = @issue.init_journal(User.current, params[:notes])
- params[:attachments].each { |file|
- next unless file.size > 0
- a = Attachment.create(:container => @issue, :file => file, :author => User.current)
- journal.details << JournalDetail.new(:property => 'attachment',
- :prop_key => a.id,
- :value => a.filename) unless a.new_record?
- } if params[:attachments] and params[:attachments].is_a? Array
+ attachments = attach_files(@issue, params[:attachments])
+ attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
if journal.save
flash[:notice] = l(:notice_successful_update)
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
journal = @issue.init_journal(User.current, params[:notes])
@issue.status = @new_status
if @issue.update_attributes(params[:issue])
- # Save attachments
- params[:attachments].each { |file|
- next unless file.size > 0
- a = Attachment.create(:container => @issue, :file => file, :author => User.current)
- journal.details << JournalDetail.new(:property => 'attachment',
- :prop_key => a.id,
- :value => a.filename) unless a.new_record?
- } if params[:attachments] and params[:attachments].is_a? Array
-
+ attachments = attach_files(@issue, params[:attachments])
+ attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
# Log time
if current_role.allowed_to?(:log_time)
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
@message.sticky = params[:message]['sticky']
end
if request.post? && @message.save
- params[:attachments].each { |file|
- Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0
- } if params[:attachments] and params[:attachments].is_a? Array
+ attach_files(@message, params[:attachments])
redirect_to :action => 'show', :id => @message
end
end
@reply.board = @board
@topic.children << @reply
if !@reply.new_record?
- params[:attachments].each { |file|
- Attachment.create(:container => @reply, :file => file, :author => User.current) if file.size > 0
- } if params[:attachments] and params[:attachments].is_a? Array
+ attach_files(@reply, params[:attachments])
end
redirect_to :action => 'show', :id => @topic
end
@message.sticky = params[:message]['sticky']
end
if request.post? && @message.update_attributes(params[:message])
- params[:attachments].each { |file|
- Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0
- } if params[:attachments] and params[:attachments].is_a? Array
+ attach_files(@message, params[:attachments])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @topic
end
def add_document
@document = @project.documents.build(params[:document])
if request.post? and @document.save
- # Save the attachments
- params[:attachments].each { |a|
- Attachment.create(:container => @document, :file => a, :author => User.current) unless a.size == 0
- } if params[:attachments] and params[:attachments].is_a? Array
+ attach_files(@document, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
redirect_to :action => 'list_documents', :id => @project
@custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
@issue.custom_values = @custom_values
if @issue.save
- if params[:attachments] && params[:attachments].is_a?(Array)
- # Save attachments
- params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
- end
+ attach_files(@issue, params[:attachments])
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
def add_file
if request.post?
@version = @project.versions.find_by_id(params[:version_id])
- # Save the attachments
- @attachments = []
- params[:attachments].each { |file|
- next unless file.size > 0
- a = Attachment.create(:container => @version, :file => file, :author => User.current)
- @attachments << a unless a.new_record?
- } if params[:attachments] and params[:attachments].is_a? Array
- Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
+ attachments = attach_files(@issue, params[:attachments])
+ Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
@versions = @project.versions.sort
def add_attachment
@page = @wiki.find_page(params[:page])
- # Save the attachments
- params[:attachments].each { |file|
- next unless file.size > 0
- a = Attachment.create(:container => @page, :file => file, :author => User.current)
- } if params[:attachments] and params[:attachments].is_a? Array
+ attach_files(@page, params[:attachments])
redirect_to :action => 'index', :page => @page.title
end