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