##// END OF EJS Templates
Adds missing flash messages on project settings (#5043)....
Jean-Philippe Lang -
r3451:63ed494f2146
parent child
Show More
@@ -1,383 +1,386
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2009 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 :activity, :only => :activity
21 21 menu_item :roadmap, :only => :roadmap
22 22 menu_item :files, :only => [:list_files, :add_file]
23 23 menu_item :settings, :only => :settings
24 24
25 25 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
26 26 before_filter :find_optional_project, :only => :activity
27 27 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
28 28 before_filter :authorize_global, :only => :add
29 29 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
30 30 accept_key_auth :activity
31 31
32 32 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
33 33 if controller.request.post?
34 34 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
35 35 end
36 36 end
37 37
38 38 helper :sort
39 39 include SortHelper
40 40 helper :custom_fields
41 41 include CustomFieldsHelper
42 42 helper :issues
43 43 helper IssuesHelper
44 44 helper :queries
45 45 include QueriesHelper
46 46 helper :repositories
47 47 include RepositoriesHelper
48 48 include ProjectsHelper
49 49
50 50 # Lists visible projects
51 51 def index
52 52 respond_to do |format|
53 53 format.html {
54 54 @projects = Project.visible.find(:all, :order => 'lft')
55 55 }
56 56 format.xml {
57 57 @projects = Project.visible.find(:all, :order => 'lft')
58 58 }
59 59 format.atom {
60 60 projects = Project.visible.find(:all, :order => 'created_on DESC',
61 61 :limit => Setting.feeds_limit.to_i)
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 # Add a new project
68 68 def add
69 69 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
70 70 @trackers = Tracker.all
71 71 @project = Project.new(params[:project])
72 72 if request.get?
73 73 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
74 74 @project.trackers = Tracker.all
75 75 @project.is_public = Setting.default_projects_public?
76 76 @project.enabled_module_names = Setting.default_projects_modules
77 77 else
78 78 @project.enabled_module_names = params[:enabled_modules]
79 79 if validate_parent_id && @project.save
80 80 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
81 81 # Add current user as a project member if he is not admin
82 82 unless User.current.admin?
83 83 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
84 84 m = Member.new(:user => User.current, :roles => [r])
85 85 @project.members << m
86 86 end
87 87 respond_to do |format|
88 88 format.html {
89 89 flash[:notice] = l(:notice_successful_create)
90 90 redirect_to :controller => 'projects', :action => 'settings', :id => @project
91 91 }
92 92 format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
93 93 end
94 94 else
95 95 respond_to do |format|
96 96 format.html
97 97 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
98 98 end
99 99 end
100 100 end
101 101 end
102 102
103 103 def copy
104 104 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
105 105 @trackers = Tracker.all
106 106 @root_projects = Project.find(:all,
107 107 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
108 108 :order => 'name')
109 109 @source_project = Project.find(params[:id])
110 110 if request.get?
111 111 @project = Project.copy_from(@source_project)
112 112 if @project
113 113 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
114 114 else
115 115 redirect_to :controller => 'admin', :action => 'projects'
116 116 end
117 117 else
118 118 @project = Project.new(params[:project])
119 119 @project.enabled_module_names = params[:enabled_modules]
120 120 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
121 121 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
122 122 flash[:notice] = l(:notice_successful_create)
123 123 redirect_to :controller => 'admin', :action => 'projects'
124 124 elsif !@project.new_record?
125 125 # Project was created
126 126 # But some objects were not copied due to validation failures
127 127 # (eg. issues from disabled trackers)
128 128 # TODO: inform about that
129 129 redirect_to :controller => 'admin', :action => 'projects'
130 130 end
131 131 end
132 132 rescue ActiveRecord::RecordNotFound
133 133 redirect_to :controller => 'admin', :action => 'projects'
134 134 end
135 135
136 136 # Show @project
137 137 def show
138 138 if params[:jump]
139 139 # try to redirect to the requested menu item
140 140 redirect_to_project_menu_item(@project, params[:jump]) && return
141 141 end
142 142
143 143 @users_by_role = @project.users_by_role
144 144 @subprojects = @project.children.visible
145 145 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
146 146 @trackers = @project.rolled_up_trackers
147 147
148 148 cond = @project.project_condition(Setting.display_subprojects_issues?)
149 149
150 150 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
151 151 :include => [:project, :status, :tracker],
152 152 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
153 153 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
154 154 :include => [:project, :status, :tracker],
155 155 :conditions => cond)
156 156
157 157 TimeEntry.visible_by(User.current) do
158 158 @total_hours = TimeEntry.sum(:hours,
159 159 :include => :project,
160 160 :conditions => cond).to_f
161 161 end
162 162 @key = User.current.rss_key
163 163
164 164 respond_to do |format|
165 165 format.html
166 166 format.xml
167 167 end
168 168 end
169 169
170 170 def settings
171 171 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
172 172 @issue_category ||= IssueCategory.new
173 173 @member ||= @project.members.new
174 174 @trackers = Tracker.all
175 175 @repository ||= @project.repository
176 176 @wiki ||= @project.wiki
177 177 end
178 178
179 179 # Edit @project
180 180 def edit
181 181 if request.get?
182 182 else
183 183 @project.attributes = params[:project]
184 184 if validate_parent_id && @project.save
185 185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
186 186 respond_to do |format|
187 187 format.html {
188 188 flash[:notice] = l(:notice_successful_update)
189 189 redirect_to :action => 'settings', :id => @project
190 190 }
191 191 format.xml { head :ok }
192 192 end
193 193 else
194 194 respond_to do |format|
195 195 format.html {
196 196 settings
197 197 render :action => 'settings'
198 198 }
199 199 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
200 200 end
201 201 end
202 202 end
203 203 end
204 204
205 205 def modules
206 206 @project.enabled_module_names = params[:enabled_modules]
207 flash[:notice] = l(:notice_successful_update)
207 208 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
208 209 end
209 210
210 211 def archive
211 212 if request.post?
212 213 unless @project.archive
213 214 flash[:error] = l(:error_can_not_archive_project)
214 215 end
215 216 end
216 217 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
217 218 end
218 219
219 220 def unarchive
220 221 @project.unarchive if request.post? && !@project.active?
221 222 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
222 223 end
223 224
224 225 # Delete @project
225 226 def destroy
226 227 @project_to_destroy = @project
227 228 if request.get?
228 229 # display confirmation view
229 230 else
230 231 if params[:format] == 'xml' || params[:confirm]
231 232 @project_to_destroy.destroy
232 233 respond_to do |format|
233 234 format.html { redirect_to :controller => 'admin', :action => 'projects' }
234 235 format.xml { head :ok }
235 236 end
236 237 end
237 238 end
238 239 # hide project in layout
239 240 @project = nil
240 241 end
241 242
242 243 def add_file
243 244 if request.post?
244 245 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
245 246 attachments = Attachment.attach_files(container, params[:attachments])
246 247 render_attachment_warning_if_needed(container)
247 248
248 249 if !attachments.empty? && Setting.notified_events.include?('file_added')
249 250 Mailer.deliver_attachments_added(attachments[:files])
250 251 end
251 252 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
252 253 return
253 254 end
254 255 @versions = @project.versions.sort
255 256 end
256 257
257 258 def save_activities
258 259 if request.post? && params[:enumerations]
259 260 Project.transaction do
260 261 params[:enumerations].each do |id, activity|
261 262 @project.update_or_create_time_entry_activity(id, activity)
262 263 end
263 264 end
265 flash[:notice] = l(:notice_successful_update)
264 266 end
265 267
266 268 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
267 269 end
268 270
269 271 def reset_activities
270 272 @project.time_entry_activities.each do |time_entry_activity|
271 273 time_entry_activity.destroy(time_entry_activity.parent)
272 274 end
275 flash[:notice] = l(:notice_successful_update)
273 276 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
274 277 end
275 278
276 279 def list_files
277 280 sort_init 'filename', 'asc'
278 281 sort_update 'filename' => "#{Attachment.table_name}.filename",
279 282 'created_on' => "#{Attachment.table_name}.created_on",
280 283 'size' => "#{Attachment.table_name}.filesize",
281 284 'downloads' => "#{Attachment.table_name}.downloads"
282 285
283 286 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
284 287 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
285 288 render :layout => !request.xhr?
286 289 end
287 290
288 291 def roadmap
289 292 @trackers = @project.trackers.find(:all, :order => 'position')
290 293 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
291 294 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
292 295 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
293 296
294 297 @versions = @project.shared_versions.sort
295 298 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
296 299
297 300 @issues_by_version = {}
298 301 unless @selected_tracker_ids.empty?
299 302 @versions.each do |version|
300 303 issues = version.fixed_issues.visible.find(:all,
301 304 :include => [:project, :status, :tracker, :priority],
302 305 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
303 306 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
304 307 @issues_by_version[version] = issues
305 308 end
306 309 end
307 310 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
308 311 end
309 312
310 313 def activity
311 314 @days = Setting.activity_days_default.to_i
312 315
313 316 if params[:from]
314 317 begin; @date_to = params[:from].to_date + 1; rescue; end
315 318 end
316 319
317 320 @date_to ||= Date.today + 1
318 321 @date_from = @date_to - @days
319 322 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
320 323 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
321 324
322 325 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
323 326 :with_subprojects => @with_subprojects,
324 327 :author => @author)
325 328 @activity.scope_select {|t| !params["show_#{t}"].nil?}
326 329 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
327 330
328 331 events = @activity.events(@date_from, @date_to)
329 332
330 333 if events.empty? || stale?(:etag => [events.first, User.current])
331 334 respond_to do |format|
332 335 format.html {
333 336 @events_by_day = events.group_by(&:event_date)
334 337 render :layout => false if request.xhr?
335 338 }
336 339 format.atom {
337 340 title = l(:label_activity)
338 341 if @author
339 342 title = @author.name
340 343 elsif @activity.scope.size == 1
341 344 title = l("label_#{@activity.scope.first.singularize}_plural")
342 345 end
343 346 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
344 347 }
345 348 end
346 349 end
347 350
348 351 rescue ActiveRecord::RecordNotFound
349 352 render_404
350 353 end
351 354
352 355 private
353 356 def find_optional_project
354 357 return true unless params[:id]
355 358 @project = Project.find(params[:id])
356 359 authorize
357 360 rescue ActiveRecord::RecordNotFound
358 361 render_404
359 362 end
360 363
361 364 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
362 365 if ids = params[:tracker_ids]
363 366 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
364 367 else
365 368 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
366 369 end
367 370 end
368 371
369 372 # Validates parent_id param according to user's permissions
370 373 # TODO: move it to Project model in a validation that depends on User.current
371 374 def validate_parent_id
372 375 return true if User.current.admin?
373 376 parent_id = params[:project] && params[:project][:parent_id]
374 377 if parent_id || @project.new_record?
375 378 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
376 379 unless @project.allowed_parents.include?(parent)
377 380 @project.errors.add :parent_id, :invalid
378 381 return false
379 382 end
380 383 end
381 384 true
382 385 end
383 386 end
General Comments 0
You need to be logged in to leave comments. Login now