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