@@ -1,121 +1,122 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'csv' |
|
19 | 19 | |
|
20 | 20 | class ImportsController < ApplicationController |
|
21 | menu_item :issues | |
|
21 | 22 | |
|
22 | 23 | before_action :find_import, :only => [:show, :settings, :mapping, :run] |
|
23 | 24 | before_action :authorize_global |
|
24 | 25 | |
|
25 | 26 | helper :issues |
|
26 | 27 | helper :queries |
|
27 | 28 | |
|
28 | 29 | def new |
|
29 | 30 | end |
|
30 | 31 | |
|
31 | 32 | def create |
|
32 | 33 | @import = IssueImport.new |
|
33 | 34 | @import.user = User.current |
|
34 | 35 | @import.file = params[:file] |
|
35 | 36 | @import.set_default_settings |
|
36 | 37 | |
|
37 | 38 | if @import.save |
|
38 | 39 | redirect_to import_settings_path(@import) |
|
39 | 40 | else |
|
40 | 41 | render :action => 'new' |
|
41 | 42 | end |
|
42 | 43 | end |
|
43 | 44 | |
|
44 | 45 | def show |
|
45 | 46 | end |
|
46 | 47 | |
|
47 | 48 | def settings |
|
48 | 49 | if request.post? && @import.parse_file |
|
49 | 50 | redirect_to import_mapping_path(@import) |
|
50 | 51 | end |
|
51 | 52 | |
|
52 | 53 | rescue CSV::MalformedCSVError => e |
|
53 | 54 | flash.now[:error] = l(:error_invalid_csv_file_or_settings) |
|
54 | 55 | rescue ArgumentError, Encoding::InvalidByteSequenceError => e |
|
55 | 56 | flash.now[:error] = l(:error_invalid_file_encoding, :encoding => ERB::Util.h(@import.settings['encoding'])) |
|
56 | 57 | rescue SystemCallError => e |
|
57 | 58 | flash.now[:error] = l(:error_can_not_read_import_file) |
|
58 | 59 | end |
|
59 | 60 | |
|
60 | 61 | def mapping |
|
61 | 62 | @custom_fields = @import.mappable_custom_fields |
|
62 | 63 | |
|
63 | 64 | if request.post? |
|
64 | 65 | respond_to do |format| |
|
65 | 66 | format.html { |
|
66 | 67 | if params[:previous] |
|
67 | 68 | redirect_to import_settings_path(@import) |
|
68 | 69 | else |
|
69 | 70 | redirect_to import_run_path(@import) |
|
70 | 71 | end |
|
71 | 72 | } |
|
72 | 73 | format.js # updates mapping form on project or tracker change |
|
73 | 74 | end |
|
74 | 75 | end |
|
75 | 76 | end |
|
76 | 77 | |
|
77 | 78 | def run |
|
78 | 79 | if request.post? |
|
79 | 80 | @current = @import.run( |
|
80 | 81 | :max_items => max_items_per_request, |
|
81 | 82 | :max_time => 10.seconds |
|
82 | 83 | ) |
|
83 | 84 | respond_to do |format| |
|
84 | 85 | format.html { |
|
85 | 86 | if @import.finished? |
|
86 | 87 | redirect_to import_path(@import) |
|
87 | 88 | else |
|
88 | 89 | redirect_to import_run_path(@import) |
|
89 | 90 | end |
|
90 | 91 | } |
|
91 | 92 | format.js |
|
92 | 93 | end |
|
93 | 94 | end |
|
94 | 95 | end |
|
95 | 96 | |
|
96 | 97 | private |
|
97 | 98 | |
|
98 | 99 | def find_import |
|
99 | 100 | @import = Import.where(:user_id => User.current.id, :filename => params[:id]).first |
|
100 | 101 | if @import.nil? |
|
101 | 102 | render_404 |
|
102 | 103 | return |
|
103 | 104 | elsif @import.finished? && action_name != 'show' |
|
104 | 105 | redirect_to import_path(@import) |
|
105 | 106 | return |
|
106 | 107 | end |
|
107 | 108 | update_from_params if request.post? |
|
108 | 109 | end |
|
109 | 110 | |
|
110 | 111 | def update_from_params |
|
111 | 112 | if params[:import_settings].is_a?(Hash) |
|
112 | 113 | @import.settings ||= {} |
|
113 | 114 | @import.settings.merge!(params[:import_settings]) |
|
114 | 115 | @import.save! |
|
115 | 116 | end |
|
116 | 117 | end |
|
117 | 118 | |
|
118 | 119 | def max_items_per_request |
|
119 | 120 | 5 |
|
120 | 121 | end |
|
121 | 122 | end |
@@ -1,240 +1,240 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class ProjectsController < ApplicationController |
|
19 | 19 | menu_item :overview |
|
20 | 20 | menu_item :settings, :only => :settings |
|
21 | menu_item :projects, :only => [:index, :new, :create] | |
|
21 | menu_item :projects, :only => [:index, :new, :copy, :create] | |
|
22 | 22 | |
|
23 | 23 | before_action :find_project, :except => [ :index, :list, :new, :create, :copy ] |
|
24 | 24 | before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] |
|
25 | 25 | before_action :authorize_global, :only => [:new, :create] |
|
26 | 26 | before_action :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
|
27 | 27 | accept_rss_auth :index |
|
28 | 28 | accept_api_auth :index, :show, :create, :update, :destroy |
|
29 | 29 | require_sudo_mode :destroy |
|
30 | 30 | |
|
31 | 31 | helper :custom_fields |
|
32 | 32 | helper :issues |
|
33 | 33 | helper :queries |
|
34 | 34 | helper :repositories |
|
35 | 35 | helper :members |
|
36 | 36 | |
|
37 | 37 | # Lists visible projects |
|
38 | 38 | def index |
|
39 | 39 | scope = Project.visible.sorted |
|
40 | 40 | |
|
41 | 41 | respond_to do |format| |
|
42 | 42 | format.html { |
|
43 | 43 | unless params[:closed] |
|
44 | 44 | scope = scope.active |
|
45 | 45 | end |
|
46 | 46 | @projects = scope.to_a |
|
47 | 47 | } |
|
48 | 48 | format.js { |
|
49 | 49 | if params[:q].present? |
|
50 | 50 | @projects = Project.visible.like(params[:q]).to_a |
|
51 | 51 | else |
|
52 | 52 | @projects = User.current.projects.to_a |
|
53 | 53 | end |
|
54 | 54 | } |
|
55 | 55 | format.api { |
|
56 | 56 | @offset, @limit = api_offset_and_limit |
|
57 | 57 | @project_count = scope.count |
|
58 | 58 | @projects = scope.offset(@offset).limit(@limit).to_a |
|
59 | 59 | } |
|
60 | 60 | format.atom { |
|
61 | 61 | projects = scope.reorder(:created_on => :desc).limit(Setting.feeds_limit.to_i).to_a |
|
62 | 62 | render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
|
63 | 63 | } |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def new |
|
68 | 68 | @issue_custom_fields = IssueCustomField.sorted.to_a |
|
69 | 69 | @trackers = Tracker.sorted.to_a |
|
70 | 70 | @project = Project.new |
|
71 | 71 | @project.safe_attributes = params[:project] |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def create |
|
75 | 75 | @issue_custom_fields = IssueCustomField.sorted.to_a |
|
76 | 76 | @trackers = Tracker.sorted.to_a |
|
77 | 77 | @project = Project.new |
|
78 | 78 | @project.safe_attributes = params[:project] |
|
79 | 79 | |
|
80 | 80 | if @project.save |
|
81 | 81 | unless User.current.admin? |
|
82 | 82 | @project.add_default_member(User.current) |
|
83 | 83 | end |
|
84 | 84 | respond_to do |format| |
|
85 | 85 | format.html { |
|
86 | 86 | flash[:notice] = l(:notice_successful_create) |
|
87 | 87 | if params[:continue] |
|
88 | 88 | attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} |
|
89 | 89 | redirect_to new_project_path(attrs) |
|
90 | 90 | else |
|
91 | 91 | redirect_to settings_project_path(@project) |
|
92 | 92 | end |
|
93 | 93 | } |
|
94 | 94 | format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } |
|
95 | 95 | end |
|
96 | 96 | else |
|
97 | 97 | respond_to do |format| |
|
98 | 98 | format.html { render :action => 'new' } |
|
99 | 99 | format.api { render_validation_errors(@project) } |
|
100 | 100 | end |
|
101 | 101 | end |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def copy |
|
105 | 105 | @issue_custom_fields = IssueCustomField.sorted.to_a |
|
106 | 106 | @trackers = Tracker.sorted.to_a |
|
107 | 107 | @source_project = Project.find(params[:id]) |
|
108 | 108 | if request.get? |
|
109 | 109 | @project = Project.copy_from(@source_project) |
|
110 | 110 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
|
111 | 111 | else |
|
112 | 112 | Mailer.with_deliveries(params[:notifications] == '1') do |
|
113 | 113 | @project = Project.new |
|
114 | 114 | @project.safe_attributes = params[:project] |
|
115 | 115 | if @project.copy(@source_project, :only => params[:only]) |
|
116 | 116 | flash[:notice] = l(:notice_successful_create) |
|
117 | 117 | redirect_to settings_project_path(@project) |
|
118 | 118 | elsif !@project.new_record? |
|
119 | 119 | # Project was created |
|
120 | 120 | # But some objects were not copied due to validation failures |
|
121 | 121 | # (eg. issues from disabled trackers) |
|
122 | 122 | # TODO: inform about that |
|
123 | 123 | redirect_to settings_project_path(@project) |
|
124 | 124 | end |
|
125 | 125 | end |
|
126 | 126 | end |
|
127 | 127 | rescue ActiveRecord::RecordNotFound |
|
128 | 128 | # source_project not found |
|
129 | 129 | render_404 |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | # Show @project |
|
133 | 133 | def show |
|
134 | 134 | # try to redirect to the requested menu item |
|
135 | 135 | if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) |
|
136 | 136 | return |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | @users_by_role = @project.users_by_role |
|
140 | 140 | @subprojects = @project.children.visible.to_a |
|
141 | 141 | @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a |
|
142 | 142 | @trackers = @project.rolled_up_trackers.visible |
|
143 | 143 | |
|
144 | 144 | cond = @project.project_condition(Setting.display_subprojects_issues?) |
|
145 | 145 | |
|
146 | 146 | @open_issues_by_tracker = Issue.visible.open.where(cond).group(:tracker).count |
|
147 | 147 | @total_issues_by_tracker = Issue.visible.where(cond).group(:tracker).count |
|
148 | 148 | |
|
149 | 149 | if User.current.allowed_to_view_all_time_entries?(@project) |
|
150 | 150 | @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | @key = User.current.rss_key |
|
154 | 154 | |
|
155 | 155 | respond_to do |format| |
|
156 | 156 | format.html |
|
157 | 157 | format.api |
|
158 | 158 | end |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | def settings |
|
162 | 162 | @issue_custom_fields = IssueCustomField.sorted.to_a |
|
163 | 163 | @issue_category ||= IssueCategory.new |
|
164 | 164 | @member ||= @project.members.new |
|
165 | 165 | @trackers = Tracker.sorted.to_a |
|
166 | 166 | |
|
167 | 167 | @version_status = params[:version_status] || 'open' |
|
168 | 168 | @version_name = params[:version_name] |
|
169 | 169 | @versions = @project.shared_versions.status(@version_status).like(@version_name) |
|
170 | 170 | @wiki ||= @project.wiki || Wiki.new(:project => @project) |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def edit |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def update |
|
177 | 177 | @project.safe_attributes = params[:project] |
|
178 | 178 | if @project.save |
|
179 | 179 | respond_to do |format| |
|
180 | 180 | format.html { |
|
181 | 181 | flash[:notice] = l(:notice_successful_update) |
|
182 | 182 | redirect_to settings_project_path(@project) |
|
183 | 183 | } |
|
184 | 184 | format.api { render_api_ok } |
|
185 | 185 | end |
|
186 | 186 | else |
|
187 | 187 | respond_to do |format| |
|
188 | 188 | format.html { |
|
189 | 189 | settings |
|
190 | 190 | render :action => 'settings' |
|
191 | 191 | } |
|
192 | 192 | format.api { render_validation_errors(@project) } |
|
193 | 193 | end |
|
194 | 194 | end |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def modules |
|
198 | 198 | @project.enabled_module_names = params[:enabled_module_names] |
|
199 | 199 | flash[:notice] = l(:notice_successful_update) |
|
200 | 200 | redirect_to settings_project_path(@project, :tab => 'modules') |
|
201 | 201 | end |
|
202 | 202 | |
|
203 | 203 | def archive |
|
204 | 204 | unless @project.archive |
|
205 | 205 | flash[:error] = l(:error_can_not_archive_project) |
|
206 | 206 | end |
|
207 | 207 | redirect_to_referer_or admin_projects_path(:status => params[:status]) |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def unarchive |
|
211 | 211 | unless @project.active? |
|
212 | 212 | @project.unarchive |
|
213 | 213 | end |
|
214 | 214 | redirect_to_referer_or admin_projects_path(:status => params[:status]) |
|
215 | 215 | end |
|
216 | 216 | |
|
217 | 217 | def close |
|
218 | 218 | @project.close |
|
219 | 219 | redirect_to project_path(@project) |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def reopen |
|
223 | 223 | @project.reopen |
|
224 | 224 | redirect_to project_path(@project) |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | # Delete @project |
|
228 | 228 | def destroy |
|
229 | 229 | @project_to_destroy = @project |
|
230 | 230 | if api_request? || params[:confirm] |
|
231 | 231 | @project_to_destroy.destroy |
|
232 | 232 | respond_to do |format| |
|
233 | 233 | format.html { redirect_to admin_projects_path } |
|
234 | 234 | format.api { render_api_ok } |
|
235 | 235 | end |
|
236 | 236 | end |
|
237 | 237 | # hide project in layout |
|
238 | 238 | @project = nil |
|
239 | 239 | end |
|
240 | 240 | end |
General Comments 0
You need to be logged in to leave comments.
Login now