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