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