@@ -1,76 +1,76 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class FilesController < ApplicationController |
|
18 | class FilesController < ApplicationController | |
19 | menu_item :files |
|
19 | menu_item :files | |
20 |
|
20 | |||
21 | before_action :find_project_by_project_id |
|
21 | before_action :find_project_by_project_id | |
22 | before_action :authorize |
|
22 | before_action :authorize | |
23 | accept_api_auth :index, :create |
|
23 | accept_api_auth :index, :create | |
24 |
|
24 | |||
25 |
helper :attachments |
|
25 | helper :attachments | |
26 | helper :sort |
|
26 | helper :sort | |
27 | include SortHelper |
|
27 | include SortHelper | |
28 |
|
28 | |||
29 | def index |
|
29 | def index | |
30 | sort_init 'filename', 'asc' |
|
30 | sort_init 'filename', 'asc' | |
31 | sort_update 'filename' => "#{Attachment.table_name}.filename", |
|
31 | sort_update 'filename' => "#{Attachment.table_name}.filename", | |
32 | 'created_on' => "#{Attachment.table_name}.created_on", |
|
32 | 'created_on' => "#{Attachment.table_name}.created_on", | |
33 | 'size' => "#{Attachment.table_name}.filesize", |
|
33 | 'size' => "#{Attachment.table_name}.filesize", | |
34 | 'downloads' => "#{Attachment.table_name}.downloads" |
|
34 | 'downloads' => "#{Attachment.table_name}.downloads" | |
35 |
|
35 | |||
36 | @containers = [Project.includes(:attachments). |
|
36 | @containers = [Project.includes(:attachments). | |
37 | references(:attachments).reorder(sort_clause).find(@project.id)] |
|
37 | references(:attachments).reorder(sort_clause).find(@project.id)] | |
38 | @containers += @project.versions.includes(:attachments). |
|
38 | @containers += @project.versions.includes(:attachments). | |
39 | references(:attachments).reorder(sort_clause).to_a.sort.reverse |
|
39 | references(:attachments).reorder(sort_clause).to_a.sort.reverse | |
40 | respond_to do |format| |
|
40 | respond_to do |format| | |
41 | format.html { render :layout => !request.xhr? } |
|
41 | format.html { render :layout => !request.xhr? } | |
42 | format.api |
|
42 | format.api | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def new |
|
46 | def new | |
47 | @versions = @project.versions.sort |
|
47 | @versions = @project.versions.sort | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def create |
|
50 | def create | |
51 | version_id = params[:version_id] || (params[:file] && params[:file][:version_id]) |
|
51 | version_id = params[:version_id] || (params[:file] && params[:file][:version_id]) | |
52 | container = version_id.blank? ? @project : @project.versions.find_by_id(version_id) |
|
52 | container = version_id.blank? ? @project : @project.versions.find_by_id(version_id) | |
53 | attachments = Attachment.attach_files(container, (params[:attachments] || (params[:file] && params[:file][:token] && params))) |
|
53 | attachments = Attachment.attach_files(container, (params[:attachments] || (params[:file] && params[:file][:token] && params))) | |
54 | render_attachment_warning_if_needed(container) |
|
54 | render_attachment_warning_if_needed(container) | |
55 |
|
55 | |||
56 | if attachments[:files].present? |
|
56 | if attachments[:files].present? | |
57 | if Setting.notified_events.include?('file_added') |
|
57 | if Setting.notified_events.include?('file_added') | |
58 | Mailer.attachments_added(attachments[:files]).deliver |
|
58 | Mailer.attachments_added(attachments[:files]).deliver | |
59 | end |
|
59 | end | |
60 | respond_to do |format| |
|
60 | respond_to do |format| | |
61 | format.html { |
|
61 | format.html { | |
62 | flash[:notice] = l(:label_file_added) |
|
62 | flash[:notice] = l(:label_file_added) | |
63 | redirect_to project_files_path(@project) } |
|
63 | redirect_to project_files_path(@project) } | |
64 | format.api { render_api_ok } |
|
64 | format.api { render_api_ok } | |
65 | end |
|
65 | end | |
66 | else |
|
66 | else | |
67 | respond_to do |format| |
|
67 | respond_to do |format| | |
68 | format.html { |
|
68 | format.html { | |
69 | flash.now[:error] = l(:label_attachment) + " " + l('activerecord.errors.messages.invalid') |
|
69 | flash.now[:error] = l(:label_attachment) + " " + l('activerecord.errors.messages.invalid') | |
70 | new |
|
70 | new | |
71 | render :action => 'new' } |
|
71 | render :action => 'new' } | |
72 | format.api { render :status => :bad_request } |
|
72 | format.api { render :status => :bad_request } | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end |
General Comments 0
You need to be logged in to leave comments.
Login now