@@ -1,691 +1,691 | |||
|
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 'csv' |
|
19 | 19 | |
|
20 | 20 | class ProjectsController < ApplicationController |
|
21 | 21 | layout 'base' |
|
22 | 22 | before_filter :find_project, :authorize, :except => [ :index, :list, :add ] |
|
23 | 23 | before_filter :require_admin, :only => [ :add, :destroy ] |
|
24 | 24 | |
|
25 | 25 | helper :sort |
|
26 | 26 | include SortHelper |
|
27 | 27 | helper :custom_fields |
|
28 | 28 | include CustomFieldsHelper |
|
29 | 29 | helper :ifpdf |
|
30 | 30 | include IfpdfHelper |
|
31 | 31 | helper IssuesHelper |
|
32 | 32 | helper :queries |
|
33 | 33 | include QueriesHelper |
|
34 | 34 | |
|
35 | 35 | def index |
|
36 | 36 | list |
|
37 | 37 | render :action => 'list' unless request.xhr? |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | # Lists public projects |
|
41 | 41 | def list |
|
42 | 42 | sort_init "#{Project.table_name}.name", "asc" |
|
43 | 43 | sort_update |
|
44 | 44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) |
|
45 | 45 | @project_pages = Paginator.new self, @project_count, |
|
46 | 46 | 15, |
|
47 | 47 | params['page'] |
|
48 | 48 | @projects = Project.find :all, :order => sort_clause, |
|
49 | 49 | :conditions => ["#{Project.table_name}.is_public=?", true], |
|
50 | 50 | :include => :parent, |
|
51 | 51 | :limit => @project_pages.items_per_page, |
|
52 | 52 | :offset => @project_pages.current.offset |
|
53 | 53 | |
|
54 | 54 | render :action => "list", :layout => false if request.xhr? |
|
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") |
|
61 | 61 | @project = Project.new(params[:project]) |
|
62 | 62 | if request.get? |
|
63 | 63 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
64 | 64 | else |
|
65 | 65 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
66 | 66 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
67 | 67 | @project.custom_values = @custom_values |
|
68 | 68 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
69 | 69 | @project.repository = Repository.new |
|
70 | 70 | @project.repository.attributes = params[:repository] |
|
71 | 71 | end |
|
72 | 72 | if "1" == params[:wiki_enabled] |
|
73 | 73 | @project.wiki = Wiki.new |
|
74 | 74 | @project.wiki.attributes = params[:wiki] |
|
75 | 75 | end |
|
76 | 76 | if @project.save |
|
77 | 77 | flash[:notice] = l(:notice_successful_create) |
|
78 | 78 | redirect_to :controller => 'admin', :action => 'projects' |
|
79 | 79 | end |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | # Show @project |
|
84 | 84 | def show |
|
85 | 85 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
86 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') | |
|
86 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} | |
|
87 | 87 | @subprojects = @project.children if @project.children.size > 0 |
|
88 | 88 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
89 | 89 | @trackers = Tracker.find(:all, :order => 'position') |
|
90 | 90 | @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]) |
|
91 | 91 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def settings |
|
95 | 95 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
96 | 96 | @custom_fields = IssueCustomField.find(:all) |
|
97 | 97 | @issue_category ||= IssueCategory.new |
|
98 | 98 | @member ||= @project.members.new |
|
99 | 99 | @roles = Role.find(:all, :order => 'position') |
|
100 | 100 | @users = User.find_active(:all) - @project.users |
|
101 | 101 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | # Edit @project |
|
105 | 105 | def edit |
|
106 | 106 | if request.post? |
|
107 | 107 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
108 | 108 | if params[:custom_fields] |
|
109 | 109 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
110 | 110 | @project.custom_values = @custom_values |
|
111 | 111 | end |
|
112 | 112 | if params[:repository_enabled] |
|
113 | 113 | case params[:repository_enabled] |
|
114 | 114 | when "0" |
|
115 | 115 | @project.repository = nil |
|
116 | 116 | when "1" |
|
117 | 117 | @project.repository ||= Repository.new |
|
118 | 118 | @project.repository.update_attributes params[:repository] |
|
119 | 119 | end |
|
120 | 120 | end |
|
121 | 121 | if params[:wiki_enabled] |
|
122 | 122 | case params[:wiki_enabled] |
|
123 | 123 | when "0" |
|
124 | 124 | @project.wiki.destroy if @project.wiki |
|
125 | 125 | when "1" |
|
126 | 126 | @project.wiki ||= Wiki.new |
|
127 | 127 | @project.wiki.update_attributes params[:wiki] |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | @project.attributes = params[:project] |
|
131 | 131 | if @project.save |
|
132 | 132 | flash[:notice] = l(:notice_successful_update) |
|
133 | 133 | redirect_to :action => 'settings', :id => @project |
|
134 | 134 | else |
|
135 | 135 | settings |
|
136 | 136 | render :action => 'settings' |
|
137 | 137 | end |
|
138 | 138 | end |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | # Delete @project |
|
142 | 142 | def destroy |
|
143 | 143 | if request.post? and params[:confirm] |
|
144 | 144 | @project.destroy |
|
145 | 145 | redirect_to :controller => 'admin', :action => 'projects' |
|
146 | 146 | end |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | # Add a new issue category to @project |
|
150 | 150 | def add_issue_category |
|
151 | 151 | if request.post? |
|
152 | 152 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
153 | 153 | if @issue_category.save |
|
154 | 154 | flash[:notice] = l(:notice_successful_create) |
|
155 | 155 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
156 | 156 | else |
|
157 | 157 | settings |
|
158 | 158 | render :action => 'settings' |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | end |
|
162 | 162 | |
|
163 | 163 | # Add a new version to @project |
|
164 | 164 | def add_version |
|
165 | 165 | @version = @project.versions.build(params[:version]) |
|
166 | 166 | if request.post? and @version.save |
|
167 | 167 | flash[:notice] = l(:notice_successful_create) |
|
168 | 168 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | # Add a new member to @project |
|
173 | 173 | def add_member |
|
174 | 174 | @member = @project.members.build(params[:member]) |
|
175 | 175 | if request.post? |
|
176 | 176 | if @member.save |
|
177 | 177 | flash[:notice] = l(:notice_successful_create) |
|
178 | 178 | redirect_to :action => 'settings', :tab => 'members', :id => @project |
|
179 | 179 | else |
|
180 | 180 | settings |
|
181 | 181 | render :action => 'settings' |
|
182 | 182 | end |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | |
|
186 | 186 | # Show members list of @project |
|
187 | 187 | def list_members |
|
188 | 188 | @members = @project.members.find(:all) |
|
189 | 189 | end |
|
190 | 190 | |
|
191 | 191 | # Add a new document to @project |
|
192 | 192 | def add_document |
|
193 | 193 | @categories = Enumeration::get_values('DCAT') |
|
194 | 194 | @document = @project.documents.build(params[:document]) |
|
195 | 195 | if request.post? and @document.save |
|
196 | 196 | # Save the attachments |
|
197 | 197 | params[:attachments].each { |a| |
|
198 | 198 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
199 | 199 | } if params[:attachments] and params[:attachments].is_a? Array |
|
200 | 200 | flash[:notice] = l(:notice_successful_create) |
|
201 | 201 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
202 | 202 | redirect_to :action => 'list_documents', :id => @project |
|
203 | 203 | end |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | # Show documents list of @project |
|
207 | 207 | def list_documents |
|
208 | 208 | @documents = @project.documents.find :all, :include => :category |
|
209 | 209 | end |
|
210 | 210 | |
|
211 | 211 | # Add a new issue to @project |
|
212 | 212 | def add_issue |
|
213 | 213 | @tracker = Tracker.find(params[:tracker_id]) |
|
214 | 214 | @priorities = Enumeration::get_values('IPRI') |
|
215 | 215 | |
|
216 | 216 | default_status = IssueStatus.default |
|
217 | 217 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
218 | 218 | @issue.status = default_status |
|
219 | 219 | @allowed_statuses = default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user |
|
220 | 220 | if request.get? |
|
221 | 221 | @issue.start_date = Date.today |
|
222 | 222 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
223 | 223 | else |
|
224 | 224 | @issue.attributes = params[:issue] |
|
225 | 225 | |
|
226 | 226 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
227 | 227 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
228 | 228 | |
|
229 | 229 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
230 | 230 | # Multiple file upload |
|
231 | 231 | @attachments = [] |
|
232 | 232 | params[:attachments].each { |a| |
|
233 | 233 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
234 | 234 | } if params[:attachments] and params[:attachments].is_a? Array |
|
235 | 235 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
236 | 236 | @issue.custom_values = @custom_values |
|
237 | 237 | if @issue.save |
|
238 | 238 | @attachments.each(&:save) |
|
239 | 239 | flash[:notice] = l(:notice_successful_create) |
|
240 | 240 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
241 | 241 | redirect_to :action => 'list_issues', :id => @project |
|
242 | 242 | end |
|
243 | 243 | end |
|
244 | 244 | end |
|
245 | 245 | |
|
246 | 246 | # Show filtered/sorted issues list of @project |
|
247 | 247 | def list_issues |
|
248 | 248 | sort_init "#{Issue.table_name}.id", "desc" |
|
249 | 249 | sort_update |
|
250 | 250 | |
|
251 | 251 | retrieve_query |
|
252 | 252 | |
|
253 | 253 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
254 | 254 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
255 | 255 | @results_per_page = params[:per_page].to_i |
|
256 | 256 | session[:results_per_page] = @results_per_page |
|
257 | 257 | else |
|
258 | 258 | @results_per_page = session[:results_per_page] || 25 |
|
259 | 259 | end |
|
260 | 260 | |
|
261 | 261 | if @query.valid? |
|
262 | 262 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
263 | 263 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
264 | 264 | @issues = Issue.find :all, :order => sort_clause, |
|
265 | 265 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], |
|
266 | 266 | :conditions => @query.statement, |
|
267 | 267 | :limit => @issue_pages.items_per_page, |
|
268 | 268 | :offset => @issue_pages.current.offset |
|
269 | 269 | end |
|
270 | 270 | @trackers = Tracker.find :all, :order => 'position' |
|
271 | 271 | render :layout => false if request.xhr? |
|
272 | 272 | end |
|
273 | 273 | |
|
274 | 274 | # Export filtered/sorted issues list to CSV |
|
275 | 275 | def export_issues_csv |
|
276 | 276 | sort_init "#{Issue.table_name}.id", "desc" |
|
277 | 277 | sort_update |
|
278 | 278 | |
|
279 | 279 | retrieve_query |
|
280 | 280 | render :action => 'list_issues' and return unless @query.valid? |
|
281 | 281 | |
|
282 | 282 | @issues = Issue.find :all, :order => sort_clause, |
|
283 | 283 | :include => [ :assigned_to, :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], |
|
284 | 284 | :conditions => @query.statement, |
|
285 | 285 | :limit => Setting.issues_export_limit |
|
286 | 286 | |
|
287 | 287 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
288 | 288 | export = StringIO.new |
|
289 | 289 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
290 | 290 | # csv header fields |
|
291 | 291 | headers = [ "#", l(:field_status), |
|
292 | 292 | l(:field_tracker), |
|
293 | 293 | l(:field_priority), |
|
294 | 294 | l(:field_subject), |
|
295 | 295 | l(:field_assigned_to), |
|
296 | 296 | l(:field_author), |
|
297 | 297 | l(:field_start_date), |
|
298 | 298 | l(:field_due_date), |
|
299 | 299 | l(:field_done_ratio), |
|
300 | 300 | l(:field_created_on), |
|
301 | 301 | l(:field_updated_on) |
|
302 | 302 | ] |
|
303 | 303 | for custom_field in @project.all_custom_fields |
|
304 | 304 | headers << custom_field.name |
|
305 | 305 | end |
|
306 | 306 | csv << headers.collect {|c| ic.iconv(c) } |
|
307 | 307 | # csv lines |
|
308 | 308 | @issues.each do |issue| |
|
309 | 309 | fields = [issue.id, issue.status.name, |
|
310 | 310 | issue.tracker.name, |
|
311 | 311 | issue.priority.name, |
|
312 | 312 | issue.subject, |
|
313 | 313 | (issue.assigned_to ? issue.assigned_to.name : ""), |
|
314 | 314 | issue.author.name, |
|
315 | 315 | issue.start_date ? l_date(issue.start_date) : nil, |
|
316 | 316 | issue.due_date ? l_date(issue.due_date) : nil, |
|
317 | 317 | issue.done_ratio, |
|
318 | 318 | l_datetime(issue.created_on), |
|
319 | 319 | l_datetime(issue.updated_on) |
|
320 | 320 | ] |
|
321 | 321 | for custom_field in @project.all_custom_fields |
|
322 | 322 | fields << (show_value issue.custom_value_for(custom_field)) |
|
323 | 323 | end |
|
324 | 324 | csv << fields.collect {|c| ic.iconv(c.to_s) } |
|
325 | 325 | end |
|
326 | 326 | end |
|
327 | 327 | export.rewind |
|
328 | 328 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
329 | 329 | end |
|
330 | 330 | |
|
331 | 331 | # Export filtered/sorted issues to PDF |
|
332 | 332 | def export_issues_pdf |
|
333 | 333 | sort_init "#{Issue.table_name}.id", "desc" |
|
334 | 334 | sort_update |
|
335 | 335 | |
|
336 | 336 | retrieve_query |
|
337 | 337 | render :action => 'list_issues' and return unless @query.valid? |
|
338 | 338 | |
|
339 | 339 | @issues = Issue.find :all, :order => sort_clause, |
|
340 | 340 | :include => [ :author, :status, :tracker, :priority ], |
|
341 | 341 | :conditions => @query.statement, |
|
342 | 342 | :limit => Setting.issues_export_limit |
|
343 | 343 | |
|
344 | 344 | @options_for_rfpdf ||= {} |
|
345 | 345 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
346 | 346 | render :layout => false |
|
347 | 347 | end |
|
348 | 348 | |
|
349 | 349 | def move_issues |
|
350 | 350 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
351 | 351 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
352 | 352 | @projects = [] |
|
353 | 353 | # find projects to which the user is allowed to move the issue |
|
354 | 354 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} |
|
355 | 355 | # issue can be moved to any tracker |
|
356 | 356 | @trackers = Tracker.find(:all) |
|
357 | 357 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
358 | 358 | new_project = Project.find(params[:new_project_id]) |
|
359 | 359 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
360 | 360 | @issues.each { |i| |
|
361 | 361 | # project dependent properties |
|
362 | 362 | unless i.project_id == new_project.id |
|
363 | 363 | i.category = nil |
|
364 | 364 | i.fixed_version = nil |
|
365 | 365 | end |
|
366 | 366 | # move the issue |
|
367 | 367 | i.project = new_project |
|
368 | 368 | i.tracker = new_tracker |
|
369 | 369 | i.save |
|
370 | 370 | } |
|
371 | 371 | flash[:notice] = l(:notice_successful_update) |
|
372 | 372 | redirect_to :action => 'list_issues', :id => @project |
|
373 | 373 | end |
|
374 | 374 | end |
|
375 | 375 | |
|
376 | 376 | def add_query |
|
377 | 377 | @query = Query.new(params[:query]) |
|
378 | 378 | @query.project = @project |
|
379 | 379 | @query.user = logged_in_user |
|
380 | 380 | |
|
381 | 381 | params[:fields].each do |field| |
|
382 | 382 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
383 | 383 | end if params[:fields] |
|
384 | 384 | |
|
385 | 385 | if request.post? and @query.save |
|
386 | 386 | flash[:notice] = l(:notice_successful_create) |
|
387 | 387 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project |
|
388 | 388 | end |
|
389 | 389 | render :layout => false if request.xhr? |
|
390 | 390 | end |
|
391 | 391 | |
|
392 | 392 | # Add a news to @project |
|
393 | 393 | def add_news |
|
394 | 394 | @news = News.new(:project => @project) |
|
395 | 395 | if request.post? |
|
396 | 396 | @news.attributes = params[:news] |
|
397 | 397 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
398 | 398 | if @news.save |
|
399 | 399 | flash[:notice] = l(:notice_successful_create) |
|
400 | 400 | redirect_to :action => 'list_news', :id => @project |
|
401 | 401 | end |
|
402 | 402 | end |
|
403 | 403 | end |
|
404 | 404 | |
|
405 | 405 | # Show news list of @project |
|
406 | 406 | def list_news |
|
407 | 407 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
408 | 408 | render :action => "list_news", :layout => false if request.xhr? |
|
409 | 409 | end |
|
410 | 410 | |
|
411 | 411 | def add_file |
|
412 | 412 | if request.post? |
|
413 | 413 | @version = @project.versions.find_by_id(params[:version_id]) |
|
414 | 414 | # Save the attachments |
|
415 | 415 | @attachments = [] |
|
416 | 416 | params[:attachments].each { |file| |
|
417 | 417 | next unless file.size > 0 |
|
418 | 418 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
419 | 419 | @attachments << a unless a.new_record? |
|
420 | 420 | } if params[:attachments] and params[:attachments].is_a? Array |
|
421 | 421 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
422 | 422 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
423 | 423 | end |
|
424 | 424 | @versions = @project.versions |
|
425 | 425 | end |
|
426 | 426 | |
|
427 | 427 | def list_files |
|
428 | 428 | @versions = @project.versions |
|
429 | 429 | end |
|
430 | 430 | |
|
431 | 431 | # Show changelog for @project |
|
432 | 432 | def changelog |
|
433 | 433 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
434 | 434 | retrieve_selected_tracker_ids(@trackers) |
|
435 | 435 | |
|
436 | 436 | @fixed_issues = @project.issues.find(:all, |
|
437 | 437 | :include => [ :fixed_version, :status, :tracker ], |
|
438 | 438 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], |
|
439 | 439 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" |
|
440 | 440 | ) unless @selected_tracker_ids.empty? |
|
441 | 441 | @fixed_issues ||= [] |
|
442 | 442 | end |
|
443 | 443 | |
|
444 | 444 | def roadmap |
|
445 | 445 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
446 | 446 | retrieve_selected_tracker_ids(@trackers) |
|
447 | 447 | |
|
448 | 448 | @versions = @project.versions.find(:all, |
|
449 | 449 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], |
|
450 | 450 | :order => "#{Version.table_name}.effective_date ASC" |
|
451 | 451 | ) |
|
452 | 452 | end |
|
453 | 453 | |
|
454 | 454 | def activity |
|
455 | 455 | if params[:year] and params[:year].to_i > 1900 |
|
456 | 456 | @year = params[:year].to_i |
|
457 | 457 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
458 | 458 | @month = params[:month].to_i |
|
459 | 459 | end |
|
460 | 460 | end |
|
461 | 461 | @year ||= Date.today.year |
|
462 | 462 | @month ||= Date.today.month |
|
463 | 463 | |
|
464 | 464 | @date_from = Date.civil(@year, @month, 1) |
|
465 | 465 | @date_to = (@date_from >> 1)-1 |
|
466 | 466 | |
|
467 | 467 | @events_by_day = {} |
|
468 | 468 | |
|
469 | 469 | unless params[:show_issues] == "0" |
|
470 | 470 | @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
471 | 471 | @events_by_day[i.created_on.to_date] ||= [] |
|
472 | 472 | @events_by_day[i.created_on.to_date] << i |
|
473 | 473 | } |
|
474 | 474 | @show_issues = 1 |
|
475 | 475 | end |
|
476 | 476 | |
|
477 | 477 | unless params[:show_news] == "0" |
|
478 | 478 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
479 | 479 | @events_by_day[i.created_on.to_date] ||= [] |
|
480 | 480 | @events_by_day[i.created_on.to_date] << i |
|
481 | 481 | } |
|
482 | 482 | @show_news = 1 |
|
483 | 483 | end |
|
484 | 484 | |
|
485 | 485 | unless params[:show_files] == "0" |
|
486 | 486 | 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 ).each { |i| |
|
487 | 487 | @events_by_day[i.created_on.to_date] ||= [] |
|
488 | 488 | @events_by_day[i.created_on.to_date] << i |
|
489 | 489 | } |
|
490 | 490 | @show_files = 1 |
|
491 | 491 | end |
|
492 | 492 | |
|
493 | 493 | unless params[:show_documents] == "0" |
|
494 | 494 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
495 | 495 | @events_by_day[i.created_on.to_date] ||= [] |
|
496 | 496 | @events_by_day[i.created_on.to_date] << i |
|
497 | 497 | } |
|
498 | 498 | 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 ).each { |i| |
|
499 | 499 | @events_by_day[i.created_on.to_date] ||= [] |
|
500 | 500 | @events_by_day[i.created_on.to_date] << i |
|
501 | 501 | } |
|
502 | 502 | @show_documents = 1 |
|
503 | 503 | end |
|
504 | 504 | |
|
505 | 505 | unless params[:show_wiki_edits] == "0" |
|
506 | 506 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + |
|
507 | 507 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
508 | 508 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
509 | 509 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
510 | 510 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
511 | 511 | @project.id, @date_from, @date_to] |
|
512 | 512 | |
|
513 | 513 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
514 | 514 | # We provide this alias so all events can be treated in the same manner |
|
515 | 515 | def i.created_on |
|
516 | 516 | self.updated_on |
|
517 | 517 | end |
|
518 | 518 | |
|
519 | 519 | @events_by_day[i.created_on.to_date] ||= [] |
|
520 | 520 | @events_by_day[i.created_on.to_date] << i |
|
521 | 521 | } |
|
522 | 522 | @show_wiki_edits = 1 |
|
523 | 523 | end |
|
524 | 524 | |
|
525 | 525 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
526 | 526 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
527 | 527 | def i.created_on |
|
528 | 528 | self.committed_on |
|
529 | 529 | end |
|
530 | 530 | @events_by_day[i.created_on.to_date] ||= [] |
|
531 | 531 | @events_by_day[i.created_on.to_date] << i |
|
532 | 532 | } |
|
533 | 533 | @show_changesets = 1 |
|
534 | 534 | end |
|
535 | 535 | |
|
536 | 536 | render :layout => false if request.xhr? |
|
537 | 537 | end |
|
538 | 538 | |
|
539 | 539 | def calendar |
|
540 | 540 | @trackers = Tracker.find(:all, :order => 'position') |
|
541 | 541 | retrieve_selected_tracker_ids(@trackers) |
|
542 | 542 | |
|
543 | 543 | if params[:year] and params[:year].to_i > 1900 |
|
544 | 544 | @year = params[:year].to_i |
|
545 | 545 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
546 | 546 | @month = params[:month].to_i |
|
547 | 547 | end |
|
548 | 548 | end |
|
549 | 549 | @year ||= Date.today.year |
|
550 | 550 | @month ||= Date.today.month |
|
551 | 551 | |
|
552 | 552 | @date_from = Date.civil(@year, @month, 1) |
|
553 | 553 | @date_to = (@date_from >> 1)-1 |
|
554 | 554 | # start on monday |
|
555 | 555 | @date_from = @date_from - (@date_from.cwday-1) |
|
556 | 556 | # finish on sunday |
|
557 | 557 | @date_to = @date_to + (7-@date_to.cwday) |
|
558 | 558 | |
|
559 | 559 | @events = [] |
|
560 | 560 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
561 | 561 | @events += Issue.find(:all, |
|
562 | 562 | :include => [:tracker, :status, :assigned_to, :priority], |
|
563 | 563 | :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to] |
|
564 | 564 | ) unless @selected_tracker_ids.empty? |
|
565 | 565 | end |
|
566 | 566 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
567 | 567 | |
|
568 | 568 | @ending_events_by_days = @events.group_by {|event| event.due_date} |
|
569 | 569 | @starting_events_by_days = @events.group_by {|event| event.start_date} |
|
570 | 570 | |
|
571 | 571 | render :layout => false if request.xhr? |
|
572 | 572 | end |
|
573 | 573 | |
|
574 | 574 | def gantt |
|
575 | 575 | @trackers = Tracker.find(:all, :order => 'position') |
|
576 | 576 | retrieve_selected_tracker_ids(@trackers) |
|
577 | 577 | |
|
578 | 578 | if params[:year] and params[:year].to_i >0 |
|
579 | 579 | @year_from = params[:year].to_i |
|
580 | 580 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
581 | 581 | @month_from = params[:month].to_i |
|
582 | 582 | else |
|
583 | 583 | @month_from = 1 |
|
584 | 584 | end |
|
585 | 585 | else |
|
586 | 586 | @month_from ||= (Date.today << 1).month |
|
587 | 587 | @year_from ||= (Date.today << 1).year |
|
588 | 588 | end |
|
589 | 589 | |
|
590 | 590 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
591 | 591 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
592 | 592 | |
|
593 | 593 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
594 | 594 | @date_to = (@date_from >> @months) - 1 |
|
595 | 595 | |
|
596 | 596 | @events = [] |
|
597 | 597 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
598 | 598 | @events += Issue.find(:all, |
|
599 | 599 | :order => "start_date, due_date", |
|
600 | 600 | :include => [:tracker, :status, :assigned_to, :priority], |
|
601 | 601 | :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] |
|
602 | 602 | ) unless @selected_tracker_ids.empty? |
|
603 | 603 | end |
|
604 | 604 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
605 | 605 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
606 | 606 | |
|
607 | 607 | if params[:output]=='pdf' |
|
608 | 608 | @options_for_rfpdf ||= {} |
|
609 | 609 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
610 | 610 | render :template => "projects/gantt.rfpdf", :layout => false |
|
611 | 611 | else |
|
612 | 612 | render :template => "projects/gantt.rhtml" |
|
613 | 613 | end |
|
614 | 614 | end |
|
615 | 615 | |
|
616 | 616 | def search |
|
617 | 617 | @question = params[:q] || "" |
|
618 | 618 | @question.strip! |
|
619 | 619 | @all_words = params[:all_words] || (params[:submit] ? false : true) |
|
620 | 620 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) |
|
621 | 621 | # tokens must be at least 3 character long |
|
622 | 622 | @tokens = @question.split.uniq.select {|w| w.length > 2 } |
|
623 | 623 | if !@tokens.empty? |
|
624 | 624 | # no more than 5 tokens to search for |
|
625 | 625 | @tokens.slice! 5..-1 if @tokens.size > 5 |
|
626 | 626 | # strings used in sql like statement |
|
627 | 627 | like_tokens = @tokens.collect {|w| "%#{w}%"} |
|
628 | 628 | operator = @all_words ? " AND " : " OR " |
|
629 | 629 | limit = 10 |
|
630 | 630 | @results = [] |
|
631 | 631 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' |
|
632 | 632 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' |
|
633 | 633 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' |
|
634 | 634 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') |
|
635 | 635 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') |
|
636 | 636 | @question = @tokens.join(" ") |
|
637 | 637 | else |
|
638 | 638 | @question = "" |
|
639 | 639 | end |
|
640 | 640 | end |
|
641 | 641 | |
|
642 | 642 | def feeds |
|
643 | 643 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
644 | 644 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
645 | 645 | end |
|
646 | 646 | |
|
647 | 647 | private |
|
648 | 648 | # Find project of id params[:id] |
|
649 | 649 | # if not found, redirect to project list |
|
650 | 650 | # Used as a before_filter |
|
651 | 651 | def find_project |
|
652 | 652 | @project = Project.find(params[:id]) |
|
653 | 653 | @html_title = @project.name |
|
654 | 654 | rescue ActiveRecord::RecordNotFound |
|
655 | 655 | render_404 |
|
656 | 656 | end |
|
657 | 657 | |
|
658 | 658 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
659 | 659 | if ids = params[:tracker_ids] |
|
660 | 660 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
661 | 661 | else |
|
662 | 662 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
663 | 663 | end |
|
664 | 664 | end |
|
665 | 665 | |
|
666 | 666 | # Retrieve query from session or build a new query |
|
667 | 667 | def retrieve_query |
|
668 | 668 | if params[:query_id] |
|
669 | 669 | @query = @project.queries.find(params[:query_id]) |
|
670 | 670 | session[:query] = @query |
|
671 | 671 | else |
|
672 | 672 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
673 | 673 | # Give it a name, required to be valid |
|
674 | 674 | @query = Query.new(:name => "_") |
|
675 | 675 | @query.project = @project |
|
676 | 676 | if params[:fields] and params[:fields].is_a? Array |
|
677 | 677 | params[:fields].each do |field| |
|
678 | 678 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
679 | 679 | end |
|
680 | 680 | else |
|
681 | 681 | @query.available_filters.keys.each do |field| |
|
682 | 682 | @query.add_short_filter(field, params[field]) if params[field] |
|
683 | 683 | end |
|
684 | 684 | end |
|
685 | 685 | session[:query] = @query |
|
686 | 686 | else |
|
687 | 687 | @query = session[:query] |
|
688 | 688 | end |
|
689 | 689 | end |
|
690 | 690 | end |
|
691 | 691 | end |
@@ -1,115 +1,115 | |||
|
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 RolesController < ApplicationController |
|
19 | 19 | layout 'base' |
|
20 | 20 | before_filter :require_admin |
|
21 | 21 | |
|
22 | 22 | verify :method => :post, :only => [ :destroy, :move ], |
|
23 | 23 | :redirect_to => { :action => :list } |
|
24 | 24 | |
|
25 | 25 | def index |
|
26 | 26 | list |
|
27 | 27 | render :action => 'list' unless request.xhr? |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def list |
|
31 |
@role_pages, @roles = paginate :roles, :per_page => |
|
|
31 | @role_pages, @roles = paginate :roles, :per_page => 25, :order => "position" | |
|
32 | 32 | render :action => "list", :layout => false if request.xhr? |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def new |
|
36 | 36 | @role = Role.new(params[:role]) |
|
37 | 37 | if request.post? |
|
38 | 38 | @role.permissions = Permission.find(params[:permission_ids]) if params[:permission_ids] |
|
39 | 39 | if @role.save |
|
40 | 40 | flash[:notice] = l(:notice_successful_create) |
|
41 | 41 | redirect_to :action => 'list' |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC') |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def edit |
|
48 | 48 | @role = Role.find(params[:id]) |
|
49 | 49 | if request.post? and @role.update_attributes(params[:role]) |
|
50 | 50 | @role.permissions = Permission.find(params[:permission_ids] || []) |
|
51 | 51 | Permission.allowed_to_role_expired |
|
52 | 52 | flash[:notice] = l(:notice_successful_update) |
|
53 | 53 | redirect_to :action => 'list' |
|
54 | 54 | end |
|
55 | 55 | @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC') |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def destroy |
|
59 | 59 | @role = Role.find(params[:id]) |
|
60 | 60 | unless @role.members.empty? |
|
61 | 61 | flash[:notice] = 'Some members have this role. Can\'t delete it.' |
|
62 | 62 | else |
|
63 | 63 | @role.destroy |
|
64 | 64 | end |
|
65 | 65 | redirect_to :action => 'list' |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def move |
|
69 | 69 | @role = Role.find(params[:id]) |
|
70 | 70 | case params[:position] |
|
71 | 71 | when 'highest' |
|
72 | 72 | @role.move_to_top |
|
73 | 73 | when 'higher' |
|
74 | 74 | @role.move_higher |
|
75 | 75 | when 'lower' |
|
76 | 76 | @role.move_lower |
|
77 | 77 | when 'lowest' |
|
78 | 78 | @role.move_to_bottom |
|
79 | 79 | end if params[:position] |
|
80 | 80 | redirect_to :action => 'list' |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def workflow |
|
84 | 84 | @role = Role.find_by_id(params[:role_id]) |
|
85 | 85 | @tracker = Tracker.find_by_id(params[:tracker_id]) |
|
86 | 86 | |
|
87 | 87 | if request.post? |
|
88 | 88 | Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
89 | 89 | (params[:issue_status] || []).each { |old, news| |
|
90 | 90 | news.each { |new| |
|
91 | 91 | @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new) |
|
92 | 92 | } |
|
93 | 93 | } |
|
94 | 94 | if @role.save |
|
95 | 95 | flash[:notice] = l(:notice_successful_update) |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | @roles = Role.find(:all, :order => 'position') |
|
99 | 99 | @trackers = Tracker.find(:all, :order => 'position') |
|
100 | 100 | @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position') |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def report |
|
104 |
@roles = Role.find : |
|
|
104 | @roles = Role.find(:all, :order => 'position') | |
|
105 | 105 | @permissions = Permission.find :all, :conditions => ["is_public=?", false], :order => 'sort' |
|
106 | 106 | if request.post? |
|
107 | 107 | @roles.each do |role| |
|
108 | 108 | role.permissions = Permission.find(params[:permission_ids] ? (params[:permission_ids][role.id.to_s] || []) : [] ) |
|
109 | 109 | end |
|
110 | 110 | Permission.allowed_to_role_expired |
|
111 | 111 | flash[:notice] = l(:notice_successful_update) |
|
112 | 112 | redirect_to :action => 'list' |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | end |
@@ -1,33 +1,37 | |||
|
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 Role < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | has_and_belongs_to_many :permissions |
|
21 | 21 | has_many :workflows, :dependent => :delete_all |
|
22 | 22 | has_many :members |
|
23 | 23 | acts_as_list |
|
24 | 24 | |
|
25 | 25 | validates_presence_of :name |
|
26 | 26 | validates_uniqueness_of :name |
|
27 | 27 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
28 | 28 | |
|
29 | def <=>(role) | |
|
30 | position <=> role.position | |
|
31 | end | |
|
32 | ||
|
29 | 33 | private |
|
30 | 34 | def check_integrity |
|
31 | 35 | raise "Can't delete role" if Member.find(:first, :conditions =>["role_id=?", self.id]) |
|
32 | 36 | end |
|
33 | 37 | end |
@@ -1,150 +1,154 | |||
|
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 "digest/sha1" |
|
19 | 19 | |
|
20 | 20 | class User < ActiveRecord::Base |
|
21 | 21 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => :delete_all |
|
22 | 22 | has_many :projects, :through => :memberships |
|
23 | 23 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
24 | 24 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' |
|
25 | 25 | has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" |
|
26 | 26 | belongs_to :auth_source |
|
27 | 27 | |
|
28 | 28 | attr_accessor :password, :password_confirmation |
|
29 | 29 | attr_accessor :last_before_login_on |
|
30 | 30 | # Prevents unauthorized assignments |
|
31 | 31 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
32 | 32 | |
|
33 | 33 | validates_presence_of :login, :firstname, :lastname, :mail |
|
34 | 34 | validates_uniqueness_of :login, :mail |
|
35 | 35 | # Login must contain lettres, numbers, underscores only |
|
36 | 36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i |
|
37 | 37 | validates_length_of :login, :maximum => 30 |
|
38 | 38 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
39 | 39 | validates_length_of :firstname, :lastname, :maximum => 30 |
|
40 | 40 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i |
|
41 | 41 | validates_length_of :mail, :maximum => 60 |
|
42 | 42 | # Password length between 4 and 12 |
|
43 | 43 | validates_length_of :password, :in => 4..12, :allow_nil => true |
|
44 | 44 | validates_confirmation_of :password, :allow_nil => true |
|
45 | 45 | validates_associated :custom_values, :on => :update |
|
46 | 46 | |
|
47 | 47 | # Account statuses |
|
48 | 48 | STATUS_ACTIVE = 1 |
|
49 | 49 | STATUS_REGISTERED = 2 |
|
50 | 50 | STATUS_LOCKED = 3 |
|
51 | 51 | |
|
52 | 52 | def before_save |
|
53 | 53 | # update hashed_password if password was set |
|
54 | 54 | self.hashed_password = User.hash_password(self.password) if self.password |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def self.active |
|
58 | 58 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do |
|
59 | 59 | yield |
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def self.find_active(*args) |
|
64 | 64 | active do |
|
65 | 65 | find(*args) |
|
66 | 66 | end |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | # Returns the user that matches provided login and password, or nil |
|
70 | 70 | def self.try_to_login(login, password) |
|
71 | 71 | user = find(:first, :conditions => ["login=?", login]) |
|
72 | 72 | if user |
|
73 | 73 | # user is already in local database |
|
74 | 74 | return nil if !user.active? |
|
75 | 75 | if user.auth_source |
|
76 | 76 | # user has an external authentication method |
|
77 | 77 | return nil unless user.auth_source.authenticate(login, password) |
|
78 | 78 | else |
|
79 | 79 | # authentication with local password |
|
80 | 80 | return nil unless User.hash_password(password) == user.hashed_password |
|
81 | 81 | end |
|
82 | 82 | else |
|
83 | 83 | # user is not yet registered, try to authenticate with available sources |
|
84 | 84 | attrs = AuthSource.authenticate(login, password) |
|
85 | 85 | if attrs |
|
86 | 86 | onthefly = new(*attrs) |
|
87 | 87 | onthefly.login = login |
|
88 | 88 | onthefly.language = Setting.default_language |
|
89 | 89 | if onthefly.save |
|
90 | 90 | user = find(:first, :conditions => ["login=?", login]) |
|
91 | 91 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
92 | 92 | end |
|
93 | 93 | end |
|
94 | 94 | end |
|
95 | 95 | user.update_attribute(:last_login_on, Time.now) if user |
|
96 | 96 | user |
|
97 | 97 | |
|
98 | 98 | rescue => text |
|
99 | 99 | raise text |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | # Return user's full name for display |
|
103 | 103 | def display_name |
|
104 | 104 | firstname + " " + lastname |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def name |
|
108 | 108 | display_name |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def active? |
|
112 | 112 | self.status == STATUS_ACTIVE |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def registered? |
|
116 | 116 | self.status == STATUS_REGISTERED |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def locked? |
|
120 | 120 | self.status == STATUS_LOCKED |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def check_password?(clear_password) |
|
124 | 124 | User.hash_password(clear_password) == self.hashed_password |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def role_for_project(project) |
|
128 | 128 | member = memberships.detect {|m| m.project_id == project.id} |
|
129 | 129 | member ? member.role : nil |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def pref |
|
133 | 133 | self.preference ||= UserPreference.new(:user => self) |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | def get_or_create_rss_key |
|
137 | 137 | self.rss_key || Token.create(:user => self, :action => 'feeds') |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def self.find_by_rss_key(key) |
|
141 | 141 | token = Token.find_by_value(key) |
|
142 | 142 | token && token.user.active? ? token.user : nil |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | def <=>(user) | |
|
146 | lastname <=> user.lastname | |
|
147 | end | |
|
148 | ||
|
145 | 149 | private |
|
146 | 150 | # Return password digest |
|
147 | 151 | def self.hash_password(clear_password) |
|
148 | 152 | Digest::SHA1.hexdigest(clear_password || "") |
|
149 | 153 | end |
|
150 | 154 | end |
@@ -1,113 +1,113 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= l(:label_export_to) %><%= link_to 'PDF', {:action => 'export_pdf', :id => @issue}, :class => 'icon icon-pdf' %> |
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <h2><%= @issue.tracker.name %> #<%= @issue.id %> - <%=h @issue.subject %></h2> |
|
6 | 6 | |
|
7 | 7 | <div class="box"> |
|
8 | 8 | <table width="100%"> |
|
9 | 9 | <tr> |
|
10 | 10 | <td style="width:15%"><b><%=l(:field_status)%> :</b></td><td style="width:35%"><%= @issue.status.name %></td> |
|
11 | 11 | <td style="width:15%"><b><%=l(:field_priority)%> :</b></td><td style="width:35%"><%= @issue.priority.name %></td> |
|
12 | 12 | </tr> |
|
13 | 13 | <tr> |
|
14 |
<td><b><%=l(:field_assigned_to)%> :</b></td><td><%= @issue.assigned_to ? @issue.assigned_to |
|
|
14 | <td><b><%=l(:field_assigned_to)%> :</b></td><td><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></td> | |
|
15 | 15 | <td><b><%=l(:field_category)%> :</b></td><td><%=h @issue.category ? @issue.category.name : "-" %></td> |
|
16 | 16 | </tr> |
|
17 | 17 | <tr> |
|
18 | 18 | <td><b><%=l(:field_author)%> :</b></td><td><%= link_to_user @issue.author %></td> |
|
19 | 19 | <td><b><%=l(:field_start_date)%> :</b></td><td><%= format_date(@issue.start_date) %></td> |
|
20 | 20 | </tr> |
|
21 | 21 | <tr> |
|
22 | 22 | <td><b><%=l(:field_created_on)%> :</b></td><td><%= format_date(@issue.created_on) %></td> |
|
23 | 23 | <td><b><%=l(:field_due_date)%> :</b></td><td><%= format_date(@issue.due_date) %></td> |
|
24 | 24 | </tr> |
|
25 | 25 | <tr> |
|
26 | 26 | <td><b><%=l(:field_updated_on)%> :</b></td><td><%= format_date(@issue.updated_on) %></td> |
|
27 | 27 | <td><b><%=l(:field_done_ratio)%> :</b></td><td><%= @issue.done_ratio %> %</td> |
|
28 | 28 | </tr> |
|
29 | 29 | <tr> |
|
30 | 30 | <td><b><%=l(:field_fixed_version)%> :</b></td><td><%= @issue.fixed_version ? @issue.fixed_version.name : "-" %></td> |
|
31 | 31 | <td><b><%=l(:label_spent_time)%> :</b></td> |
|
32 | 32 | <td><%= @issue.spent_hours > 0 ? (link_to lwr(:label_f_hour, @issue.spent_hours), {:controller => 'timelog', :action => 'details', :issue_id => @issue}, :class => 'icon icon-time') : "-" %></td> |
|
33 | 33 | </tr> |
|
34 | 34 | <tr> |
|
35 | 35 | <% n = 0 |
|
36 | 36 | for custom_value in @custom_values %> |
|
37 | 37 | <td><b><%= custom_value.custom_field.name %> :</b></td><td><%= h(show_value(custom_value)) %></td> |
|
38 | 38 | <% n = n + 1 |
|
39 | 39 | if (n > 1) |
|
40 | 40 | n = 0 %> |
|
41 | 41 | </tr><tr> |
|
42 | 42 | <%end |
|
43 | 43 | end %> |
|
44 | 44 | </tr> |
|
45 | 45 | </table> |
|
46 | 46 | <hr /> |
|
47 | 47 | <br /> |
|
48 | 48 | |
|
49 | 49 | <b><%=l(:field_description)%> :</b><br /><br /> |
|
50 | 50 | <%= textilizable @issue.description %> |
|
51 | 51 | <br /> |
|
52 | 52 | |
|
53 | 53 | <div class="contextual"> |
|
54 | 54 | <%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit' %> |
|
55 | 55 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %> |
|
56 | 56 | <%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %> |
|
57 | 57 | <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> |
|
58 | 58 | </div> |
|
59 | 59 | |
|
60 | 60 | <% if authorize_for('issues', 'change_status') and @status_options and !@status_options.empty? %> |
|
61 | 61 | <% form_tag ({:controller => 'issues', :action => 'change_status', :id => @issue}) do %> |
|
62 | 62 | <%=l(:label_change_status)%> : |
|
63 | 63 | <select name="new_status_id"> |
|
64 | 64 | <%= options_from_collection_for_select @status_options, "id", "name" %> |
|
65 | 65 | </select> |
|
66 | 66 | <%= submit_tag l(:button_change) %> |
|
67 | 67 | <% end %> |
|
68 | 68 | <% end %> |
|
69 | 69 | |
|
70 | 70 | </div> |
|
71 | 71 | |
|
72 | 72 | <div id="history" class="box"> |
|
73 | 73 | <h3><%=l(:label_history)%> |
|
74 | 74 | <% if @journals_count > @journals.length %>(<%= l(:label_last_changes, @journals.length) %>)<% end %></h3> |
|
75 | 75 | <%= render :partial => 'history', :locals => { :journals => @journals } %> |
|
76 | 76 | <% if @journals_count > @journals.length %> |
|
77 | 77 | <p><center><small><%= link_to l(:label_change_view_all), :action => 'history', :id => @issue %></small></center></p> |
|
78 | 78 | <% end %> |
|
79 | 79 | </div> |
|
80 | 80 | |
|
81 | 81 | <div class="box"> |
|
82 | 82 | <h3><%=l(:label_attachment_plural)%></h3> |
|
83 | 83 | <table width="100%"> |
|
84 | 84 | <% for attachment in @issue.attachments %> |
|
85 | 85 | <tr> |
|
86 | 86 | <td><%= link_to attachment.filename, { :action => 'download', :id => @issue, :attachment_id => attachment }, :class => 'icon icon-attachment' %> (<%= number_to_human_size(attachment.filesize) %>)</td> |
|
87 | 87 | <td><%= format_date(attachment.created_on) %></td> |
|
88 | 88 | <td><%= attachment.author.display_name %></td> |
|
89 | 89 | <td><div class="contextual"><%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy_attachment', :id => @issue, :attachment_id => attachment }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></div></td> |
|
90 | 90 | </tr> |
|
91 | 91 | <% end %> |
|
92 | 92 | </table> |
|
93 | 93 | <br /> |
|
94 | 94 | <% if authorize_for('issues', 'add_attachment') %> |
|
95 | 95 | <% form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true, :class => "tabular") do %> |
|
96 | 96 | <p id="attachments_p"><label><%=l(:label_attachment_new)%> |
|
97 | 97 | <%= image_to_function "add.png", "addFileField();return false" %></label> |
|
98 | 98 | <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p> |
|
99 | 99 | <%= submit_tag l(:button_add) %> |
|
100 | 100 | <% end %> |
|
101 | 101 | <% end %> |
|
102 | 102 | </div> |
|
103 | 103 | |
|
104 | 104 | <% if authorize_for('issues', 'add_note') %> |
|
105 | 105 | <div class="box"> |
|
106 | 106 | <h3><%= l(:label_add_note) %></h3> |
|
107 | 107 | <% form_tag ({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular" ) do %> |
|
108 | 108 | <p><label for="notes"><%=l(:field_notes)%></label> |
|
109 | 109 | <%= text_area_tag 'notes', '', :cols => 60, :rows => 10, :class => 'wiki-edit' %></p> |
|
110 | 110 | <%= submit_tag l(:button_add) %> |
|
111 | 111 | <% end %> |
|
112 | 112 | </div> |
|
113 | 113 | <% end %> |
@@ -1,62 +1,60 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to l(:label_feed_plural), {:action => 'feeds', :id => @project}, :class => 'icon icon-feed' %> |
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <h2><%=l(:label_overview)%></h2> |
|
6 | 6 | |
|
7 | 7 | <div class="splitcontentleft"> |
|
8 |
<%= |
|
|
8 | <%= textilizable @project.description %> | |
|
9 | 9 | <ul> |
|
10 | 10 | <% unless @project.homepage.empty? %><li><%=l(:field_homepage)%>: <%= auto_link @project.homepage %></li><% end %> |
|
11 | 11 | <li><%=l(:field_created_on)%>: <%= format_date(@project.created_on) %></li> |
|
12 | 12 | <% unless @project.parent.nil? %> |
|
13 | 13 | <li><%=l(:field_parent)%>: <%= link_to @project.parent.name, :controller => 'projects', :action => 'show', :id => @project.parent %></li> |
|
14 | 14 | <% end %> |
|
15 | 15 | <% for custom_value in @custom_values %> |
|
16 | 16 | <% if !custom_value.value.empty? %> |
|
17 | 17 | <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li> |
|
18 | 18 | <% end %> |
|
19 | 19 | <% end %> |
|
20 | 20 | </ul> |
|
21 | 21 | |
|
22 | 22 | <div class="box"> |
|
23 | 23 | <div class="contextual"> |
|
24 | 24 | <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %> |
|
25 | 25 | </div> |
|
26 | 26 | <h3 class="icon22 icon22-tracker"><%=l(:label_issue_tracking)%></h3> |
|
27 | 27 | <ul> |
|
28 | 28 | <% for tracker in @trackers %> |
|
29 | 29 | <li><%= link_to tracker.name, :controller => 'projects', :action => 'list_issues', :id => @project, |
|
30 | 30 | :set_filter => 1, |
|
31 | 31 | "tracker_id" => tracker.id %>: |
|
32 | 32 | <%= @open_issues_by_tracker[tracker] || 0 %> <%= lwr(:label_open_issues, @open_issues_by_tracker[tracker] || 0) %> |
|
33 | 33 | <%= l(:label_on) %> <%= @total_issues_by_tracker[tracker] || 0 %></li> |
|
34 | 34 | <% end %> |
|
35 | 35 | </ul> |
|
36 | 36 | <p class="textcenter"><small><%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %></small></p> |
|
37 | 37 | </div> |
|
38 | 38 | </div> |
|
39 | 39 | |
|
40 | 40 | <div class="splitcontentright"> |
|
41 | 41 | <div class="box"> |
|
42 | 42 | <h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3> |
|
43 | <% for member in @members %> | |
|
44 | <%= link_to_user member.user %> (<%= member.role.name %>)<br /> | |
|
43 | <% @members_by_role.keys.sort.each do |role| %> | |
|
44 | <%= role.name %>: <%= @members_by_role[role].collect(&:user).sort.collect{|u| link_to_user u}.join(", ") %><br /> | |
|
45 | 45 | <% end %> |
|
46 | 46 | </div> |
|
47 | 47 | |
|
48 | 48 | <% if @subprojects %> |
|
49 | 49 | <div class="box"> |
|
50 | 50 | <h3 class="icon22 icon22-projects"><%=l(:label_subproject_plural)%></h3> |
|
51 | <% for subproject in @subprojects %> | |
|
52 | <%= link_to subproject.name, :action => 'show', :id => subproject %><br /> | |
|
53 | <% end %> | |
|
51 | <%= @subprojects.collect{|p| link_to(p.name, :action => 'show', :id => p)}.join(", ") %> | |
|
54 | 52 | </div> |
|
55 | 53 | <% end %> |
|
56 | 54 | |
|
57 | 55 | <div class="box"> |
|
58 | 56 | <h3><%=l(:label_news_latest)%></h3> |
|
59 | 57 | <%= render :partial => 'news/news', :collection => @news %> |
|
60 | 58 | <p class="textcenter"><small><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></small></p> |
|
61 | 59 | </div> |
|
62 | 60 | </div> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now