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