@@ -144,6 +144,19 class ApplicationController < ActionController::Base | |||||
144 | def accept_key_auth_actions |
|
144 | def accept_key_auth_actions | |
145 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] |
|
145 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] | |
146 | end |
|
146 | end | |
|
147 | ||||
|
148 | # TODO: move to model | |||
|
149 | def attach_files(obj, files) | |||
|
150 | attachments = [] | |||
|
151 | if files && files.is_a?(Array) | |||
|
152 | files.each do |file| | |||
|
153 | next unless file.size > 0 | |||
|
154 | a = Attachment.create(:container => obj, :file => file, :author => User.current) | |||
|
155 | attachments << a unless a.new_record? | |||
|
156 | end | |||
|
157 | end | |||
|
158 | attachments | |||
|
159 | end | |||
147 |
|
160 | |||
148 | # qvalues http header parser |
|
161 | # qvalues http header parser | |
149 | # code taken from webrick |
|
162 | # code taken from webrick |
@@ -45,14 +45,8 class DocumentsController < ApplicationController | |||||
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def add_attachment |
|
47 | def add_attachment | |
48 | # Save the attachments |
|
48 | attachments = attach_files(@document, params[:attachments]) | |
49 | @attachments = [] |
|
49 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added') | |
50 | params[:attachments].each { |file| |
|
|||
51 | next unless file.size > 0 |
|
|||
52 | a = Attachment.create(:container => @document, :file => file, :author => User.current) |
|
|||
53 | @attachments << a unless a.new_record? |
|
|||
54 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
55 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added') |
|
|||
56 | redirect_to :action => 'show', :id => @document |
|
50 | redirect_to :action => 'show', :id => @document | |
57 | end |
|
51 | end | |
58 |
|
52 |
@@ -116,13 +116,8 class IssuesController < ApplicationController | |||||
116 |
|
116 | |||
117 | def add_note |
|
117 | def add_note | |
118 | journal = @issue.init_journal(User.current, params[:notes]) |
|
118 | journal = @issue.init_journal(User.current, params[:notes]) | |
119 | params[:attachments].each { |file| |
|
119 | attachments = attach_files(@issue, params[:attachments]) | |
120 | next unless file.size > 0 |
|
120 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
121 | a = Attachment.create(:container => @issue, :file => file, :author => User.current) |
|
|||
122 | journal.details << JournalDetail.new(:property => 'attachment', |
|
|||
123 | :prop_key => a.id, |
|
|||
124 | :value => a.filename) unless a.new_record? |
|
|||
125 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
126 | if journal.save |
|
121 | if journal.save | |
127 | flash[:notice] = l(:notice_successful_update) |
|
122 | flash[:notice] = l(:notice_successful_update) | |
128 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
123 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
@@ -140,15 +135,8 class IssuesController < ApplicationController | |||||
140 | journal = @issue.init_journal(User.current, params[:notes]) |
|
135 | journal = @issue.init_journal(User.current, params[:notes]) | |
141 | @issue.status = @new_status |
|
136 | @issue.status = @new_status | |
142 | if @issue.update_attributes(params[:issue]) |
|
137 | if @issue.update_attributes(params[:issue]) | |
143 | # Save attachments |
|
138 | attachments = attach_files(@issue, params[:attachments]) | |
144 | params[:attachments].each { |file| |
|
139 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
145 | next unless file.size > 0 |
|
|||
146 | a = Attachment.create(:container => @issue, :file => file, :author => User.current) |
|
|||
147 | journal.details << JournalDetail.new(:property => 'attachment', |
|
|||
148 | :prop_key => a.id, |
|
|||
149 | :value => a.filename) unless a.new_record? |
|
|||
150 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
151 |
|
||||
152 | # Log time |
|
140 | # Log time | |
153 | if current_role.allowed_to?(:log_time) |
|
141 | if current_role.allowed_to?(:log_time) | |
154 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
142 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
@@ -42,9 +42,7 class MessagesController < ApplicationController | |||||
42 | @message.sticky = params[:message]['sticky'] |
|
42 | @message.sticky = params[:message]['sticky'] | |
43 | end |
|
43 | end | |
44 | if request.post? && @message.save |
|
44 | if request.post? && @message.save | |
45 | params[:attachments].each { |file| |
|
45 | attach_files(@message, params[:attachments]) | |
46 | Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0 |
|
|||
47 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
48 | redirect_to :action => 'show', :id => @message |
|
46 | redirect_to :action => 'show', :id => @message | |
49 | end |
|
47 | end | |
50 | end |
|
48 | end | |
@@ -56,9 +54,7 class MessagesController < ApplicationController | |||||
56 | @reply.board = @board |
|
54 | @reply.board = @board | |
57 | @topic.children << @reply |
|
55 | @topic.children << @reply | |
58 | if !@reply.new_record? |
|
56 | if !@reply.new_record? | |
59 | params[:attachments].each { |file| |
|
57 | attach_files(@reply, params[:attachments]) | |
60 | Attachment.create(:container => @reply, :file => file, :author => User.current) if file.size > 0 |
|
|||
61 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
62 | end |
|
58 | end | |
63 | redirect_to :action => 'show', :id => @topic |
|
59 | redirect_to :action => 'show', :id => @topic | |
64 | end |
|
60 | end | |
@@ -70,9 +66,7 class MessagesController < ApplicationController | |||||
70 | @message.sticky = params[:message]['sticky'] |
|
66 | @message.sticky = params[:message]['sticky'] | |
71 | end |
|
67 | end | |
72 | if request.post? && @message.update_attributes(params[:message]) |
|
68 | if request.post? && @message.update_attributes(params[:message]) | |
73 | params[:attachments].each { |file| |
|
69 | attach_files(@message, params[:attachments]) | |
74 | Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0 |
|
|||
75 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
76 | flash[:notice] = l(:notice_successful_update) |
|
70 | flash[:notice] = l(:notice_successful_update) | |
77 | redirect_to :action => 'show', :id => @topic |
|
71 | redirect_to :action => 'show', :id => @topic | |
78 | end |
|
72 | end |
@@ -181,10 +181,7 class ProjectsController < ApplicationController | |||||
181 | def add_document |
|
181 | def add_document | |
182 | @document = @project.documents.build(params[:document]) |
|
182 | @document = @project.documents.build(params[:document]) | |
183 | if request.post? and @document.save |
|
183 | if request.post? and @document.save | |
184 | # Save the attachments |
|
184 | attach_files(@document, params[:attachments]) | |
185 | params[:attachments].each { |a| |
|
|||
186 | Attachment.create(:container => @document, :file => a, :author => User.current) unless a.size == 0 |
|
|||
187 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
188 | flash[:notice] = l(:notice_successful_create) |
|
185 | flash[:notice] = l(:notice_successful_create) | |
189 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') |
|
186 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') | |
190 | redirect_to :action => 'list_documents', :id => @project |
|
187 | redirect_to :action => 'list_documents', :id => @project | |
@@ -237,10 +234,7 class ProjectsController < ApplicationController | |||||
237 | @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]) } |
|
234 | @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]) } | |
238 | @issue.custom_values = @custom_values |
|
235 | @issue.custom_values = @custom_values | |
239 | if @issue.save |
|
236 | if @issue.save | |
240 | if params[:attachments] && params[:attachments].is_a?(Array) |
|
237 | attach_files(@issue, params[:attachments]) | |
241 | # Save attachments |
|
|||
242 | params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0} |
|
|||
243 | end |
|
|||
244 | flash[:notice] = l(:notice_successful_create) |
|
238 | flash[:notice] = l(:notice_successful_create) | |
245 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') |
|
239 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
246 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
240 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
@@ -345,14 +339,8 class ProjectsController < ApplicationController | |||||
345 | def add_file |
|
339 | def add_file | |
346 | if request.post? |
|
340 | if request.post? | |
347 | @version = @project.versions.find_by_id(params[:version_id]) |
|
341 | @version = @project.versions.find_by_id(params[:version_id]) | |
348 | # Save the attachments |
|
342 | attachments = attach_files(@issue, params[:attachments]) | |
349 | @attachments = [] |
|
343 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') | |
350 | params[:attachments].each { |file| |
|
|||
351 | next unless file.size > 0 |
|
|||
352 | a = Attachment.create(:container => @version, :file => file, :author => User.current) |
|
|||
353 | @attachments << a unless a.new_record? |
|
|||
354 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
355 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added') |
|
|||
356 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
344 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
357 | end |
|
345 | end | |
358 | @versions = @project.versions.sort |
|
346 | @versions = @project.versions.sort |
@@ -154,11 +154,7 class WikiController < ApplicationController | |||||
154 |
|
154 | |||
155 | def add_attachment |
|
155 | def add_attachment | |
156 | @page = @wiki.find_page(params[:page]) |
|
156 | @page = @wiki.find_page(params[:page]) | |
157 | # Save the attachments |
|
157 | attach_files(@page, params[:attachments]) | |
158 | params[:attachments].each { |file| |
|
|||
159 | next unless file.size > 0 |
|
|||
160 | a = Attachment.create(:container => @page, :file => file, :author => User.current) |
|
|||
161 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
162 | redirect_to :action => 'index', :page => @page.title |
|
158 | redirect_to :action => 'index', :page => @page.title | |
163 | end |
|
159 | end | |
164 |
|
160 |
General Comments 0
You need to be logged in to leave comments.
Login now