##// END OF EJS Templates
ProjectsController#add_news moved to NewsController#new....
Jean-Philippe Lang -
r1097:1ecef3a95ae0
parent child
Show More
@@ -0,0 +1,14
1 <h2><%=l(:label_news_new)%></h2>
2
3 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
4 :html => { :id => 'news-form' } do |f| %>
5 <%= render :partial => 'news/form', :locals => { :f => f } %>
6 <%= submit_tag l(:button_create) %>
7 <%= link_to_remote l(:label_preview),
8 { :url => { :controller => 'news', :action => 'preview' },
9 :method => 'post',
10 :update => 'preview',
11 :with => "Form.serialize('news-form')"
12 }, :accesskey => accesskey(:preview) %>
13 <% end %>
14 <div id="preview" class="wiki"></div>
@@ -1,82 +1,107
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, :except => :index
20 before_filter :find_news, :except => [:new, :index, :preview]
21 before_filter :find_project, :only => :new
22 before_filter :authorize, :except => [:index, :preview]
21 23 before_filter :find_optional_project, :only => :index
22 24 accept_key_auth :index
23 25
24 26 def index
25 27 @news_pages, @newss = paginate :news,
26 28 :per_page => 10,
27 29 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
28 30 :include => [:author, :project],
29 31 :order => "#{News.table_name}.created_on DESC"
30 32 respond_to do |format|
31 33 format.html { render :layout => false if request.xhr? }
32 34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
33 35 end
34 36 end
35 37
36 38 def show
37 39 end
38 40
41 def new
42 @news = News.new(:project => @project, :author => User.current)
43 if request.post?
44 @news.attributes = params[:news]
45 if @news.save
46 flash[:notice] = l(:notice_successful_create)
47 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
48 redirect_to :controller => 'news', :action => 'index', :project_id => @project
49 end
50 end
51 end
52
39 53 def edit
40 54 if request.post? and @news.update_attributes(params[:news])
41 55 flash[:notice] = l(:notice_successful_update)
42 56 redirect_to :action => 'show', :id => @news
43 57 end
44 58 end
45 59
46 60 def add_comment
47 61 @comment = Comment.new(params[:comment])
48 62 @comment.author = User.current
49 63 if @news.comments << @comment
50 64 flash[:notice] = l(:label_comment_added)
51 65 redirect_to :action => 'show', :id => @news
52 66 else
53 67 render :action => 'show'
54 68 end
55 69 end
56 70
57 71 def destroy_comment
58 72 @news.comments.find(params[:comment_id]).destroy
59 73 redirect_to :action => 'show', :id => @news
60 74 end
61 75
62 76 def destroy
63 77 @news.destroy
64 78 redirect_to :action => 'index', :project_id => @project
65 79 end
66 80
81 def preview
82 @text = (params[:news] ? params[:news][:description] : nil)
83 render :partial => 'common/preview'
84 end
85
67 86 private
68 def find_project
87 def find_news
69 88 @news = News.find(params[:id])
70 89 @project = @news.project
71 90 rescue ActiveRecord::RecordNotFound
72 91 render_404
73 92 end
74 93
94 def find_project
95 @project = Project.find(params[:project_id])
96 rescue ActiveRecord::RecordNotFound
97 render_404
98 end
99
75 100 def find_optional_project
76 101 return true unless params[:project_id]
77 102 @project = Project.find(params[:project_id])
78 103 authorize
79 104 rescue ActiveRecord::RecordNotFound
80 105 render_404
81 106 end
82 107 end
@@ -1,484 +1,471
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 menu_item :overview
21 21 menu_item :activity, :only => :activity
22 22 menu_item :roadmap, :only => :roadmap
23 23 menu_item :files, :only => [:list_files, :add_file]
24 24 menu_item :settings, :only => :settings
25 25 menu_item :issues, :only => [:bulk_edit_issues, :changelog, :move_issues]
26 26
27 27 before_filter :find_project, :except => [ :index, :list, :add ]
28 28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
29 29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
30 30 accept_key_auth :activity, :calendar
31 31
32 32 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
33 33 cache_sweeper :version_sweeper, :only => [ :add_version ]
34 34
35 35 helper :sort
36 36 include SortHelper
37 37 helper :custom_fields
38 38 include CustomFieldsHelper
39 39 helper :ifpdf
40 40 include IfpdfHelper
41 41 helper :issues
42 42 helper IssuesHelper
43 43 helper :queries
44 44 include QueriesHelper
45 45 helper :repositories
46 46 include RepositoriesHelper
47 47 include ProjectsHelper
48 48
49 49 def index
50 50 list
51 51 render :action => 'list' unless request.xhr?
52 52 end
53 53
54 54 # Lists visible projects
55 55 def list
56 56 projects = Project.find :all,
57 57 :conditions => Project.visible_by(User.current),
58 58 :include => :parent
59 59 @project_tree = projects.group_by {|p| p.parent || p}
60 60 @project_tree.each_key {|p| @project_tree[p] -= [p]}
61 61 end
62 62
63 63 # Add a new project
64 64 def add
65 65 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
66 66 @trackers = Tracker.all
67 67 @root_projects = Project.find(:all,
68 68 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
69 69 :order => 'name')
70 70 @project = Project.new(params[:project])
71 71 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
72 72 if request.get?
73 73 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
74 74 @project.trackers = Tracker.all
75 75 else
76 76 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
77 77 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
78 78 @project.custom_values = @custom_values
79 79 if @project.save
80 80 @project.enabled_module_names = params[:enabled_modules]
81 81 flash[:notice] = l(:notice_successful_create)
82 82 redirect_to :controller => 'admin', :action => 'projects'
83 83 end
84 84 end
85 85 end
86 86
87 87 # Show @project
88 88 def show
89 89 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
90 90 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
91 91 @subprojects = @project.active_children
92 92 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
93 93 @trackers = @project.trackers
94 94 @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])
95 95 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
96 96 @total_hours = @project.time_entries.sum(:hours)
97 97 @key = User.current.rss_key
98 98 end
99 99
100 100 def settings
101 101 @root_projects = Project.find(:all,
102 102 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
103 103 :order => 'name')
104 104 @custom_fields = IssueCustomField.find(:all)
105 105 @issue_category ||= IssueCategory.new
106 106 @member ||= @project.members.new
107 107 @trackers = Tracker.all
108 108 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
109 109 @repository ||= @project.repository
110 110 @wiki ||= @project.wiki
111 111 end
112 112
113 113 # Edit @project
114 114 def edit
115 115 if request.post?
116 116 if params[:custom_fields]
117 117 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
118 118 @project.custom_values = @custom_values
119 119 end
120 120 @project.attributes = params[:project]
121 121 if @project.save
122 122 flash[:notice] = l(:notice_successful_update)
123 123 redirect_to :action => 'settings', :id => @project
124 124 else
125 125 settings
126 126 render :action => 'settings'
127 127 end
128 128 end
129 129 end
130 130
131 131 def modules
132 132 @project.enabled_module_names = params[:enabled_modules]
133 133 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
134 134 end
135 135
136 136 def archive
137 137 @project.archive if request.post? && @project.active?
138 138 redirect_to :controller => 'admin', :action => 'projects'
139 139 end
140 140
141 141 def unarchive
142 142 @project.unarchive if request.post? && !@project.active?
143 143 redirect_to :controller => 'admin', :action => 'projects'
144 144 end
145 145
146 146 # Delete @project
147 147 def destroy
148 148 @project_to_destroy = @project
149 149 if request.post? and params[:confirm]
150 150 @project_to_destroy.destroy
151 151 redirect_to :controller => 'admin', :action => 'projects'
152 152 end
153 153 # hide project in layout
154 154 @project = nil
155 155 end
156 156
157 157 # Add a new issue category to @project
158 158 def add_issue_category
159 159 @category = @project.issue_categories.build(params[:category])
160 160 if request.post? and @category.save
161 161 respond_to do |format|
162 162 format.html do
163 163 flash[:notice] = l(:notice_successful_create)
164 164 redirect_to :action => 'settings', :tab => 'categories', :id => @project
165 165 end
166 166 format.js do
167 167 # IE doesn't support the replace_html rjs method for select box options
168 168 render(:update) {|page| page.replace "issue_category_id",
169 169 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]')
170 170 }
171 171 end
172 172 end
173 173 end
174 174 end
175 175
176 176 # Add a new version to @project
177 177 def add_version
178 178 @version = @project.versions.build(params[:version])
179 179 if request.post? and @version.save
180 180 flash[:notice] = l(:notice_successful_create)
181 181 redirect_to :action => 'settings', :tab => 'versions', :id => @project
182 182 end
183 183 end
184 184
185 185 # Bulk edit issues
186 186 def bulk_edit_issues
187 187 if request.post?
188 188 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
189 189 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
190 190 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
191 191 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
192 192 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
193 193 issues = @project.issues.find_all_by_id(params[:issue_ids])
194 194 unsaved_issue_ids = []
195 195 issues.each do |issue|
196 196 journal = issue.init_journal(User.current, params[:notes])
197 197 issue.priority = priority if priority
198 198 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
199 199 issue.category = category if category
200 200 issue.fixed_version = fixed_version if fixed_version
201 201 issue.start_date = params[:start_date] unless params[:start_date].blank?
202 202 issue.due_date = params[:due_date] unless params[:due_date].blank?
203 203 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
204 204 # Don't save any change to the issue if the user is not authorized to apply the requested status
205 205 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
206 206 # Send notification for each issue (if changed)
207 207 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
208 208 else
209 209 # Keep unsaved issue ids to display them in flash error
210 210 unsaved_issue_ids << issue.id
211 211 end
212 212 end
213 213 if unsaved_issue_ids.empty?
214 214 flash[:notice] = l(:notice_successful_update) unless issues.empty?
215 215 else
216 216 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
217 217 end
218 218 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
219 219 return
220 220 end
221 221 # Find potential statuses the user could be allowed to switch issues to
222 222 @available_statuses = Workflow.find(:all, :include => :new_status,
223 223 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
224 224 render :update do |page|
225 225 page.hide 'query_form'
226 226 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
227 227 end
228 228 end
229 229
230 230 def move_issues
231 231 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
232 232 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
233 233
234 234 @projects = []
235 235 # find projects to which the user is allowed to move the issue
236 236 if User.current.admin?
237 237 # admin is allowed to move issues to any active (visible) project
238 238 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
239 239 else
240 240 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
241 241 end
242 242 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
243 243 @target_project ||= @project
244 244 @trackers = @target_project.trackers
245 245 if request.post?
246 246 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
247 247 unsaved_issue_ids = []
248 248 @issues.each do |issue|
249 249 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
250 250 end
251 251 if unsaved_issue_ids.empty?
252 252 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
253 253 else
254 254 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
255 255 end
256 256 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
257 257 return
258 258 end
259 259 render :layout => false if request.xhr?
260 260 end
261 261
262 # Add a news to @project
263 def add_news
264 @news = News.new(:project => @project, :author => User.current)
265 if request.post?
266 @news.attributes = params[:news]
267 if @news.save
268 flash[:notice] = l(:notice_successful_create)
269 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
270 redirect_to :controller => 'news', :action => 'index', :project_id => @project
271 end
272 end
273 end
274
275 262 def add_file
276 263 if request.post?
277 264 @version = @project.versions.find_by_id(params[:version_id])
278 265 attachments = attach_files(@version, params[:attachments])
279 266 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
280 267 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
281 268 end
282 269 @versions = @project.versions.sort
283 270 end
284 271
285 272 def list_files
286 273 @versions = @project.versions.sort
287 274 end
288 275
289 276 # Show changelog for @project
290 277 def changelog
291 278 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
292 279 retrieve_selected_tracker_ids(@trackers)
293 280 @versions = @project.versions.sort
294 281 end
295 282
296 283 def roadmap
297 284 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
298 285 retrieve_selected_tracker_ids(@trackers)
299 286 @versions = @project.versions.sort
300 287 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
301 288 end
302 289
303 290 def activity
304 291 if params[:year] and params[:year].to_i > 1900
305 292 @year = params[:year].to_i
306 293 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
307 294 @month = params[:month].to_i
308 295 end
309 296 end
310 297 @year ||= Date.today.year
311 298 @month ||= Date.today.month
312 299
313 300 case params[:format]
314 301 when 'atom'
315 302 # 30 last days
316 303 @date_from = Date.today - 30
317 304 @date_to = Date.today + 1
318 305 else
319 306 # current month
320 307 @date_from = Date.civil(@year, @month, 1)
321 308 @date_to = @date_from >> 1
322 309 end
323 310
324 311 @event_types = %w(issues news files documents changesets wiki_pages messages)
325 312 @event_types.delete('wiki_pages') unless @project.wiki
326 313 @event_types.delete('changesets') unless @project.repository
327 314 @event_types.delete('messages') unless @project.boards.any?
328 315 # only show what the user is allowed to view
329 316 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
330 317
331 318 @scope = @event_types.select {|t| params["show_#{t}"]}
332 319 # default events if none is specified in parameters
333 320 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
334 321
335 322 @events = []
336 323
337 324 if @scope.include?('issues')
338 325 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
339 326 @events += @project.issues_status_changes(@date_from, @date_to)
340 327 end
341 328
342 329 if @scope.include?('news')
343 330 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
344 331 end
345 332
346 333 if @scope.include?('files')
347 334 @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 )
348 335 end
349 336
350 337 if @scope.include?('documents')
351 338 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
352 339 @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 )
353 340 end
354 341
355 342 if @scope.include?('wiki_pages')
356 343 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
357 344 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
358 345 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
359 346 "#{WikiContent.versioned_table_name}.id"
360 347 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
361 348 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
362 349 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
363 350 @project.id, @date_from, @date_to]
364 351
365 352 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
366 353 end
367 354
368 355 if @scope.include?('changesets')
369 356 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
370 357 end
371 358
372 359 if @scope.include?('messages')
373 360 @events += Message.find(:all,
374 361 :include => [:board, :author],
375 362 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
376 363 end
377 364
378 365 @events_by_day = @events.group_by(&:event_date)
379 366
380 367 respond_to do |format|
381 368 format.html { render :layout => false if request.xhr? }
382 369 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
383 370 end
384 371 end
385 372
386 373 def calendar
387 374 @trackers = @project.rolled_up_trackers
388 375 retrieve_selected_tracker_ids(@trackers)
389 376
390 377 if params[:year] and params[:year].to_i > 1900
391 378 @year = params[:year].to_i
392 379 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
393 380 @month = params[:month].to_i
394 381 end
395 382 end
396 383 @year ||= Date.today.year
397 384 @month ||= Date.today.month
398 385 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
399 386
400 387 events = []
401 388 @project.issues_with_subprojects(params[:with_subprojects]) do
402 389 events += Issue.find(:all,
403 390 :include => [:tracker, :status, :assigned_to, :priority, :project],
404 391 :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]
405 392 ) unless @selected_tracker_ids.empty?
406 393 end
407 394 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
408 395 @calendar.events = events
409 396
410 397 render :layout => false if request.xhr?
411 398 end
412 399
413 400 def gantt
414 401 @trackers = @project.rolled_up_trackers
415 402 retrieve_selected_tracker_ids(@trackers)
416 403
417 404 if params[:year] and params[:year].to_i >0
418 405 @year_from = params[:year].to_i
419 406 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
420 407 @month_from = params[:month].to_i
421 408 else
422 409 @month_from = 1
423 410 end
424 411 else
425 412 @month_from ||= Date.today.month
426 413 @year_from ||= Date.today.year
427 414 end
428 415
429 416 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
430 417 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
431 418 months = (params[:months] || User.current.pref[:gantt_months]).to_i
432 419 @months = (months > 0 && months < 25) ? months : 6
433 420
434 421 # Save gantt paramters as user preference (zoom and months count)
435 422 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
436 423 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
437 424 User.current.preference.save
438 425 end
439 426
440 427 @date_from = Date.civil(@year_from, @month_from, 1)
441 428 @date_to = (@date_from >> @months) - 1
442 429
443 430 @events = []
444 431 @project.issues_with_subprojects(params[:with_subprojects]) do
445 432 @events += Issue.find(:all,
446 433 :order => "start_date, due_date",
447 434 :include => [:tracker, :status, :assigned_to, :priority, :project],
448 435 :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]
449 436 ) unless @selected_tracker_ids.empty?
450 437 end
451 438 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
452 439 @events.sort! {|x,y| x.start_date <=> y.start_date }
453 440
454 441 if params[:format]=='pdf'
455 442 @options_for_rfpdf ||= {}
456 443 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
457 444 render :template => "projects/gantt.rfpdf", :layout => false
458 445 elsif params[:format]=='png' && respond_to?('gantt_image')
459 446 image = gantt_image(@events, @date_from, @months, @zoom)
460 447 image.format = 'PNG'
461 448 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
462 449 else
463 450 render :template => "projects/gantt.rhtml"
464 451 end
465 452 end
466 453
467 454 private
468 455 # Find project of id params[:id]
469 456 # if not found, redirect to project list
470 457 # Used as a before_filter
471 458 def find_project
472 459 @project = Project.find(params[:id])
473 460 rescue ActiveRecord::RecordNotFound
474 461 render_404
475 462 end
476 463
477 464 def retrieve_selected_tracker_ids(selectable_trackers)
478 465 if ids = params[:tracker_ids]
479 466 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
480 467 else
481 468 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
482 469 end
483 470 end
484 471 end
@@ -1,6 +1,14
1 1 <h2><%=l(:label_news)%></h2>
2 2
3 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit" } do |f| %>
3 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit" },
4 :html => { :id => 'news-form' } do |f| %>
4 5 <%= render :partial => 'form', :locals => { :f => f } %>
5 6 <%= submit_tag l(:button_save) %>
6 <% end %> No newline at end of file
7 <%= link_to_remote l(:label_preview),
8 { :url => { :controller => 'news', :action => 'preview' },
9 :method => 'post',
10 :update => 'preview',
11 :with => "Form.serialize('news-form')"
12 }, :accesskey => accesskey(:preview) %>
13 <% end %>
14 <div id="preview" class="wiki"></div>
@@ -1,38 +1,46
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized(l(:label_news_new),
3 {:controller => 'projects', :action => 'add_news', :id => @project},
3 {:controller => 'news', :action => 'new', :project_id => @project},
4 4 :class => 'icon icon-add',
5 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 => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %>
10 <% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
11 :html => { :id => 'news-form' } do |f| %>
11 12 <%= render :partial => 'news/form', :locals => { :f => f } %>
12 13 <%= submit_tag l(:button_create) %>
14 <%= link_to_remote l(:label_preview),
15 { :url => { :controller => 'news', :action => 'preview' },
16 :method => 'post',
17 :update => 'preview',
18 :with => "Form.serialize('news-form')"
19 }, :accesskey => accesskey(:preview) %> |
13 20 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
14 21 <% end if @project %>
22 <div id="preview" class="wiki"></div>
15 23 </div>
16 24
17 25 <h2><%=l(:label_news_plural)%></h2>
18 26
19 27 <% if @newss.empty? %>
20 28 <p class="nodata"><%= l(:label_no_data) %></p>
21 29 <% else %>
22 30 <% @newss.each do |news| %>
23 31 <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
24 32 <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
25 33 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
26 34 <p class="author"><%= authoring news.created_on, news.author %></p>
27 35 <div class="wiki">
28 36 <%= textilizable(news.description) %>
29 37 </div>
30 38 <% end %>
31 39 <% end %>
32 40 <p class="pagination"><%= pagination_links_full @news_pages %></p>
33 41
34 42 <% content_for :header_tags do %>
35 43 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
36 44 <% end %>
37 45
38 46 <% html_title(l(:label_news_plural)) -%>
@@ -1,48 +1,56
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:button_edit),
3 3 {:controller => 'news', :action => 'edit', :id => @news},
4 4 :class => 'icon icon-edit',
5 5 :accesskey => accesskey(:edit),
6 6 :onclick => 'Element.show("edit-news"); return false;' %>
7 7 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy', :id => @news}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
8 8 </div>
9 9
10 10 <h2><%=h @news.title %></h2>
11 11
12 12 <div id="edit-news" style="display:none;">
13 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news } do |f| %>
13 <% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news },
14 :html => { :id => 'news-form' } do |f| %>
14 15 <%= render :partial => 'form', :locals => { :f => f } %>
15 16 <%= submit_tag l(:button_save) %>
17 <%= link_to_remote l(:label_preview),
18 { :url => { :controller => 'news', :action => 'preview' },
19 :method => 'post',
20 :update => 'preview',
21 :with => "Form.serialize('news-form')"
22 }, :accesskey => accesskey(:preview) %> |
16 23 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
17 24 <% end %>
25 <div id="preview" class="wiki"></div>
18 26 </div>
19 27
20 28 <p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %>
21 29 <span class="author"><%= authoring @news.created_on, @news.author %></span></em></p>
22 30 <div class="wiki">
23 31 <%= textilizable(@news.description) %>
24 32 </div>
25 33 <br />
26 34
27 35 <div id="comments" style="margin-bottom:16px;">
28 36 <h3 class="icon22 icon22-comment"><%= l(:label_comment_plural) %></h3>
29 37 <% @news.comments.each do |comment| %>
30 38 <% next if comment.new_record? %>
31 39 <h4><%= authoring comment.created_on, comment.author %></h4>
32 40 <div class="contextual">
33 41 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
34 42 </div>
35 43 <%= textilizable(comment.comments) %>
36 44 <% end if @news.comments_count > 0 %>
37 45 </div>
38 46
39 47 <% if authorize_for 'news', 'add_comment' %>
40 48 <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comments" %></p>
41 49 <% form_tag({:action => 'add_comment', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
42 50 <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit' %>
43 51 <%= wikitoolbar_for 'comment_comments' %>
44 52 <p><%= submit_tag l(:button_add) %></p>
45 53 <% end %>
46 54 <% end %>
47 55
48 56 <% html_title @news.title -%>
@@ -1,111 +1,111
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 Bazaar )
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 :versions => [:show, :status_by],
31 31 :queries => :index,
32 32 :reports => :issue_report}, :public => true
33 33 map.permission :add_issues, {:issues => :new}
34 34 map.permission :edit_issues, {:projects => :bulk_edit_issues,
35 35 :issues => [:edit, :update, :destroy_attachment]}
36 36 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
37 37 map.permission :add_issue_notes, {:issues => :update}
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 map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
54 map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
55 55 map.permission :view_news, {:news => [:index, :show]}, :public => true
56 56 map.permission :comment_news, {:news => :add_comment}
57 57 end
58 58
59 59 map.project_module :documents do |map|
60 60 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin
61 61 map.permission :view_documents, :documents => [:index, :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, :annotate, :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, :annotate, :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]}
87 87 map.permission :edit_messages, {:messages => :edit}, :require => :member
88 88 map.permission :delete_messages, {:messages => :destroy}, :require => :member
89 89 end
90 90 end
91 91
92 92 # Project menu configuration
93 93 Redmine::MenuManager.map :project_menu do |menu|
94 94 menu.push :overview, { :controller => 'projects', :action => 'show' }, :caption => :label_overview
95 95 menu.push :activity, { :controller => 'projects', :action => 'activity' }, :caption => :label_activity
96 96 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
97 97 :if => Proc.new { |p| p.versions.any? }, :caption => :label_roadmap
98 98 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
99 99 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
100 100 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
101 101 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
102 102 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
103 103 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
104 104 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }, :caption => :label_wiki
105 105 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
106 106 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
107 107 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
108 108 menu.push :repository, { :controller => 'repositories', :action => 'show' },
109 109 :if => Proc.new { |p| p.repository && !p.repository.new_record? }, :caption => :label_repository
110 110 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :caption => :label_settings
111 111 end
@@ -1,48 +1,59
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 'news_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class NewsController; def rescue_action(e) raise e end; end
23 23
24 24 class NewsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :enabled_modules
26 26
27 27 def setup
28 28 @controller = NewsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_index
35 35 get :index
36 36 assert_response :success
37 37 assert_template 'index'
38 38 assert_not_nil assigns(:newss)
39 39 assert_nil assigns(:project)
40 40 end
41 41
42 42 def test_index_with_project
43 43 get :index, :project_id => 1
44 44 assert_response :success
45 45 assert_template 'index'
46 46 assert_not_nil assigns(:newss)
47 47 end
48
49 def test_preview
50 get :preview, :project_id => 1,
51 :news => {:title => '',
52 :description => 'News description',
53 :summary => ''}
54 assert_response :success
55 assert_template 'common/_preview'
56 assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
57 :content => /News description/
58 end
48 59 end
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now