##// END OF EJS Templates
Moved ProjectsController#list_news to NewsController#index....
Jean-Philippe Lang -
r875:ad68a82be19f
parent child
Show More
@@ -1,60 +1,82
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 NewsController < ApplicationController
19 19 layout 'base'
20 before_filter :find_project, :authorize
21
20 before_filter :find_project, :authorize, :except => :index
21 before_filter :find_optional_project, :only => :index
22 accept_key_auth :index
23
24 def index
25 @news_pages, @newss = paginate :news,
26 :per_page => 10,
27 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
28 :include => [:author, :project],
29 :order => "#{News.table_name}.created_on DESC"
30 respond_to do |format|
31 format.html { render :layout => false if request.xhr? }
32 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
33 end
34 end
35
22 36 def show
23 37 end
24 38
25 39 def edit
26 40 if request.post? and @news.update_attributes(params[:news])
27 41 flash[:notice] = l(:notice_successful_update)
28 42 redirect_to :action => 'show', :id => @news
29 43 end
30 44 end
31 45
32 46 def add_comment
33 47 @comment = Comment.new(params[:comment])
34 48 @comment.author = logged_in_user
35 49 if @news.comments << @comment
36 50 flash[:notice] = l(:label_comment_added)
37 51 redirect_to :action => 'show', :id => @news
38 52 else
39 53 render :action => 'show'
40 54 end
41 55 end
42 56
43 57 def destroy_comment
44 58 @news.comments.find(params[:comment_id]).destroy
45 59 redirect_to :action => 'show', :id => @news
46 60 end
47 61
48 62 def destroy
49 63 @news.destroy
50 redirect_to :controller => 'projects', :action => 'list_news', :id => @project
64 redirect_to :action => 'index', :project_id => @project
51 65 end
52 66
53 67 private
54 68 def find_project
55 69 @news = News.find(params[:id])
56 70 @project = @news.project
57 71 rescue ActiveRecord::RecordNotFound
58 72 render_404
59 end
73 end
74
75 def find_optional_project
76 return true unless params[:project_id]
77 @project = Project.find(params[:project_id])
78 authorize
79 rescue ActiveRecord::RecordNotFound
80 render_404
81 end
60 82 end
@@ -1,555 +1,545
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 layout 'base'
20 20 before_filter :find_project, :except => [ :index, :list, :add ]
21 21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
22 22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
23 23 accept_key_auth :activity, :calendar
24 24
25 25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
26 26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
27 27 cache_sweeper :version_sweeper, :only => [ :add_version ]
28 28
29 29 helper :sort
30 30 include SortHelper
31 31 helper :custom_fields
32 32 include CustomFieldsHelper
33 33 helper :ifpdf
34 34 include IfpdfHelper
35 35 helper :issues
36 36 helper IssuesHelper
37 37 helper :queries
38 38 include QueriesHelper
39 39 helper :repositories
40 40 include RepositoriesHelper
41 41 include ProjectsHelper
42 42
43 43 def index
44 44 list
45 45 render :action => 'list' unless request.xhr?
46 46 end
47 47
48 48 # Lists visible projects
49 49 def list
50 50 projects = Project.find :all,
51 51 :conditions => Project.visible_by(logged_in_user),
52 52 :include => :parent
53 53 @project_tree = projects.group_by {|p| p.parent || p}
54 54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
55 55 end
56 56
57 57 # Add a new project
58 58 def add
59 59 @custom_fields = IssueCustomField.find(:all)
60 60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
61 61 @project = Project.new(params[:project])
62 62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 63 if request.get?
64 64 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 65 else
66 66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 67 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
68 68 @project.custom_values = @custom_values
69 69 if @project.save
70 70 @project.enabled_module_names = params[:enabled_modules]
71 71 flash[:notice] = l(:notice_successful_create)
72 72 redirect_to :controller => 'admin', :action => 'projects'
73 73 end
74 74 end
75 75 end
76 76
77 77 # Show @project
78 78 def show
79 79 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
80 80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 81 @subprojects = @project.active_children
82 82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
83 83 @trackers = Tracker.find(:all, :order => 'position')
84 84 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
85 85 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
86 86 @total_hours = @project.time_entries.sum(:hours)
87 87 @key = User.current.rss_key
88 88 end
89 89
90 90 def settings
91 91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
92 92 @custom_fields = IssueCustomField.find(:all)
93 93 @issue_category ||= IssueCategory.new
94 94 @member ||= @project.members.new
95 95 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
96 96 @repository ||= @project.repository
97 97 @wiki ||= @project.wiki
98 98 end
99 99
100 100 # Edit @project
101 101 def edit
102 102 if request.post?
103 103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
104 104 if params[:custom_fields]
105 105 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
106 106 @project.custom_values = @custom_values
107 107 end
108 108 @project.attributes = params[:project]
109 109 if @project.save
110 110 flash[:notice] = l(:notice_successful_update)
111 111 redirect_to :action => 'settings', :id => @project
112 112 else
113 113 settings
114 114 render :action => 'settings'
115 115 end
116 116 end
117 117 end
118 118
119 119 def modules
120 120 @project.enabled_module_names = params[:enabled_modules]
121 121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
122 122 end
123 123
124 124 def archive
125 125 @project.archive if request.post? && @project.active?
126 126 redirect_to :controller => 'admin', :action => 'projects'
127 127 end
128 128
129 129 def unarchive
130 130 @project.unarchive if request.post? && !@project.active?
131 131 redirect_to :controller => 'admin', :action => 'projects'
132 132 end
133 133
134 134 # Delete @project
135 135 def destroy
136 136 @project_to_destroy = @project
137 137 if request.post? and params[:confirm]
138 138 @project_to_destroy.destroy
139 139 redirect_to :controller => 'admin', :action => 'projects'
140 140 end
141 141 # hide project in layout
142 142 @project = nil
143 143 end
144 144
145 145 # Add a new issue category to @project
146 146 def add_issue_category
147 147 @category = @project.issue_categories.build(params[:category])
148 148 if request.post? and @category.save
149 149 respond_to do |format|
150 150 format.html do
151 151 flash[:notice] = l(:notice_successful_create)
152 152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
153 153 end
154 154 format.js do
155 155 # IE doesn't support the replace_html rjs method for select box options
156 156 render(:update) {|page| page.replace "issue_category_id",
157 157 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]')
158 158 }
159 159 end
160 160 end
161 161 end
162 162 end
163 163
164 164 # Add a new version to @project
165 165 def add_version
166 166 @version = @project.versions.build(params[:version])
167 167 if request.post? and @version.save
168 168 flash[:notice] = l(:notice_successful_create)
169 169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
170 170 end
171 171 end
172 172
173 173 # Add a new document to @project
174 174 def add_document
175 175 @document = @project.documents.build(params[:document])
176 176 if request.post? and @document.save
177 177 # Save the attachments
178 178 params[:attachments].each { |a|
179 179 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
180 180 } if params[:attachments] and params[:attachments].is_a? Array
181 181 flash[:notice] = l(:notice_successful_create)
182 182 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
183 183 redirect_to :action => 'list_documents', :id => @project
184 184 end
185 185 end
186 186
187 187 # Show documents list of @project
188 188 def list_documents
189 189 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
190 190 documents = @project.documents.find :all, :include => [:attachments, :category]
191 191 case @sort_by
192 192 when 'date'
193 193 @grouped = documents.group_by {|d| d.created_on.to_date }
194 194 when 'title'
195 195 @grouped = documents.group_by {|d| d.title.first.upcase}
196 196 when 'author'
197 197 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
198 198 else
199 199 @grouped = documents.group_by(&:category)
200 200 end
201 201 render :layout => false if request.xhr?
202 202 end
203 203
204 204 # Add a new issue to @project
205 205 # The new issue will be created from an existing one if copy_from parameter is given
206 206 def add_issue
207 207 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
208 208 @issue.project = @project
209 209 @issue.author = User.current
210 210 @issue.tracker ||= Tracker.find(params[:tracker_id])
211 211
212 212 default_status = IssueStatus.default
213 213 unless default_status
214 214 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
215 215 render :nothing => true, :layout => true
216 216 return
217 217 end
218 218 @issue.status = default_status
219 219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
220 220
221 221 if request.get?
222 222 @issue.start_date ||= Date.today
223 223 @custom_values = @issue.custom_values.empty? ?
224 224 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
225 225 @issue.custom_values
226 226 else
227 227 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
228 228 # Check that the user is allowed to apply the requested status
229 229 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
230 230 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
231 231 @issue.custom_values = @custom_values
232 232 if @issue.save
233 233 if params[:attachments] && params[:attachments].is_a?(Array)
234 234 # Save attachments
235 235 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
236 236 end
237 237 flash[:notice] = l(:notice_successful_create)
238 238 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
239 239 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
240 240 return
241 241 end
242 242 end
243 243 @priorities = Enumeration::get_values('IPRI')
244 244 end
245 245
246 246 # Bulk edit issues
247 247 def bulk_edit_issues
248 248 if request.post?
249 249 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
250 250 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
251 251 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
252 252 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
253 253 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
254 254 issues = @project.issues.find_all_by_id(params[:issue_ids])
255 255 unsaved_issue_ids = []
256 256 issues.each do |issue|
257 257 journal = issue.init_journal(User.current, params[:notes])
258 258 issue.priority = priority if priority
259 259 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
260 260 issue.category = category if category
261 261 issue.fixed_version = fixed_version if fixed_version
262 262 issue.start_date = params[:start_date] unless params[:start_date].blank?
263 263 issue.due_date = params[:due_date] unless params[:due_date].blank?
264 264 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
265 265 # Don't save any change to the issue if the user is not authorized to apply the requested status
266 266 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
267 267 # Send notification for each issue (if changed)
268 268 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
269 269 else
270 270 # Keep unsaved issue ids to display them in flash error
271 271 unsaved_issue_ids << issue.id
272 272 end
273 273 end
274 274 if unsaved_issue_ids.empty?
275 275 flash[:notice] = l(:notice_successful_update) unless issues.empty?
276 276 else
277 277 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
278 278 end
279 279 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
280 280 return
281 281 end
282 282 if current_role && User.current.allowed_to?(:change_issue_status, @project)
283 283 # Find potential statuses the user could be allowed to switch issues to
284 284 @available_statuses = Workflow.find(:all, :include => :new_status,
285 285 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
286 286 end
287 287 render :update do |page|
288 288 page.hide 'query_form'
289 289 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
290 290 end
291 291 end
292 292
293 293 def move_issues
294 294 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
295 295 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
296 296 @projects = []
297 297 # find projects to which the user is allowed to move the issue
298 298 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
299 299 # issue can be moved to any tracker
300 300 @trackers = Tracker.find(:all)
301 301 if request.post? and params[:new_project_id] and params[:new_tracker_id]
302 302 new_project = Project.find_by_id(params[:new_project_id])
303 303 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
304 304 @issues.each do |i|
305 305 if new_project && i.project_id != new_project.id
306 306 # issue is moved to another project
307 307 i.category = nil
308 308 i.fixed_version = nil
309 309 # delete issue relations
310 310 i.relations_from.clear
311 311 i.relations_to.clear
312 312 i.project = new_project
313 313 end
314 314 if new_tracker
315 315 i.tracker = new_tracker
316 316 end
317 317 i.save
318 318 end
319 319 flash[:notice] = l(:notice_successful_update)
320 320 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
321 321 end
322 322 end
323 323
324 324 # Add a news to @project
325 325 def add_news
326 326 @news = News.new(:project => @project)
327 327 if request.post?
328 328 @news.attributes = params[:news]
329 329 @news.author_id = self.logged_in_user.id if self.logged_in_user
330 330 if @news.save
331 331 flash[:notice] = l(:notice_successful_create)
332 332 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
333 redirect_to :action => 'list_news', :id => @project
333 redirect_to :controller => 'news', :action => 'index', :project_id => @project
334 334 end
335 335 end
336 336 end
337 337
338 # Show news list of @project
339 def list_news
340 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
341
342 respond_to do |format|
343 format.html { render :layout => false if request.xhr? }
344 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
345 end
346 end
347
348 338 def add_file
349 339 if request.post?
350 340 @version = @project.versions.find_by_id(params[:version_id])
351 341 # Save the attachments
352 342 @attachments = []
353 343 params[:attachments].each { |file|
354 344 next unless file.size > 0
355 345 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
356 346 @attachments << a unless a.new_record?
357 347 } if params[:attachments] and params[:attachments].is_a? Array
358 348 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
359 349 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
360 350 end
361 351 @versions = @project.versions.sort
362 352 end
363 353
364 354 def list_files
365 355 @versions = @project.versions.sort
366 356 end
367 357
368 358 # Show changelog for @project
369 359 def changelog
370 360 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
371 361 retrieve_selected_tracker_ids(@trackers)
372 362 @versions = @project.versions.sort
373 363 end
374 364
375 365 def roadmap
376 366 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
377 367 retrieve_selected_tracker_ids(@trackers)
378 368 @versions = @project.versions.sort
379 369 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
380 370 end
381 371
382 372 def activity
383 373 if params[:year] and params[:year].to_i > 1900
384 374 @year = params[:year].to_i
385 375 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
386 376 @month = params[:month].to_i
387 377 end
388 378 end
389 379 @year ||= Date.today.year
390 380 @month ||= Date.today.month
391 381
392 382 case params[:format]
393 383 when 'atom'
394 384 # 30 last days
395 385 @date_from = Date.today - 30
396 386 @date_to = Date.today + 1
397 387 else
398 388 # current month
399 389 @date_from = Date.civil(@year, @month, 1)
400 390 @date_to = @date_from >> 1
401 391 end
402 392
403 393 @event_types = %w(issues news files documents wiki_pages changesets)
404 394 @event_types.delete('wiki_pages') unless @project.wiki
405 395 @event_types.delete('changesets') unless @project.repository
406 396 # only show what the user is allowed to view
407 397 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
408 398
409 399 @scope = @event_types.select {|t| params["show_#{t}"]}
410 400 # default events if none is specified in parameters
411 401 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
412 402
413 403 @events = []
414 404
415 405 if @scope.include?('issues')
416 406 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
417 407 end
418 408
419 409 if @scope.include?('news')
420 410 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
421 411 end
422 412
423 413 if @scope.include?('files')
424 414 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
425 415 end
426 416
427 417 if @scope.include?('documents')
428 418 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
429 419 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
430 420 end
431 421
432 422 if @scope.include?('wiki_pages')
433 423 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
434 424 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
435 425 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
436 426 "#{WikiContent.versioned_table_name}.id"
437 427 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
438 428 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
439 429 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
440 430 @project.id, @date_from, @date_to]
441 431
442 432 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
443 433 end
444 434
445 435 if @scope.include?('changesets')
446 436 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
447 437 end
448 438
449 439 @events_by_day = @events.group_by(&:event_date)
450 440
451 441 respond_to do |format|
452 442 format.html { render :layout => false if request.xhr? }
453 443 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
454 444 end
455 445 end
456 446
457 447 def calendar
458 448 @trackers = Tracker.find(:all, :order => 'position')
459 449 retrieve_selected_tracker_ids(@trackers)
460 450
461 451 if params[:year] and params[:year].to_i > 1900
462 452 @year = params[:year].to_i
463 453 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
464 454 @month = params[:month].to_i
465 455 end
466 456 end
467 457 @year ||= Date.today.year
468 458 @month ||= Date.today.month
469 459 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
470 460
471 461 events = []
472 462 @project.issues_with_subprojects(params[:with_subprojects]) do
473 463 events += Issue.find(:all,
474 464 :include => [:tracker, :status, :assigned_to, :priority, :project],
475 465 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
476 466 ) unless @selected_tracker_ids.empty?
477 467 end
478 468 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
479 469 @calendar.events = events
480 470
481 471 render :layout => false if request.xhr?
482 472 end
483 473
484 474 def gantt
485 475 @trackers = Tracker.find(:all, :order => 'position')
486 476 retrieve_selected_tracker_ids(@trackers)
487 477
488 478 if params[:year] and params[:year].to_i >0
489 479 @year_from = params[:year].to_i
490 480 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
491 481 @month_from = params[:month].to_i
492 482 else
493 483 @month_from = 1
494 484 end
495 485 else
496 486 @month_from ||= Date.today.month
497 487 @year_from ||= Date.today.year
498 488 end
499 489
500 490 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
501 491 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
502 492 months = (params[:months] || User.current.pref[:gantt_months]).to_i
503 493 @months = (months > 0 && months < 25) ? months : 6
504 494
505 495 # Save gantt paramters as user preference (zoom and months count)
506 496 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
507 497 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
508 498 User.current.preference.save
509 499 end
510 500
511 501 @date_from = Date.civil(@year_from, @month_from, 1)
512 502 @date_to = (@date_from >> @months) - 1
513 503
514 504 @events = []
515 505 @project.issues_with_subprojects(params[:with_subprojects]) do
516 506 @events += Issue.find(:all,
517 507 :order => "start_date, due_date",
518 508 :include => [:tracker, :status, :assigned_to, :priority, :project],
519 509 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
520 510 ) unless @selected_tracker_ids.empty?
521 511 end
522 512 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
523 513 @events.sort! {|x,y| x.start_date <=> y.start_date }
524 514
525 515 if params[:format]=='pdf'
526 516 @options_for_rfpdf ||= {}
527 517 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
528 518 render :template => "projects/gantt.rfpdf", :layout => false
529 519 elsif params[:format]=='png' && respond_to?('gantt_image')
530 520 image = gantt_image(@events, @date_from, @months, @zoom)
531 521 image.format = 'PNG'
532 522 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
533 523 else
534 524 render :template => "projects/gantt.rhtml"
535 525 end
536 526 end
537 527
538 528 private
539 529 # Find project of id params[:id]
540 530 # if not found, redirect to project list
541 531 # Used as a before_filter
542 532 def find_project
543 533 @project = Project.find(params[:id])
544 534 rescue ActiveRecord::RecordNotFound
545 535 render_404
546 536 end
547 537
548 538 def retrieve_selected_tracker_ids(selectable_trackers)
549 539 if ids = params[:tracker_ids]
550 540 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
551 541 else
552 542 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
553 543 end
554 544 end
555 545 end
@@ -1,33 +1,34
1 1 <div class="contextual">
2 <%= link_to_if_authorized l(:label_news_new),
2 <%= link_to_if_authorized(l(:label_news_new),
3 3 {:controller => 'projects', :action => 'add_news', :id => @project},
4 4 :class => 'icon icon-add',
5 :onclick => 'Element.show("add-news"); return false;' %>
5 :onclick => 'Element.show("add-news"); return false;') if @project %>
6 6 </div>
7 7
8 8 <div id="add-news" style="display:none;">
9 9 <h2><%=l(:label_news_new)%></h2>
10 <% labelled_tabular_form_for :news, @news, :url => { :action => "add_news", :id => @project } do |f| %>
10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %>
11 11 <%= render :partial => 'news/form', :locals => { :f => f } %>
12 12 <%= submit_tag l(:button_create) %>
13 13 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
14 <% end %>
14 <% end if @project %>
15 15 </div>
16 16
17 17 <h2><%=l(:label_news_plural)%></h2>
18 18
19 19 <% if @newss.empty? %>
20 20 <p class="nodata"><%= l(:label_no_data) %></p>
21 21 <% else %>
22 22 <% @newss.each do |news| %>
23 <h3><%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
23 <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
24 <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
24 25 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
25 26 <p class="author"><%= authoring news.created_on, news.author %></p>
26 27 <%= textilizable(news.description) %>
27 28 <% end %>
28 29 <% end %>
29 30 <%= pagination_links_full @news_pages %>
30 31
31 32 <% content_for :header_tags do %>
32 33 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
33 34 <% end %>
@@ -1,83 +1,83
1 1 <h2><%=l(:label_overview)%></h2>
2 2
3 3 <div class="splitcontentleft">
4 4 <%= textilizable @project.description %>
5 5 <ul>
6 6 <% unless @project.homepage.blank? %><li><%=l(:field_homepage)%>: <%= auto_link @project.homepage %></li><% end %>
7 7 <% if @subprojects.any? %>
8 8 <li><%=l(:label_subproject_plural)%>: <%= @subprojects.collect{|p| link_to(p.name, :action => 'show', :id => p)}.join(", ") %></li>
9 9 <% end %>
10 10 <% if @project.parent %>
11 11 <li><%=l(:field_parent)%>: <%= link_to @project.parent.name, :controller => 'projects', :action => 'show', :id => @project.parent %></li>
12 12 <% end %>
13 13 <% for custom_value in @custom_values %>
14 14 <% if !custom_value.value.empty? %>
15 15 <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
16 16 <% end %>
17 17 <% end %>
18 18 </ul>
19 19
20 20 <% if User.current.allowed_to?(:view_issues, @project) %>
21 21 <div class="box">
22 22 <h3 class="icon22 icon22-tracker"><%=l(:label_issue_tracking)%></h3>
23 23 <ul>
24 24 <% for tracker in @trackers %>
25 25 <li><%= link_to tracker.name, :controller => 'issues', :action => 'index', :project_id => @project,
26 26 :set_filter => 1,
27 27 "tracker_id" => tracker.id %>:
28 28 <%= @open_issues_by_tracker[tracker] || 0 %> <%= lwr(:label_open_issues, @open_issues_by_tracker[tracker] || 0) %>
29 29 <%= l(:label_on) %> <%= @total_issues_by_tracker[tracker] || 0 %></li>
30 30 <% end %>
31 31 </ul>
32 32 <p><%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 %></p>
33 33 </div>
34 34 <% end %>
35 35 </div>
36 36
37 37 <div class="splitcontentright">
38 38 <% if @members_by_role.any? %>
39 39 <div class="box">
40 40 <h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>
41 41 <p><% @members_by_role.keys.sort.each do |role| %>
42 42 <%= role.name %>:
43 43 <%= @members_by_role[role].collect(&:user).sort.collect{|u| link_to_user u}.join(", ") %>
44 44 <br />
45 45 <% end %></p>
46 46 </div>
47 47 <% end %>
48 48
49 <% if @news.any? && authorize_for('projects', 'list_news') %>
49 <% if @news.any? && authorize_for('news', 'index') %>
50 50 <div class="box">
51 51 <h3><%=l(:label_news_latest)%></h3>
52 52 <%= render :partial => 'news/news', :collection => @news %>
53 <p><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></p>
53 <p><%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %></p>
54 54 </div>
55 55 <% end %>
56 56 </div>
57 57
58 58 <% content_for :sidebar do %>
59 59 <% if authorize_for('projects', 'add_issue') %>
60 60 <h3><%= l(:label_issue_new) %></h3>
61 61 <%= l(:label_tracker) %>: <%= new_issue_selector %>
62 62 <% end %>
63 63
64 64 <% planning_links = []
65 65 planning_links << link_to_if_authorized(l(:label_calendar), :action => 'calendar', :id => @project)
66 66 planning_links << link_to_if_authorized(l(:label_gantt), :action => 'gantt', :id => @project)
67 67 planning_links.compact!
68 68 unless planning_links.empty? %>
69 69 <h3>Planning</h3>
70 70 <p><%= planning_links.join(' | ') %></p>
71 71 <% end %>
72 72
73 73 <% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
74 74 <h3><%= l(:label_spent_time) %></h3>
75 75 <p><span class="icon icon-time"><%= lwr(:label_f_hour, @total_hours) %></span></p>
76 76 <p><%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}) %> |
77 77 <%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}) %></p>
78 78 <% end %>
79 79 <% end %>
80 80
81 81 <% content_for :header_tags do %>
82 82 <%= auto_discovery_link_tag(:atom, {:action => 'activity', :id => @project, :format => 'atom', :key => User.current.rss_key}) %>
83 83 <% end %>
@@ -1,28 +1,31
1 1 <h2><%= l(:label_home) %></h2>
2 2
3 3 <div class="splitcontentleft">
4 4 <%= textilizable Setting.welcome_text %>
5 <% if @news.any? %>
5 6 <div class="box">
6 7 <h3><%=l(:label_news_latest)%></h3>
7 8 <%= render :partial => 'news/news', :collection => @news %>
8 </div>
9 <%= link_to l(:label_issue_view_all), :controller => 'news' %>
10 </div>
11 <% end %>
9 12 </div>
10 13
11 14 <div class="splitcontentright">
12 15 <div class="box">
13 16 <h3 class="icon22 icon22-projects"><%=l(:label_project_latest)%></h3>
14 17 <ul>
15 18 <% for project in @projects %>
16 19 <li>
17 20 <%= link_to project.name, :controller => 'projects', :action => 'show', :id => project %> (<%= format_time(project.created_on) %>)
18 21 <%= textilizable project.description, :project => project %>
19 22 </li>
20 23 <% end %>
21 24 </ul>
22 25 </div>
23 26 </div>
24 27
25 28 <% content_for :header_tags do %>
26 29 <%= auto_discovery_link_tag(:rss, {:controller => 'feeds', :action => 'news', :key => @key}, {:title => l(:label_news_latest)}) %>
27 30 <%= auto_discovery_link_tag(:atom, {:controller => 'feeds', :action => 'news', :key => @key, :format => 'atom'}, {:title => l(:label_news_latest)}) %>
28 31 <% end %>
@@ -1,35 +1,36
1 1 ActionController::Routing::Routes.draw do |map|
2 2 # Add your own custom routes here.
3 3 # The priority is based upon order of creation: first created -> highest priority.
4 4
5 5 # Here's a sample route:
6 6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10 10
11 11 map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
12 12 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
13 13 map.connect 'help/:ctrl/:page', :controller => 'help'
14 14 #map.connect ':controller/:action/:id/:sort_key/:sort_order'
15 15
16 16 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
17 17 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
18 map.connect 'projects/:project_id/news/:action', :controller => 'news'
18 19 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
19 20 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
20 21
21 22 map.with_options :controller => 'repositories' do |omap|
22 23 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
23 24 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
24 25 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
25 26 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
26 27 end
27 28
28 29 # Allow downloading Web Service WSDL as a file with an extension
29 30 # instead of a file named 'wsdl'
30 31 map.connect ':controller/service.wsdl', :action => 'wsdl'
31 32
32 33
33 34 # Install the default route as the lowest priority.
34 35 map.connect ':controller/:action/:id'
35 36 end
@@ -1,103 +1,103
1 1 require 'redmine/access_control'
2 2 require 'redmine/menu_manager'
3 3 require 'redmine/mime_type'
4 4 require 'redmine/themes'
5 5 require 'redmine/plugin'
6 6
7 7 begin
8 8 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
9 9 rescue LoadError
10 10 # RMagick is not available
11 11 end
12 12
13 13 REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
14 14
15 15 # Permissions
16 16 Redmine::AccessControl.map do |map|
17 17 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
18 18 map.permission :search_project, {:search => :index}, :public => true
19 19 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
20 20 map.permission :select_project_modules, {:projects => :modules}, :require => :member
21 21 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy]}, :require => :member
22 22 map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :destroy]}, :require => :member
23 23
24 24 map.project_module :issue_tracking do |map|
25 25 # Issue categories
26 26 map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member
27 27 # Issues
28 28 map.permission :view_issues, {:projects => [:changelog, :roadmap],
29 29 :issues => [:index, :changes, :show, :context_menu],
30 30 :queries => :index,
31 31 :reports => :issue_report}, :public => true
32 32 map.permission :add_issues, {:projects => :add_issue}, :require => :loggedin
33 33 map.permission :edit_issues, {:projects => :bulk_edit_issues,
34 34 :issues => [:edit, :destroy_attachment]}, :require => :loggedin
35 35 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}, :require => :loggedin
36 36 map.permission :add_issue_notes, {:issues => :add_note}, :require => :loggedin
37 37 map.permission :change_issue_status, {:issues => :change_status}, :require => :loggedin
38 38 map.permission :move_issues, {:projects => :move_issues}, :require => :loggedin
39 39 map.permission :delete_issues, {:issues => :destroy}, :require => :member
40 40 # Queries
41 41 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
42 42 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
43 43 # Gantt & calendar
44 44 map.permission :view_gantt, :projects => :gantt
45 45 map.permission :view_calendar, :projects => :calendar
46 46 end
47 47
48 48 map.project_module :time_tracking do |map|
49 49 map.permission :log_time, {:timelog => :edit}, :require => :loggedin
50 50 map.permission :view_time_entries, :timelog => [:details, :report]
51 51 end
52 52
53 53 map.project_module :news do |map|
54 54 map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
55 map.permission :view_news, {:projects => :list_news, :news => :show}, :public => true
55 map.permission :view_news, {:news => [:index, :show]}, :public => true
56 56 map.permission :comment_news, {:news => :add_comment}, :require => :loggedin
57 57 end
58 58
59 59 map.project_module :documents do |map|
60 60 map.permission :manage_documents, {:projects => :add_document, :documents => [:edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin
61 61 map.permission :view_documents, :projects => :list_documents, :documents => [:show, :download]
62 62 end
63 63
64 64 map.project_module :files do |map|
65 65 map.permission :manage_files, {:projects => :add_file, :versions => :destroy_file}, :require => :loggedin
66 66 map.permission :view_files, :projects => :list_files, :versions => :download
67 67 end
68 68
69 69 map.project_module :wiki do |map|
70 70 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
71 71 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
72 72 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
73 73 map.permission :view_wiki_pages, :wiki => [:index, :history, :diff, :special]
74 74 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment, :destroy_attachment]
75 75 end
76 76
77 77 map.project_module :repository do |map|
78 78 map.permission :manage_repository, {:repositories => [:edit, :destroy]}, :require => :member
79 79 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :changes, :diff, :stats, :graph]
80 80 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
81 81 end
82 82
83 83 map.project_module :boards do |map|
84 84 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
85 85 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
86 86 map.permission :add_messages, {:messages => [:new, :reply]}, :require => :loggedin
87 87 end
88 88 end
89 89
90 90 # Project menu configuration
91 91 Redmine::MenuManager.map :project_menu do |menu|
92 92 menu.push :label_overview, :controller => 'projects', :action => 'show'
93 93 menu.push :label_activity, :controller => 'projects', :action => 'activity'
94 94 menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap'
95 95 menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id
96 menu.push :label_news_plural, :controller => 'projects', :action => 'list_news'
96 menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id
97 97 menu.push :label_document_plural, :controller => 'projects', :action => 'list_documents'
98 98 menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
99 99 menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }
100 100 menu.push :label_attachment_plural, :controller => 'projects', :action => 'list_files'
101 101 menu.push :label_repository, { :controller => 'repositories', :action => 'show' }, :if => Proc.new { |p| p.repository && !p.repository.new_record? }
102 102 menu.push :label_settings, :controller => 'projects', :action => 'settings'
103 103 end
@@ -1,66 +1,48
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 require File.dirname(__FILE__) + '/../test_helper'
19 require 'feeds_controller'
19 require 'news_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 class FeedsController; def rescue_action(e) raise e end; end
23
24 class FeedsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :members, :roles
22 class NewsController; def rescue_action(e) raise e end; end
26 23
24 class NewsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :enabled_modules
26
27 27 def setup
28 @controller = FeedsController.new
28 @controller = NewsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 end
32
33 def test_news
34 get :news
35 assert_response :success
36 assert_template 'news'
37 assert_not_nil assigns(:news)
38 end
39
40 def test_issues
41 get :issues
42 assert_response :success
43 assert_template 'issues'
44 assert_not_nil assigns(:issues)
31 User.current = nil
45 32 end
46 33
47 def test_history
48 get :history
34 def test_index
35 get :index
49 36 assert_response :success
50 assert_template 'history'
51 assert_not_nil assigns(:journals)
52 end
53
54 def test_project_privacy
55 get :news, :project_id => 2
56 assert_response 403
37 assert_template 'index'
38 assert_not_nil assigns(:newss)
39 assert_nil assigns(:project)
57 40 end
58
59 def test_rss_key
60 user = User.find(2)
61 key = user.rss_key
62
63 get :news, :project_id => 2, :key => key
41
42 def test_index_with_project
43 get :index, :project_id => 1
64 44 assert_response :success
45 assert_template 'index'
46 assert_not_nil assigns(:newss)
65 47 end
66 48 end
@@ -1,138 +1,131
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'projects_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class ProjectsController; def rescue_action(e) raise e end; end
23 23
24 24 class ProjectsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
26 26
27 27 def setup
28 28 @controller = ProjectsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 end
32 32
33 33 def test_index
34 34 get :index
35 35 assert_response :success
36 36 assert_template 'list'
37 37 end
38 38
39 39 def test_list
40 40 get :list
41 41 assert_response :success
42 42 assert_template 'list'
43 43 assert_not_nil assigns(:project_tree)
44 44 end
45 45
46 46 def test_show
47 47 get :show, :id => 1
48 48 assert_response :success
49 49 assert_template 'show'
50 50 assert_not_nil assigns(:project)
51 51 end
52 52
53 53 def test_list_documents
54 54 get :list_documents, :id => 1
55 55 assert_response :success
56 56 assert_template 'list_documents'
57 57 assert_not_nil assigns(:grouped)
58 58 end
59 59
60 60 def test_bulk_edit_issues
61 61 @request.session[:user_id] = 2
62 62 # update issues priority
63 63 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
64 64 assert_response 302
65 65 # check that the issues were updated
66 66 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
67 67 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
68 end
69
70 def test_list_news
71 get :list_news, :id => 1
72 assert_response :success
73 assert_template 'list_news'
74 assert_not_nil assigns(:newss)
75 68 end
76 69
77 70 def test_list_files
78 71 get :list_files, :id => 1
79 72 assert_response :success
80 73 assert_template 'list_files'
81 74 assert_not_nil assigns(:versions)
82 75 end
83 76
84 77 def test_changelog
85 78 get :changelog, :id => 1
86 79 assert_response :success
87 80 assert_template 'changelog'
88 81 assert_not_nil assigns(:versions)
89 82 end
90 83
91 84 def test_roadmap
92 85 get :roadmap, :id => 1
93 86 assert_response :success
94 87 assert_template 'roadmap'
95 88 assert_not_nil assigns(:versions)
96 89 end
97 90
98 91 def test_activity
99 92 get :activity, :id => 1
100 93 assert_response :success
101 94 assert_template 'activity'
102 95 assert_not_nil assigns(:events_by_day)
103 96 end
104 97
105 98 def test_archive
106 99 @request.session[:user_id] = 1 # admin
107 100 post :archive, :id => 1
108 101 assert_redirected_to 'admin/projects'
109 102 assert !Project.find(1).active?
110 103 end
111 104
112 105 def test_unarchive
113 106 @request.session[:user_id] = 1 # admin
114 107 Project.find(1).archive
115 108 post :unarchive, :id => 1
116 109 assert_redirected_to 'admin/projects'
117 110 assert Project.find(1).active?
118 111 end
119 112
120 113 def test_add_issue
121 114 @request.session[:user_id] = 2
122 115 get :add_issue, :id => 1, :tracker_id => 1
123 116 assert_response :success
124 117 assert_template 'add_issue'
125 118 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
126 119 assert_redirected_to 'projects/1/issues'
127 120 assert Issue.find_by_subject('This is the test_add_issue issue')
128 121 end
129 122
130 123 def test_copy_issue
131 124 @request.session[:user_id] = 2
132 125 get :add_issue, :id => 1, :copy_from => 1
133 126 assert_template 'add_issue'
134 127 assert_not_nil assigns(:issue)
135 128 orig = Issue.find(1)
136 129 assert_equal orig.subject, assigns(:issue).subject
137 130 end
138 131 end
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now