@@ -0,0 +1,6 | |||||
|
1 | <h2><%=l(:label_issue_category_new)%></h2> | |||
|
2 | ||||
|
3 | <% labelled_tabular_form_for :category, @category, :url => { :action => 'add_issue_category' } do |f| %> | |||
|
4 | <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> | |||
|
5 | <%= submit_tag l(:button_create) %> | |||
|
6 | <% end %> |
@@ -0,0 +1,9 | |||||
|
1 | class AddIssueCategoriesAssignedToId < ActiveRecord::Migration | |||
|
2 | def self.up | |||
|
3 | add_column :issue_categories, :assigned_to_id, :integer | |||
|
4 | end | |||
|
5 | ||||
|
6 | def self.down | |||
|
7 | remove_column :issue_categories, :assigned_to_id | |||
|
8 | end | |||
|
9 | end |
@@ -0,0 +1,27 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class IssueTest < Test::Unit::TestCase | |||
|
21 | fixtures :projects, :users, :members, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues | |||
|
22 | ||||
|
23 | def test_category_based_assignment | |||
|
24 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) | |||
|
25 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to | |||
|
26 | end | |||
|
27 | end |
@@ -1,667 +1,662 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'csv' |
|
18 | require 'csv' | |
19 |
|
19 | |||
20 | class ProjectsController < ApplicationController |
|
20 | class ProjectsController < ApplicationController | |
21 | layout 'base' |
|
21 | layout 'base' | |
22 | before_filter :find_project, :except => [ :index, :list, :add ] |
|
22 | before_filter :find_project, :except => [ :index, :list, :add ] | |
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] | |
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] | |
25 |
|
25 | |||
26 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] |
|
26 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] | |
27 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] |
|
27 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] | |
28 |
|
28 | |||
29 | helper :sort |
|
29 | helper :sort | |
30 | include SortHelper |
|
30 | include SortHelper | |
31 | helper :custom_fields |
|
31 | helper :custom_fields | |
32 | include CustomFieldsHelper |
|
32 | include CustomFieldsHelper | |
33 | helper :ifpdf |
|
33 | helper :ifpdf | |
34 | include IfpdfHelper |
|
34 | include IfpdfHelper | |
35 | helper IssuesHelper |
|
35 | helper IssuesHelper | |
36 | helper :queries |
|
36 | helper :queries | |
37 | include QueriesHelper |
|
37 | include QueriesHelper | |
38 | helper :repositories |
|
38 | helper :repositories | |
39 | include RepositoriesHelper |
|
39 | include RepositoriesHelper | |
40 |
|
40 | |||
41 | def index |
|
41 | def index | |
42 | list |
|
42 | list | |
43 | render :action => 'list' unless request.xhr? |
|
43 | render :action => 'list' unless request.xhr? | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | # Lists public projects |
|
46 | # Lists public projects | |
47 | def list |
|
47 | def list | |
48 | sort_init "#{Project.table_name}.name", "asc" |
|
48 | sort_init "#{Project.table_name}.name", "asc" | |
49 | sort_update |
|
49 | sort_update | |
50 | @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user)) |
|
50 | @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user)) | |
51 | @project_pages = Paginator.new self, @project_count, |
|
51 | @project_pages = Paginator.new self, @project_count, | |
52 | 15, |
|
52 | 15, | |
53 | params['page'] |
|
53 | params['page'] | |
54 | @projects = Project.find :all, :order => sort_clause, |
|
54 | @projects = Project.find :all, :order => sort_clause, | |
55 | :conditions => Project.visible_by(logged_in_user), |
|
55 | :conditions => Project.visible_by(logged_in_user), | |
56 | :include => :parent, |
|
56 | :include => :parent, | |
57 | :limit => @project_pages.items_per_page, |
|
57 | :limit => @project_pages.items_per_page, | |
58 | :offset => @project_pages.current.offset |
|
58 | :offset => @project_pages.current.offset | |
59 |
|
59 | |||
60 | render :action => "list", :layout => false if request.xhr? |
|
60 | render :action => "list", :layout => false if request.xhr? | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | # Add a new project |
|
63 | # Add a new project | |
64 | def add |
|
64 | def add | |
65 | @custom_fields = IssueCustomField.find(:all) |
|
65 | @custom_fields = IssueCustomField.find(:all) | |
66 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
66 | @root_projects = Project.find(:all, :conditions => "parent_id is null") | |
67 | @project = Project.new(params[:project]) |
|
67 | @project = Project.new(params[:project]) | |
68 | if request.get? |
|
68 | if request.get? | |
69 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
69 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
70 | else |
|
70 | else | |
71 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
71 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
72 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
72 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
73 | @project.custom_values = @custom_values |
|
73 | @project.custom_values = @custom_values | |
74 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
74 | if params[:repository_enabled] && params[:repository_enabled] == "1" | |
75 | @project.repository = Repository.factory(params[:repository_scm]) |
|
75 | @project.repository = Repository.factory(params[:repository_scm]) | |
76 | @project.repository.attributes = params[:repository] |
|
76 | @project.repository.attributes = params[:repository] | |
77 | end |
|
77 | end | |
78 | if "1" == params[:wiki_enabled] |
|
78 | if "1" == params[:wiki_enabled] | |
79 | @project.wiki = Wiki.new |
|
79 | @project.wiki = Wiki.new | |
80 | @project.wiki.attributes = params[:wiki] |
|
80 | @project.wiki.attributes = params[:wiki] | |
81 | end |
|
81 | end | |
82 | if @project.save |
|
82 | if @project.save | |
83 | flash[:notice] = l(:notice_successful_create) |
|
83 | flash[:notice] = l(:notice_successful_create) | |
84 | redirect_to :controller => 'admin', :action => 'projects' |
|
84 | redirect_to :controller => 'admin', :action => 'projects' | |
85 | end |
|
85 | end | |
86 | end |
|
86 | end | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | # Show @project |
|
89 | # Show @project | |
90 | def show |
|
90 | def show | |
91 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
91 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
92 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
92 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} | |
93 | @subprojects = @project.active_children |
|
93 | @subprojects = @project.active_children | |
94 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
94 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
95 | @trackers = Tracker.find(:all, :order => 'position') |
|
95 | @trackers = Tracker.find(:all, :order => 'position') | |
96 | @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]) |
|
96 | @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]) | |
97 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
97 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def settings |
|
100 | def settings | |
101 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
101 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) | |
102 | @custom_fields = IssueCustomField.find(:all) |
|
102 | @custom_fields = IssueCustomField.find(:all) | |
103 | @issue_category ||= IssueCategory.new |
|
103 | @issue_category ||= IssueCategory.new | |
104 | @member ||= @project.members.new |
|
104 | @member ||= @project.members.new | |
105 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
105 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | # Edit @project |
|
108 | # Edit @project | |
109 | def edit |
|
109 | def edit | |
110 | if request.post? |
|
110 | if request.post? | |
111 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
111 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
112 | if params[:custom_fields] |
|
112 | if params[:custom_fields] | |
113 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
113 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
114 | @project.custom_values = @custom_values |
|
114 | @project.custom_values = @custom_values | |
115 | end |
|
115 | end | |
116 | if params[:repository_enabled] |
|
116 | if params[:repository_enabled] | |
117 | case params[:repository_enabled] |
|
117 | case params[:repository_enabled] | |
118 | when "0" |
|
118 | when "0" | |
119 | @project.repository = nil |
|
119 | @project.repository = nil | |
120 | when "1" |
|
120 | when "1" | |
121 | @project.repository ||= Repository.factory(params[:repository_scm]) |
|
121 | @project.repository ||= Repository.factory(params[:repository_scm]) | |
122 | @project.repository.update_attributes params[:repository] if @project.repository |
|
122 | @project.repository.update_attributes params[:repository] if @project.repository | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 | if params[:wiki_enabled] |
|
125 | if params[:wiki_enabled] | |
126 | case params[:wiki_enabled] |
|
126 | case params[:wiki_enabled] | |
127 | when "0" |
|
127 | when "0" | |
128 | @project.wiki.destroy if @project.wiki |
|
128 | @project.wiki.destroy if @project.wiki | |
129 | when "1" |
|
129 | when "1" | |
130 | @project.wiki ||= Wiki.new |
|
130 | @project.wiki ||= Wiki.new | |
131 | @project.wiki.update_attributes params[:wiki] |
|
131 | @project.wiki.update_attributes params[:wiki] | |
132 | end |
|
132 | end | |
133 | end |
|
133 | end | |
134 | @project.attributes = params[:project] |
|
134 | @project.attributes = params[:project] | |
135 | if @project.save |
|
135 | if @project.save | |
136 | flash[:notice] = l(:notice_successful_update) |
|
136 | flash[:notice] = l(:notice_successful_update) | |
137 | redirect_to :action => 'settings', :id => @project |
|
137 | redirect_to :action => 'settings', :id => @project | |
138 | else |
|
138 | else | |
139 | settings |
|
139 | settings | |
140 | render :action => 'settings' |
|
140 | render :action => 'settings' | |
141 | end |
|
141 | end | |
142 | end |
|
142 | end | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def archive |
|
145 | def archive | |
146 | @project.archive if request.post? && @project.active? |
|
146 | @project.archive if request.post? && @project.active? | |
147 | redirect_to :controller => 'admin', :action => 'projects' |
|
147 | redirect_to :controller => 'admin', :action => 'projects' | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def unarchive |
|
150 | def unarchive | |
151 | @project.unarchive if request.post? && !@project.active? |
|
151 | @project.unarchive if request.post? && !@project.active? | |
152 | redirect_to :controller => 'admin', :action => 'projects' |
|
152 | redirect_to :controller => 'admin', :action => 'projects' | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | # Delete @project |
|
155 | # Delete @project | |
156 | def destroy |
|
156 | def destroy | |
157 | @project_to_destroy = @project |
|
157 | @project_to_destroy = @project | |
158 | if request.post? and params[:confirm] |
|
158 | if request.post? and params[:confirm] | |
159 | @project_to_destroy.destroy |
|
159 | @project_to_destroy.destroy | |
160 | redirect_to :controller => 'admin', :action => 'projects' |
|
160 | redirect_to :controller => 'admin', :action => 'projects' | |
161 | end |
|
161 | end | |
162 | # hide project in layout |
|
162 | # hide project in layout | |
163 | @project = nil |
|
163 | @project = nil | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | # Add a new issue category to @project |
|
166 | # Add a new issue category to @project | |
167 | def add_issue_category |
|
167 | def add_issue_category | |
168 | if request.post? |
|
168 | @category = @project.issue_categories.build(params[:category]) | |
169 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
169 | if request.post? and @category.save | |
170 | if @issue_category.save |
|
170 | flash[:notice] = l(:notice_successful_create) | |
171 | flash[:notice] = l(:notice_successful_create) |
|
171 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
172 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
|||
173 | else |
|
|||
174 | settings |
|
|||
175 | render :action => 'settings' |
|
|||
176 | end |
|
|||
177 | end |
|
172 | end | |
178 |
end |
|
173 | end | |
179 |
|
174 | |||
180 | # Add a new version to @project |
|
175 | # Add a new version to @project | |
181 | def add_version |
|
176 | def add_version | |
182 | @version = @project.versions.build(params[:version]) |
|
177 | @version = @project.versions.build(params[:version]) | |
183 | if request.post? and @version.save |
|
178 | if request.post? and @version.save | |
184 | flash[:notice] = l(:notice_successful_create) |
|
179 | flash[:notice] = l(:notice_successful_create) | |
185 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
180 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
186 | end |
|
181 | end | |
187 | end |
|
182 | end | |
188 |
|
183 | |||
189 | # Add a new member to @project |
|
184 | # Add a new member to @project | |
190 | def add_member |
|
185 | def add_member | |
191 | @member = @project.members.build(params[:member]) |
|
186 | @member = @project.members.build(params[:member]) | |
192 | if request.post? && @member.save |
|
187 | if request.post? && @member.save | |
193 | respond_to do |format| |
|
188 | respond_to do |format| | |
194 | format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } |
|
189 | format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project } | |
195 | format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} } |
|
190 | format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} } | |
196 | end |
|
191 | end | |
197 | else |
|
192 | else | |
198 | settings |
|
193 | settings | |
199 | render :action => 'settings' |
|
194 | render :action => 'settings' | |
200 | end |
|
195 | end | |
201 | end |
|
196 | end | |
202 |
|
197 | |||
203 | # Show members list of @project |
|
198 | # Show members list of @project | |
204 | def list_members |
|
199 | def list_members | |
205 | @members = @project.members.find(:all) |
|
200 | @members = @project.members.find(:all) | |
206 | end |
|
201 | end | |
207 |
|
202 | |||
208 | # Add a new document to @project |
|
203 | # Add a new document to @project | |
209 | def add_document |
|
204 | def add_document | |
210 | @categories = Enumeration::get_values('DCAT') |
|
205 | @categories = Enumeration::get_values('DCAT') | |
211 | @document = @project.documents.build(params[:document]) |
|
206 | @document = @project.documents.build(params[:document]) | |
212 | if request.post? and @document.save |
|
207 | if request.post? and @document.save | |
213 | # Save the attachments |
|
208 | # Save the attachments | |
214 | params[:attachments].each { |a| |
|
209 | params[:attachments].each { |a| | |
215 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
210 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
216 | } if params[:attachments] and params[:attachments].is_a? Array |
|
211 | } if params[:attachments] and params[:attachments].is_a? Array | |
217 | flash[:notice] = l(:notice_successful_create) |
|
212 | flash[:notice] = l(:notice_successful_create) | |
218 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
213 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
219 | redirect_to :action => 'list_documents', :id => @project |
|
214 | redirect_to :action => 'list_documents', :id => @project | |
220 | end |
|
215 | end | |
221 | end |
|
216 | end | |
222 |
|
217 | |||
223 | # Show documents list of @project |
|
218 | # Show documents list of @project | |
224 | def list_documents |
|
219 | def list_documents | |
225 | @documents = @project.documents.find :all, :include => :category |
|
220 | @documents = @project.documents.find :all, :include => :category | |
226 | end |
|
221 | end | |
227 |
|
222 | |||
228 | # Add a new issue to @project |
|
223 | # Add a new issue to @project | |
229 | def add_issue |
|
224 | def add_issue | |
230 | @tracker = Tracker.find(params[:tracker_id]) |
|
225 | @tracker = Tracker.find(params[:tracker_id]) | |
231 | @priorities = Enumeration::get_values('IPRI') |
|
226 | @priorities = Enumeration::get_values('IPRI') | |
232 |
|
227 | |||
233 | default_status = IssueStatus.default |
|
228 | default_status = IssueStatus.default | |
234 | unless default_status |
|
229 | unless default_status | |
235 | flash.now[:notice] = 'No default issue status defined. Please check your configuration.' |
|
230 | flash.now[:notice] = 'No default issue status defined. Please check your configuration.' | |
236 | render :nothing => true, :layout => true |
|
231 | render :nothing => true, :layout => true | |
237 | return |
|
232 | return | |
238 | end |
|
233 | end | |
239 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
234 | @issue = Issue.new(:project => @project, :tracker => @tracker) | |
240 | @issue.status = default_status |
|
235 | @issue.status = default_status | |
241 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user |
|
236 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user | |
242 | if request.get? |
|
237 | if request.get? | |
243 | @issue.start_date = Date.today |
|
238 | @issue.start_date = Date.today | |
244 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
239 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
245 | else |
|
240 | else | |
246 | @issue.attributes = params[:issue] |
|
241 | @issue.attributes = params[:issue] | |
247 |
|
242 | |||
248 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
243 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
249 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
244 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
250 |
|
245 | |||
251 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
246 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
252 | # Multiple file upload |
|
247 | # Multiple file upload | |
253 | @attachments = [] |
|
248 | @attachments = [] | |
254 | params[:attachments].each { |a| |
|
249 | params[:attachments].each { |a| | |
255 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
250 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
256 | } if params[:attachments] and params[:attachments].is_a? Array |
|
251 | } if params[:attachments] and params[:attachments].is_a? Array | |
257 | @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]) } |
|
252 | @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]) } | |
258 | @issue.custom_values = @custom_values |
|
253 | @issue.custom_values = @custom_values | |
259 | if @issue.save |
|
254 | if @issue.save | |
260 | @attachments.each(&:save) |
|
255 | @attachments.each(&:save) | |
261 | flash[:notice] = l(:notice_successful_create) |
|
256 | flash[:notice] = l(:notice_successful_create) | |
262 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
257 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
263 | redirect_to :action => 'list_issues', :id => @project |
|
258 | redirect_to :action => 'list_issues', :id => @project | |
264 | end |
|
259 | end | |
265 | end |
|
260 | end | |
266 | end |
|
261 | end | |
267 |
|
262 | |||
268 | # Show filtered/sorted issues list of @project |
|
263 | # Show filtered/sorted issues list of @project | |
269 | def list_issues |
|
264 | def list_issues | |
270 | sort_init "#{Issue.table_name}.id", "desc" |
|
265 | sort_init "#{Issue.table_name}.id", "desc" | |
271 | sort_update |
|
266 | sort_update | |
272 |
|
267 | |||
273 | retrieve_query |
|
268 | retrieve_query | |
274 |
|
269 | |||
275 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
270 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
276 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
271 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
277 | @results_per_page = params[:per_page].to_i |
|
272 | @results_per_page = params[:per_page].to_i | |
278 | session[:results_per_page] = @results_per_page |
|
273 | session[:results_per_page] = @results_per_page | |
279 | else |
|
274 | else | |
280 | @results_per_page = session[:results_per_page] || 25 |
|
275 | @results_per_page = session[:results_per_page] || 25 | |
281 | end |
|
276 | end | |
282 |
|
277 | |||
283 | if @query.valid? |
|
278 | if @query.valid? | |
284 | @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement) |
|
279 | @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement) | |
285 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
280 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
286 | @issues = Issue.find :all, :order => sort_clause, |
|
281 | @issues = Issue.find :all, :order => sort_clause, | |
287 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ], |
|
282 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ], | |
288 | :conditions => @query.statement, |
|
283 | :conditions => @query.statement, | |
289 | :limit => @issue_pages.items_per_page, |
|
284 | :limit => @issue_pages.items_per_page, | |
290 | :offset => @issue_pages.current.offset |
|
285 | :offset => @issue_pages.current.offset | |
291 | end |
|
286 | end | |
292 | render :layout => false if request.xhr? |
|
287 | render :layout => false if request.xhr? | |
293 | end |
|
288 | end | |
294 |
|
289 | |||
295 | # Export filtered/sorted issues list to CSV |
|
290 | # Export filtered/sorted issues list to CSV | |
296 | def export_issues_csv |
|
291 | def export_issues_csv | |
297 | sort_init "#{Issue.table_name}.id", "desc" |
|
292 | sort_init "#{Issue.table_name}.id", "desc" | |
298 | sort_update |
|
293 | sort_update | |
299 |
|
294 | |||
300 | retrieve_query |
|
295 | retrieve_query | |
301 | render :action => 'list_issues' and return unless @query.valid? |
|
296 | render :action => 'list_issues' and return unless @query.valid? | |
302 |
|
297 | |||
303 | @issues = Issue.find :all, :order => sort_clause, |
|
298 | @issues = Issue.find :all, :order => sort_clause, | |
304 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], |
|
299 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], | |
305 | :conditions => @query.statement, |
|
300 | :conditions => @query.statement, | |
306 | :limit => Setting.issues_export_limit.to_i |
|
301 | :limit => Setting.issues_export_limit.to_i | |
307 |
|
302 | |||
308 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
303 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
309 | export = StringIO.new |
|
304 | export = StringIO.new | |
310 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
305 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
311 | # csv header fields |
|
306 | # csv header fields | |
312 | headers = [ "#", l(:field_status), |
|
307 | headers = [ "#", l(:field_status), | |
313 | l(:field_project), |
|
308 | l(:field_project), | |
314 | l(:field_tracker), |
|
309 | l(:field_tracker), | |
315 | l(:field_priority), |
|
310 | l(:field_priority), | |
316 | l(:field_subject), |
|
311 | l(:field_subject), | |
317 | l(:field_assigned_to), |
|
312 | l(:field_assigned_to), | |
318 | l(:field_author), |
|
313 | l(:field_author), | |
319 | l(:field_start_date), |
|
314 | l(:field_start_date), | |
320 | l(:field_due_date), |
|
315 | l(:field_due_date), | |
321 | l(:field_done_ratio), |
|
316 | l(:field_done_ratio), | |
322 | l(:field_created_on), |
|
317 | l(:field_created_on), | |
323 | l(:field_updated_on) |
|
318 | l(:field_updated_on) | |
324 | ] |
|
319 | ] | |
325 | for custom_field in @project.all_custom_fields |
|
320 | for custom_field in @project.all_custom_fields | |
326 | headers << custom_field.name |
|
321 | headers << custom_field.name | |
327 | end |
|
322 | end | |
328 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
323 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
329 | # csv lines |
|
324 | # csv lines | |
330 | @issues.each do |issue| |
|
325 | @issues.each do |issue| | |
331 | fields = [issue.id, issue.status.name, |
|
326 | fields = [issue.id, issue.status.name, | |
332 | issue.project.name, |
|
327 | issue.project.name, | |
333 | issue.tracker.name, |
|
328 | issue.tracker.name, | |
334 | issue.priority.name, |
|
329 | issue.priority.name, | |
335 | issue.subject, |
|
330 | issue.subject, | |
336 | (issue.assigned_to ? issue.assigned_to.name : ""), |
|
331 | (issue.assigned_to ? issue.assigned_to.name : ""), | |
337 | issue.author.name, |
|
332 | issue.author.name, | |
338 | issue.start_date ? l_date(issue.start_date) : nil, |
|
333 | issue.start_date ? l_date(issue.start_date) : nil, | |
339 | issue.due_date ? l_date(issue.due_date) : nil, |
|
334 | issue.due_date ? l_date(issue.due_date) : nil, | |
340 | issue.done_ratio, |
|
335 | issue.done_ratio, | |
341 | l_datetime(issue.created_on), |
|
336 | l_datetime(issue.created_on), | |
342 | l_datetime(issue.updated_on) |
|
337 | l_datetime(issue.updated_on) | |
343 | ] |
|
338 | ] | |
344 | for custom_field in @project.all_custom_fields |
|
339 | for custom_field in @project.all_custom_fields | |
345 | fields << (show_value issue.custom_value_for(custom_field)) |
|
340 | fields << (show_value issue.custom_value_for(custom_field)) | |
346 | end |
|
341 | end | |
347 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
342 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
348 | end |
|
343 | end | |
349 | end |
|
344 | end | |
350 | export.rewind |
|
345 | export.rewind | |
351 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
346 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
352 | end |
|
347 | end | |
353 |
|
348 | |||
354 | # Export filtered/sorted issues to PDF |
|
349 | # Export filtered/sorted issues to PDF | |
355 | def export_issues_pdf |
|
350 | def export_issues_pdf | |
356 | sort_init "#{Issue.table_name}.id", "desc" |
|
351 | sort_init "#{Issue.table_name}.id", "desc" | |
357 | sort_update |
|
352 | sort_update | |
358 |
|
353 | |||
359 | retrieve_query |
|
354 | retrieve_query | |
360 | render :action => 'list_issues' and return unless @query.valid? |
|
355 | render :action => 'list_issues' and return unless @query.valid? | |
361 |
|
356 | |||
362 | @issues = Issue.find :all, :order => sort_clause, |
|
357 | @issues = Issue.find :all, :order => sort_clause, | |
363 | :include => [ :author, :status, :tracker, :priority, :project, :custom_values ], |
|
358 | :include => [ :author, :status, :tracker, :priority, :project, :custom_values ], | |
364 | :conditions => @query.statement, |
|
359 | :conditions => @query.statement, | |
365 | :limit => Setting.issues_export_limit.to_i |
|
360 | :limit => Setting.issues_export_limit.to_i | |
366 |
|
361 | |||
367 | @options_for_rfpdf ||= {} |
|
362 | @options_for_rfpdf ||= {} | |
368 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
363 | @options_for_rfpdf[:file_name] = "export.pdf" | |
369 | render :layout => false |
|
364 | render :layout => false | |
370 | end |
|
365 | end | |
371 |
|
366 | |||
372 | def move_issues |
|
367 | def move_issues | |
373 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
368 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
374 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
369 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
375 | @projects = [] |
|
370 | @projects = [] | |
376 | # find projects to which the user is allowed to move the issue |
|
371 | # find projects to which the user is allowed to move the issue | |
377 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} |
|
372 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} | |
378 | # issue can be moved to any tracker |
|
373 | # issue can be moved to any tracker | |
379 | @trackers = Tracker.find(:all) |
|
374 | @trackers = Tracker.find(:all) | |
380 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
375 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
381 | new_project = Project.find(params[:new_project_id]) |
|
376 | new_project = Project.find(params[:new_project_id]) | |
382 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
377 | new_tracker = Tracker.find(params[:new_tracker_id]) | |
383 | @issues.each { |i| |
|
378 | @issues.each { |i| | |
384 | # project dependent properties |
|
379 | # project dependent properties | |
385 | unless i.project_id == new_project.id |
|
380 | unless i.project_id == new_project.id | |
386 | i.category = nil |
|
381 | i.category = nil | |
387 | i.fixed_version = nil |
|
382 | i.fixed_version = nil | |
388 | # delete issue relations |
|
383 | # delete issue relations | |
389 | i.relations_from.clear |
|
384 | i.relations_from.clear | |
390 | i.relations_to.clear |
|
385 | i.relations_to.clear | |
391 | end |
|
386 | end | |
392 | # move the issue |
|
387 | # move the issue | |
393 | i.project = new_project |
|
388 | i.project = new_project | |
394 | i.tracker = new_tracker |
|
389 | i.tracker = new_tracker | |
395 | i.save |
|
390 | i.save | |
396 | } |
|
391 | } | |
397 | flash[:notice] = l(:notice_successful_update) |
|
392 | flash[:notice] = l(:notice_successful_update) | |
398 | redirect_to :action => 'list_issues', :id => @project |
|
393 | redirect_to :action => 'list_issues', :id => @project | |
399 | end |
|
394 | end | |
400 | end |
|
395 | end | |
401 |
|
396 | |||
402 | # Add a news to @project |
|
397 | # Add a news to @project | |
403 | def add_news |
|
398 | def add_news | |
404 | @news = News.new(:project => @project) |
|
399 | @news = News.new(:project => @project) | |
405 | if request.post? |
|
400 | if request.post? | |
406 | @news.attributes = params[:news] |
|
401 | @news.attributes = params[:news] | |
407 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
402 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
408 | if @news.save |
|
403 | if @news.save | |
409 | flash[:notice] = l(:notice_successful_create) |
|
404 | flash[:notice] = l(:notice_successful_create) | |
410 | redirect_to :action => 'list_news', :id => @project |
|
405 | redirect_to :action => 'list_news', :id => @project | |
411 | end |
|
406 | end | |
412 | end |
|
407 | end | |
413 | end |
|
408 | end | |
414 |
|
409 | |||
415 | # Show news list of @project |
|
410 | # Show news list of @project | |
416 | def list_news |
|
411 | def list_news | |
417 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
412 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" | |
418 | render :action => "list_news", :layout => false if request.xhr? |
|
413 | render :action => "list_news", :layout => false if request.xhr? | |
419 | end |
|
414 | end | |
420 |
|
415 | |||
421 | def add_file |
|
416 | def add_file | |
422 | if request.post? |
|
417 | if request.post? | |
423 | @version = @project.versions.find_by_id(params[:version_id]) |
|
418 | @version = @project.versions.find_by_id(params[:version_id]) | |
424 | # Save the attachments |
|
419 | # Save the attachments | |
425 | @attachments = [] |
|
420 | @attachments = [] | |
426 | params[:attachments].each { |file| |
|
421 | params[:attachments].each { |file| | |
427 | next unless file.size > 0 |
|
422 | next unless file.size > 0 | |
428 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
423 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) | |
429 | @attachments << a unless a.new_record? |
|
424 | @attachments << a unless a.new_record? | |
430 | } if params[:attachments] and params[:attachments].is_a? Array |
|
425 | } if params[:attachments] and params[:attachments].is_a? Array | |
431 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
426 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
432 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
427 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
433 | end |
|
428 | end | |
434 | @versions = @project.versions.sort |
|
429 | @versions = @project.versions.sort | |
435 | end |
|
430 | end | |
436 |
|
431 | |||
437 | def list_files |
|
432 | def list_files | |
438 | @versions = @project.versions.sort |
|
433 | @versions = @project.versions.sort | |
439 | end |
|
434 | end | |
440 |
|
435 | |||
441 | # Show changelog for @project |
|
436 | # Show changelog for @project | |
442 | def changelog |
|
437 | def changelog | |
443 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
438 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
444 | retrieve_selected_tracker_ids(@trackers) |
|
439 | retrieve_selected_tracker_ids(@trackers) | |
445 | @versions = @project.versions.sort |
|
440 | @versions = @project.versions.sort | |
446 | end |
|
441 | end | |
447 |
|
442 | |||
448 | def roadmap |
|
443 | def roadmap | |
449 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
444 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') | |
450 | retrieve_selected_tracker_ids(@trackers) |
|
445 | retrieve_selected_tracker_ids(@trackers) | |
451 | conditions = ("1" == params[:completed] ? nil : [ "#{Version.table_name}.effective_date > ? OR #{Version.table_name}.effective_date IS NULL", Date.today]) |
|
446 | conditions = ("1" == params[:completed] ? nil : [ "#{Version.table_name}.effective_date > ? OR #{Version.table_name}.effective_date IS NULL", Date.today]) | |
452 | @versions = @project.versions.find(:all, :conditions => conditions).sort |
|
447 | @versions = @project.versions.find(:all, :conditions => conditions).sort | |
453 | end |
|
448 | end | |
454 |
|
449 | |||
455 | def activity |
|
450 | def activity | |
456 | if params[:year] and params[:year].to_i > 1900 |
|
451 | if params[:year] and params[:year].to_i > 1900 | |
457 | @year = params[:year].to_i |
|
452 | @year = params[:year].to_i | |
458 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
453 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
459 | @month = params[:month].to_i |
|
454 | @month = params[:month].to_i | |
460 | end |
|
455 | end | |
461 | end |
|
456 | end | |
462 | @year ||= Date.today.year |
|
457 | @year ||= Date.today.year | |
463 | @month ||= Date.today.month |
|
458 | @month ||= Date.today.month | |
464 |
|
459 | |||
465 | @date_from = Date.civil(@year, @month, 1) |
|
460 | @date_from = Date.civil(@year, @month, 1) | |
466 | @date_to = @date_from >> 1 |
|
461 | @date_to = @date_from >> 1 | |
467 |
|
462 | |||
468 | @events_by_day = {} |
|
463 | @events_by_day = {} | |
469 |
|
464 | |||
470 | unless params[:show_issues] == "0" |
|
465 | unless params[:show_issues] == "0" | |
471 | @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
466 | @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
472 | @events_by_day[i.created_on.to_date] ||= [] |
|
467 | @events_by_day[i.created_on.to_date] ||= [] | |
473 | @events_by_day[i.created_on.to_date] << i |
|
468 | @events_by_day[i.created_on.to_date] << i | |
474 | } |
|
469 | } | |
475 | @show_issues = 1 |
|
470 | @show_issues = 1 | |
476 | end |
|
471 | end | |
477 |
|
472 | |||
478 | unless params[:show_news] == "0" |
|
473 | unless params[:show_news] == "0" | |
479 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
474 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| | |
480 | @events_by_day[i.created_on.to_date] ||= [] |
|
475 | @events_by_day[i.created_on.to_date] ||= [] | |
481 | @events_by_day[i.created_on.to_date] << i |
|
476 | @events_by_day[i.created_on.to_date] << i | |
482 | } |
|
477 | } | |
483 | @show_news = 1 |
|
478 | @show_news = 1 | |
484 | end |
|
479 | end | |
485 |
|
480 | |||
486 | unless params[:show_files] == "0" |
|
481 | unless params[:show_files] == "0" | |
487 | 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| |
|
482 | 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| | |
488 | @events_by_day[i.created_on.to_date] ||= [] |
|
483 | @events_by_day[i.created_on.to_date] ||= [] | |
489 | @events_by_day[i.created_on.to_date] << i |
|
484 | @events_by_day[i.created_on.to_date] << i | |
490 | } |
|
485 | } | |
491 | @show_files = 1 |
|
486 | @show_files = 1 | |
492 | end |
|
487 | end | |
493 |
|
488 | |||
494 | unless params[:show_documents] == "0" |
|
489 | unless params[:show_documents] == "0" | |
495 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
490 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
496 | @events_by_day[i.created_on.to_date] ||= [] |
|
491 | @events_by_day[i.created_on.to_date] ||= [] | |
497 | @events_by_day[i.created_on.to_date] << i |
|
492 | @events_by_day[i.created_on.to_date] << i | |
498 | } |
|
493 | } | |
499 | 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| |
|
494 | 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| | |
500 | @events_by_day[i.created_on.to_date] ||= [] |
|
495 | @events_by_day[i.created_on.to_date] ||= [] | |
501 | @events_by_day[i.created_on.to_date] << i |
|
496 | @events_by_day[i.created_on.to_date] << i | |
502 | } |
|
497 | } | |
503 | @show_documents = 1 |
|
498 | @show_documents = 1 | |
504 | end |
|
499 | end | |
505 |
|
500 | |||
506 | unless @project.wiki.nil? || params[:show_wiki_edits] == "0" |
|
501 | unless @project.wiki.nil? || params[:show_wiki_edits] == "0" | |
507 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
502 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
508 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
503 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" | |
509 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
504 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
510 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
505 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
511 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
506 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
512 | @project.id, @date_from, @date_to] |
|
507 | @project.id, @date_from, @date_to] | |
513 |
|
508 | |||
514 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
509 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| | |
515 | # We provide this alias so all events can be treated in the same manner |
|
510 | # We provide this alias so all events can be treated in the same manner | |
516 | def i.created_on |
|
511 | def i.created_on | |
517 | self.updated_on |
|
512 | self.updated_on | |
518 | end |
|
513 | end | |
519 |
|
514 | |||
520 | @events_by_day[i.created_on.to_date] ||= [] |
|
515 | @events_by_day[i.created_on.to_date] ||= [] | |
521 | @events_by_day[i.created_on.to_date] << i |
|
516 | @events_by_day[i.created_on.to_date] << i | |
522 | } |
|
517 | } | |
523 | @show_wiki_edits = 1 |
|
518 | @show_wiki_edits = 1 | |
524 | end |
|
519 | end | |
525 |
|
520 | |||
526 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
521 | unless @project.repository.nil? || params[:show_changesets] == "0" | |
527 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
522 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| | |
528 | def i.created_on |
|
523 | def i.created_on | |
529 | self.committed_on |
|
524 | self.committed_on | |
530 | end |
|
525 | end | |
531 | @events_by_day[i.created_on.to_date] ||= [] |
|
526 | @events_by_day[i.created_on.to_date] ||= [] | |
532 | @events_by_day[i.created_on.to_date] << i |
|
527 | @events_by_day[i.created_on.to_date] << i | |
533 | } |
|
528 | } | |
534 | @show_changesets = 1 |
|
529 | @show_changesets = 1 | |
535 | end |
|
530 | end | |
536 |
|
531 | |||
537 | render :layout => false if request.xhr? |
|
532 | render :layout => false if request.xhr? | |
538 | end |
|
533 | end | |
539 |
|
534 | |||
540 | def calendar |
|
535 | def calendar | |
541 | @trackers = Tracker.find(:all, :order => 'position') |
|
536 | @trackers = Tracker.find(:all, :order => 'position') | |
542 | retrieve_selected_tracker_ids(@trackers) |
|
537 | retrieve_selected_tracker_ids(@trackers) | |
543 |
|
538 | |||
544 | if params[:year] and params[:year].to_i > 1900 |
|
539 | if params[:year] and params[:year].to_i > 1900 | |
545 | @year = params[:year].to_i |
|
540 | @year = params[:year].to_i | |
546 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
541 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
547 | @month = params[:month].to_i |
|
542 | @month = params[:month].to_i | |
548 | end |
|
543 | end | |
549 | end |
|
544 | end | |
550 | @year ||= Date.today.year |
|
545 | @year ||= Date.today.year | |
551 | @month ||= Date.today.month |
|
546 | @month ||= Date.today.month | |
552 |
|
547 | |||
553 | @date_from = Date.civil(@year, @month, 1) |
|
548 | @date_from = Date.civil(@year, @month, 1) | |
554 | @date_to = (@date_from >> 1)-1 |
|
549 | @date_to = (@date_from >> 1)-1 | |
555 | # start on monday |
|
550 | # start on monday | |
556 | @date_from = @date_from - (@date_from.cwday-1) |
|
551 | @date_from = @date_from - (@date_from.cwday-1) | |
557 | # finish on sunday |
|
552 | # finish on sunday | |
558 | @date_to = @date_to + (7-@date_to.cwday) |
|
553 | @date_to = @date_to + (7-@date_to.cwday) | |
559 |
|
554 | |||
560 | @events = [] |
|
555 | @events = [] | |
561 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
556 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
562 | @events += Issue.find(:all, |
|
557 | @events += Issue.find(:all, | |
563 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
558 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
564 | :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] |
|
559 | :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] | |
565 | ) unless @selected_tracker_ids.empty? |
|
560 | ) unless @selected_tracker_ids.empty? | |
566 | end |
|
561 | end | |
567 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
562 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
568 |
|
563 | |||
569 | @ending_events_by_days = @events.group_by {|event| event.due_date} |
|
564 | @ending_events_by_days = @events.group_by {|event| event.due_date} | |
570 | @starting_events_by_days = @events.group_by {|event| event.start_date} |
|
565 | @starting_events_by_days = @events.group_by {|event| event.start_date} | |
571 |
|
566 | |||
572 | render :layout => false if request.xhr? |
|
567 | render :layout => false if request.xhr? | |
573 | end |
|
568 | end | |
574 |
|
569 | |||
575 | def gantt |
|
570 | def gantt | |
576 | @trackers = Tracker.find(:all, :order => 'position') |
|
571 | @trackers = Tracker.find(:all, :order => 'position') | |
577 | retrieve_selected_tracker_ids(@trackers) |
|
572 | retrieve_selected_tracker_ids(@trackers) | |
578 |
|
573 | |||
579 | if params[:year] and params[:year].to_i >0 |
|
574 | if params[:year] and params[:year].to_i >0 | |
580 | @year_from = params[:year].to_i |
|
575 | @year_from = params[:year].to_i | |
581 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
576 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
582 | @month_from = params[:month].to_i |
|
577 | @month_from = params[:month].to_i | |
583 | else |
|
578 | else | |
584 | @month_from = 1 |
|
579 | @month_from = 1 | |
585 | end |
|
580 | end | |
586 | else |
|
581 | else | |
587 | @month_from ||= (Date.today << 1).month |
|
582 | @month_from ||= (Date.today << 1).month | |
588 | @year_from ||= (Date.today << 1).year |
|
583 | @year_from ||= (Date.today << 1).year | |
589 | end |
|
584 | end | |
590 |
|
585 | |||
591 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
586 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 | |
592 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
587 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 | |
593 |
|
588 | |||
594 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
589 | @date_from = Date.civil(@year_from, @month_from, 1) | |
595 | @date_to = (@date_from >> @months) - 1 |
|
590 | @date_to = (@date_from >> @months) - 1 | |
596 |
|
591 | |||
597 | @events = [] |
|
592 | @events = [] | |
598 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
593 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
599 | @events += Issue.find(:all, |
|
594 | @events += Issue.find(:all, | |
600 | :order => "start_date, due_date", |
|
595 | :order => "start_date, due_date", | |
601 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
596 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
602 | :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] |
|
597 | :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] | |
603 | ) unless @selected_tracker_ids.empty? |
|
598 | ) unless @selected_tracker_ids.empty? | |
604 | end |
|
599 | end | |
605 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
600 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
606 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
601 | @events.sort! {|x,y| x.start_date <=> y.start_date } | |
607 |
|
602 | |||
608 | if params[:output]=='pdf' |
|
603 | if params[:output]=='pdf' | |
609 | @options_for_rfpdf ||= {} |
|
604 | @options_for_rfpdf ||= {} | |
610 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
605 | @options_for_rfpdf[:file_name] = "gantt.pdf" | |
611 | render :template => "projects/gantt.rfpdf", :layout => false |
|
606 | render :template => "projects/gantt.rfpdf", :layout => false | |
612 | else |
|
607 | else | |
613 | render :template => "projects/gantt.rhtml" |
|
608 | render :template => "projects/gantt.rhtml" | |
614 | end |
|
609 | end | |
615 | end |
|
610 | end | |
616 |
|
611 | |||
617 | def feeds |
|
612 | def feeds | |
618 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
613 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] | |
619 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
614 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user | |
620 | end |
|
615 | end | |
621 |
|
616 | |||
622 | private |
|
617 | private | |
623 | # Find project of id params[:id] |
|
618 | # Find project of id params[:id] | |
624 | # if not found, redirect to project list |
|
619 | # if not found, redirect to project list | |
625 | # Used as a before_filter |
|
620 | # Used as a before_filter | |
626 | def find_project |
|
621 | def find_project | |
627 | @project = Project.find(params[:id]) |
|
622 | @project = Project.find(params[:id]) | |
628 | @html_title = @project.name |
|
623 | @html_title = @project.name | |
629 | rescue ActiveRecord::RecordNotFound |
|
624 | rescue ActiveRecord::RecordNotFound | |
630 | render_404 |
|
625 | render_404 | |
631 | end |
|
626 | end | |
632 |
|
627 | |||
633 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
628 | def retrieve_selected_tracker_ids(selectable_trackers) | |
634 | if ids = params[:tracker_ids] |
|
629 | if ids = params[:tracker_ids] | |
635 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
630 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
636 | else |
|
631 | else | |
637 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
632 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
638 | end |
|
633 | end | |
639 | end |
|
634 | end | |
640 |
|
635 | |||
641 | # Retrieve query from session or build a new query |
|
636 | # Retrieve query from session or build a new query | |
642 | def retrieve_query |
|
637 | def retrieve_query | |
643 | if params[:query_id] |
|
638 | if params[:query_id] | |
644 | @query = @project.queries.find(params[:query_id]) |
|
639 | @query = @project.queries.find(params[:query_id]) | |
645 | @query.executed_by = logged_in_user |
|
640 | @query.executed_by = logged_in_user | |
646 | session[:query] = @query |
|
641 | session[:query] = @query | |
647 | else |
|
642 | else | |
648 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
643 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id | |
649 | # Give it a name, required to be valid |
|
644 | # Give it a name, required to be valid | |
650 | @query = Query.new(:name => "_", :executed_by => logged_in_user) |
|
645 | @query = Query.new(:name => "_", :executed_by => logged_in_user) | |
651 | @query.project = @project |
|
646 | @query.project = @project | |
652 | if params[:fields] and params[:fields].is_a? Array |
|
647 | if params[:fields] and params[:fields].is_a? Array | |
653 | params[:fields].each do |field| |
|
648 | params[:fields].each do |field| | |
654 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
649 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
655 | end |
|
650 | end | |
656 | else |
|
651 | else | |
657 | @query.available_filters.keys.each do |field| |
|
652 | @query.available_filters.keys.each do |field| | |
658 | @query.add_short_filter(field, params[field]) if params[field] |
|
653 | @query.add_short_filter(field, params[field]) if params[field] | |
659 | end |
|
654 | end | |
660 | end |
|
655 | end | |
661 | session[:query] = @query |
|
656 | session[:query] = @query | |
662 | else |
|
657 | else | |
663 | @query = session[:query] |
|
658 | @query = session[:query] | |
664 | end |
|
659 | end | |
665 | end |
|
660 | end | |
666 | end |
|
661 | end | |
667 | end |
|
662 | end |
@@ -1,124 +1,131 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Issue < ActiveRecord::Base |
|
18 | class Issue < ActiveRecord::Base | |
19 | belongs_to :project |
|
19 | belongs_to :project | |
20 | belongs_to :tracker |
|
20 | belongs_to :tracker | |
21 | belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' |
|
21 | belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' | |
22 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
22 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | |
23 | belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' |
|
23 | belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' | |
24 | belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' |
|
24 | belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' | |
25 | belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' |
|
25 | belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' | |
26 | belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' |
|
26 | belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' | |
27 |
|
27 | |||
28 | has_many :journals, :as => :journalized, :dependent => :destroy |
|
28 | has_many :journals, :as => :journalized, :dependent => :destroy | |
29 | has_many :attachments, :as => :container, :dependent => :destroy |
|
29 | has_many :attachments, :as => :container, :dependent => :destroy | |
30 | has_many :time_entries |
|
30 | has_many :time_entries | |
31 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
31 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
32 | has_many :custom_fields, :through => :custom_values |
|
32 | has_many :custom_fields, :through => :custom_values | |
33 | has_and_belongs_to_many :changesets, :order => "revision ASC" |
|
33 | has_and_belongs_to_many :changesets, :order => "revision ASC" | |
34 |
|
34 | |||
35 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
|
35 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all | |
36 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
|
36 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all | |
37 |
|
37 | |||
38 | acts_as_watchable |
|
38 | acts_as_watchable | |
39 |
|
39 | |||
40 | validates_presence_of :subject, :description, :priority, :tracker, :author, :status |
|
40 | validates_presence_of :subject, :description, :priority, :tracker, :author, :status | |
41 | validates_inclusion_of :done_ratio, :in => 0..100 |
|
41 | validates_inclusion_of :done_ratio, :in => 0..100 | |
42 | validates_associated :custom_values, :on => :update |
|
42 | validates_associated :custom_values, :on => :update | |
43 |
|
43 | |||
44 | # set default status for new issues |
|
44 | # set default status for new issues | |
45 | def before_validation |
|
45 | def before_validation | |
46 | self.status = IssueStatus.default if status.nil? |
|
46 | self.status = IssueStatus.default if status.nil? | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
49 | def validate |
|
49 | def validate | |
50 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? |
|
50 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? | |
51 | errors.add :due_date, :activerecord_error_not_a_date |
|
51 | errors.add :due_date, :activerecord_error_not_a_date | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | if self.due_date and self.start_date and self.due_date < self.start_date |
|
54 | if self.due_date and self.start_date and self.due_date < self.start_date | |
55 | errors.add :due_date, :activerecord_error_greater_than_start_date |
|
55 | errors.add :due_date, :activerecord_error_greater_than_start_date | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | if start_date && soonest_start && start_date < soonest_start |
|
58 | if start_date && soonest_start && start_date < soonest_start | |
59 | errors.add :start_date, :activerecord_error_invalid |
|
59 | errors.add :start_date, :activerecord_error_invalid | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
|
63 | def before_create | |||
|
64 | # default assignment based on category | |||
|
65 | if assigned_to.nil? && category && category.assigned_to | |||
|
66 | self.assigned_to = category.assigned_to | |||
|
67 | end | |||
|
68 | end | |||
|
69 | ||||
63 | def before_save |
|
70 | def before_save | |
64 | if @current_journal |
|
71 | if @current_journal | |
65 | # attributes changes |
|
72 | # attributes changes | |
66 | (Issue.column_names - %w(id description)).each {|c| |
|
73 | (Issue.column_names - %w(id description)).each {|c| | |
67 | @current_journal.details << JournalDetail.new(:property => 'attr', |
|
74 | @current_journal.details << JournalDetail.new(:property => 'attr', | |
68 | :prop_key => c, |
|
75 | :prop_key => c, | |
69 | :old_value => @issue_before_change.send(c), |
|
76 | :old_value => @issue_before_change.send(c), | |
70 | :value => send(c)) unless send(c)==@issue_before_change.send(c) |
|
77 | :value => send(c)) unless send(c)==@issue_before_change.send(c) | |
71 | } |
|
78 | } | |
72 | # custom fields changes |
|
79 | # custom fields changes | |
73 | custom_values.each {|c| |
|
80 | custom_values.each {|c| | |
74 | @current_journal.details << JournalDetail.new(:property => 'cf', |
|
81 | @current_journal.details << JournalDetail.new(:property => 'cf', | |
75 | :prop_key => c.custom_field_id, |
|
82 | :prop_key => c.custom_field_id, | |
76 | :old_value => @custom_values_before_change[c.custom_field_id], |
|
83 | :old_value => @custom_values_before_change[c.custom_field_id], | |
77 | :value => c.value) unless @custom_values_before_change[c.custom_field_id]==c.value |
|
84 | :value => c.value) unless @custom_values_before_change[c.custom_field_id]==c.value | |
78 | } |
|
85 | } | |
79 | @current_journal.save unless @current_journal.details.empty? and @current_journal.notes.empty? |
|
86 | @current_journal.save unless @current_journal.details.empty? and @current_journal.notes.empty? | |
80 | end |
|
87 | end | |
81 | end |
|
88 | end | |
82 |
|
89 | |||
83 | def after_save |
|
90 | def after_save | |
84 | relations_from.each(&:set_issue_to_dates) |
|
91 | relations_from.each(&:set_issue_to_dates) | |
85 | end |
|
92 | end | |
86 |
|
93 | |||
87 | def custom_value_for(custom_field) |
|
94 | def custom_value_for(custom_field) | |
88 | self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id } |
|
95 | self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id } | |
89 | return nil |
|
96 | return nil | |
90 | end |
|
97 | end | |
91 |
|
98 | |||
92 | def init_journal(user, notes = "") |
|
99 | def init_journal(user, notes = "") | |
93 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) |
|
100 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) | |
94 | @issue_before_change = self.clone |
|
101 | @issue_before_change = self.clone | |
95 | @custom_values_before_change = {} |
|
102 | @custom_values_before_change = {} | |
96 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } |
|
103 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } | |
97 | @current_journal |
|
104 | @current_journal | |
98 | end |
|
105 | end | |
99 |
|
106 | |||
100 | def spent_hours |
|
107 | def spent_hours | |
101 | @spent_hours ||= time_entries.sum(:hours) || 0 |
|
108 | @spent_hours ||= time_entries.sum(:hours) || 0 | |
102 | end |
|
109 | end | |
103 |
|
110 | |||
104 | def relations |
|
111 | def relations | |
105 | (relations_from + relations_to).sort |
|
112 | (relations_from + relations_to).sort | |
106 | end |
|
113 | end | |
107 |
|
114 | |||
108 | def all_dependent_issues |
|
115 | def all_dependent_issues | |
109 | dependencies = [] |
|
116 | dependencies = [] | |
110 | relations_from.each do |relation| |
|
117 | relations_from.each do |relation| | |
111 | dependencies << relation.issue_to |
|
118 | dependencies << relation.issue_to | |
112 | dependencies += relation.issue_to.all_dependent_issues |
|
119 | dependencies += relation.issue_to.all_dependent_issues | |
113 | end |
|
120 | end | |
114 | dependencies |
|
121 | dependencies | |
115 | end |
|
122 | end | |
116 |
|
123 | |||
117 | def duration |
|
124 | def duration | |
118 | (start_date && due_date) ? due_date - start_date : 0 |
|
125 | (start_date && due_date) ? due_date - start_date : 0 | |
119 | end |
|
126 | end | |
120 |
|
127 | |||
121 | def soonest_start |
|
128 | def soonest_start | |
122 | @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min |
|
129 | @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min | |
123 | end |
|
130 | end | |
124 | end |
|
131 | end |
@@ -1,29 +1,30 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class IssueCategory < ActiveRecord::Base |
|
18 | class IssueCategory < ActiveRecord::Base | |
19 | before_destroy :check_integrity |
|
19 | before_destroy :check_integrity | |
20 | belongs_to :project |
|
20 | belongs_to :project | |
|
21 | belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' | |||
21 |
|
22 | |||
22 | validates_presence_of :name |
|
23 | validates_presence_of :name | |
23 | validates_uniqueness_of :name, :scope => [:project_id] |
|
24 | validates_uniqueness_of :name, :scope => [:project_id] | |
24 |
|
25 | |||
25 | private |
|
26 | private | |
26 | def check_integrity |
|
27 | def check_integrity | |
27 | raise "Can't delete category" if Issue.find(:first, :conditions => ["category_id=?", self.id]) |
|
28 | raise "Can't delete category" if Issue.find(:first, :conditions => ["category_id=?", self.id]) | |
28 | end |
|
29 | end | |
29 | end |
|
30 | end |
@@ -1,29 +1,34 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Member < ActiveRecord::Base |
|
18 | class Member < ActiveRecord::Base | |
19 | belongs_to :user |
|
19 | belongs_to :user | |
20 | belongs_to :role |
|
20 | belongs_to :role | |
21 | belongs_to :project |
|
21 | belongs_to :project | |
22 |
|
22 | |||
23 | validates_presence_of :role, :user, :project |
|
23 | validates_presence_of :role, :user, :project | |
24 | validates_uniqueness_of :user_id, :scope => :project_id |
|
24 | validates_uniqueness_of :user_id, :scope => :project_id | |
25 |
|
25 | |||
26 | def name |
|
26 | def name | |
27 | self.user.display_name |
|
27 | self.user.display_name | |
28 | end |
|
28 | end | |
|
29 | ||||
|
30 | def before_destroy | |||
|
31 | # remove category based auto assignments for this member | |||
|
32 | project.issue_categories.update_all "assigned_to_id = NULL", ["assigned_to_id = ?", self.user.id] | |||
|
33 | end | |||
29 | end |
|
34 | end |
@@ -1,166 +1,167 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require "digest/sha1" |
|
18 | require "digest/sha1" | |
19 |
|
19 | |||
20 | class User < ActiveRecord::Base |
|
20 | class User < ActiveRecord::Base | |
21 | # Account statuses |
|
21 | # Account statuses | |
22 | STATUS_ACTIVE = 1 |
|
22 | STATUS_ACTIVE = 1 | |
23 | STATUS_REGISTERED = 2 |
|
23 | STATUS_REGISTERED = 2 | |
24 | STATUS_LOCKED = 3 |
|
24 | STATUS_LOCKED = 3 | |
25 |
|
25 | |||
26 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all |
|
26 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all | |
27 | has_many :projects, :through => :memberships |
|
27 | has_many :projects, :through => :memberships | |
28 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
28 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
|
29 | has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify | |||
29 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' |
|
30 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' | |
30 | has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" |
|
31 | has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" | |
31 | belongs_to :auth_source |
|
32 | belongs_to :auth_source | |
32 |
|
33 | |||
33 | attr_accessor :password, :password_confirmation |
|
34 | attr_accessor :password, :password_confirmation | |
34 | attr_accessor :last_before_login_on |
|
35 | attr_accessor :last_before_login_on | |
35 | # Prevents unauthorized assignments |
|
36 | # Prevents unauthorized assignments | |
36 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
37 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password | |
37 |
|
38 | |||
38 | validates_presence_of :login, :firstname, :lastname, :mail |
|
39 | validates_presence_of :login, :firstname, :lastname, :mail | |
39 | validates_uniqueness_of :login, :mail |
|
40 | validates_uniqueness_of :login, :mail | |
40 | # Login must contain lettres, numbers, underscores only |
|
41 | # Login must contain lettres, numbers, underscores only | |
41 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i |
|
42 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i | |
42 | validates_length_of :login, :maximum => 30 |
|
43 | validates_length_of :login, :maximum => 30 | |
43 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
44 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i | |
44 | validates_length_of :firstname, :lastname, :maximum => 30 |
|
45 | validates_length_of :firstname, :lastname, :maximum => 30 | |
45 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i |
|
46 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i | |
46 | validates_length_of :mail, :maximum => 60 |
|
47 | validates_length_of :mail, :maximum => 60 | |
47 | # Password length between 4 and 12 |
|
48 | # Password length between 4 and 12 | |
48 | validates_length_of :password, :in => 4..12, :allow_nil => true |
|
49 | validates_length_of :password, :in => 4..12, :allow_nil => true | |
49 | validates_confirmation_of :password, :allow_nil => true |
|
50 | validates_confirmation_of :password, :allow_nil => true | |
50 | validates_associated :custom_values, :on => :update |
|
51 | validates_associated :custom_values, :on => :update | |
51 |
|
52 | |||
52 | def before_save |
|
53 | def before_save | |
53 | # update hashed_password if password was set |
|
54 | # update hashed_password if password was set | |
54 | self.hashed_password = User.hash_password(self.password) if self.password |
|
55 | self.hashed_password = User.hash_password(self.password) if self.password | |
55 | end |
|
56 | end | |
56 |
|
57 | |||
57 | def self.active |
|
58 | def self.active | |
58 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do |
|
59 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do | |
59 | yield |
|
60 | yield | |
60 | end |
|
61 | end | |
61 | end |
|
62 | end | |
62 |
|
63 | |||
63 | def self.find_active(*args) |
|
64 | def self.find_active(*args) | |
64 | active do |
|
65 | active do | |
65 | find(*args) |
|
66 | find(*args) | |
66 | end |
|
67 | end | |
67 | end |
|
68 | end | |
68 |
|
69 | |||
69 | # Returns the user that matches provided login and password, or nil |
|
70 | # Returns the user that matches provided login and password, or nil | |
70 | def self.try_to_login(login, password) |
|
71 | def self.try_to_login(login, password) | |
71 | user = find(:first, :conditions => ["login=?", login]) |
|
72 | user = find(:first, :conditions => ["login=?", login]) | |
72 | if user |
|
73 | if user | |
73 | # user is already in local database |
|
74 | # user is already in local database | |
74 | return nil if !user.active? |
|
75 | return nil if !user.active? | |
75 | if user.auth_source |
|
76 | if user.auth_source | |
76 | # user has an external authentication method |
|
77 | # user has an external authentication method | |
77 | return nil unless user.auth_source.authenticate(login, password) |
|
78 | return nil unless user.auth_source.authenticate(login, password) | |
78 | else |
|
79 | else | |
79 | # authentication with local password |
|
80 | # authentication with local password | |
80 | return nil unless User.hash_password(password) == user.hashed_password |
|
81 | return nil unless User.hash_password(password) == user.hashed_password | |
81 | end |
|
82 | end | |
82 | else |
|
83 | else | |
83 | # user is not yet registered, try to authenticate with available sources |
|
84 | # user is not yet registered, try to authenticate with available sources | |
84 | attrs = AuthSource.authenticate(login, password) |
|
85 | attrs = AuthSource.authenticate(login, password) | |
85 | if attrs |
|
86 | if attrs | |
86 | onthefly = new(*attrs) |
|
87 | onthefly = new(*attrs) | |
87 | onthefly.login = login |
|
88 | onthefly.login = login | |
88 | onthefly.language = Setting.default_language |
|
89 | onthefly.language = Setting.default_language | |
89 | if onthefly.save |
|
90 | if onthefly.save | |
90 | user = find(:first, :conditions => ["login=?", login]) |
|
91 | user = find(:first, :conditions => ["login=?", login]) | |
91 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
92 | logger.info("User '#{user.login}' created on the fly.") if logger | |
92 | end |
|
93 | end | |
93 | end |
|
94 | end | |
94 | end |
|
95 | end | |
95 | user.update_attribute(:last_login_on, Time.now) if user |
|
96 | user.update_attribute(:last_login_on, Time.now) if user | |
96 | user |
|
97 | user | |
97 |
|
98 | |||
98 | rescue => text |
|
99 | rescue => text | |
99 | raise text |
|
100 | raise text | |
100 | end |
|
101 | end | |
101 |
|
102 | |||
102 | # Return user's full name for display |
|
103 | # Return user's full name for display | |
103 | def display_name |
|
104 | def display_name | |
104 | firstname + " " + lastname |
|
105 | firstname + " " + lastname | |
105 | end |
|
106 | end | |
106 |
|
107 | |||
107 | def name |
|
108 | def name | |
108 | display_name |
|
109 | display_name | |
109 | end |
|
110 | end | |
110 |
|
111 | |||
111 | def active? |
|
112 | def active? | |
112 | self.status == STATUS_ACTIVE |
|
113 | self.status == STATUS_ACTIVE | |
113 | end |
|
114 | end | |
114 |
|
115 | |||
115 | def registered? |
|
116 | def registered? | |
116 | self.status == STATUS_REGISTERED |
|
117 | self.status == STATUS_REGISTERED | |
117 | end |
|
118 | end | |
118 |
|
119 | |||
119 | def locked? |
|
120 | def locked? | |
120 | self.status == STATUS_LOCKED |
|
121 | self.status == STATUS_LOCKED | |
121 | end |
|
122 | end | |
122 |
|
123 | |||
123 | def check_password?(clear_password) |
|
124 | def check_password?(clear_password) | |
124 | User.hash_password(clear_password) == self.hashed_password |
|
125 | User.hash_password(clear_password) == self.hashed_password | |
125 | end |
|
126 | end | |
126 |
|
127 | |||
127 | def role_for_project(project) |
|
128 | def role_for_project(project) | |
128 | return nil unless project |
|
129 | return nil unless project | |
129 | member = memberships.detect {|m| m.project_id == project.id} |
|
130 | member = memberships.detect {|m| m.project_id == project.id} | |
130 | member ? member.role : nil |
|
131 | member ? member.role : nil | |
131 | end |
|
132 | end | |
132 |
|
133 | |||
133 | def authorized_to(project, action) |
|
134 | def authorized_to(project, action) | |
134 | return true if self.admin? |
|
135 | return true if self.admin? | |
135 | role = role_for_project(project) |
|
136 | role = role_for_project(project) | |
136 | role && Permission.allowed_to_role(action, role) |
|
137 | role && Permission.allowed_to_role(action, role) | |
137 | end |
|
138 | end | |
138 |
|
139 | |||
139 | def pref |
|
140 | def pref | |
140 | self.preference ||= UserPreference.new(:user => self) |
|
141 | self.preference ||= UserPreference.new(:user => self) | |
141 | end |
|
142 | end | |
142 |
|
143 | |||
143 | def get_or_create_rss_key |
|
144 | def get_or_create_rss_key | |
144 | self.rss_key || Token.create(:user => self, :action => 'feeds') |
|
145 | self.rss_key || Token.create(:user => self, :action => 'feeds') | |
145 | end |
|
146 | end | |
146 |
|
147 | |||
147 | def self.find_by_rss_key(key) |
|
148 | def self.find_by_rss_key(key) | |
148 | token = Token.find_by_value(key) |
|
149 | token = Token.find_by_value(key) | |
149 | token && token.user.active? ? token.user : nil |
|
150 | token && token.user.active? ? token.user : nil | |
150 | end |
|
151 | end | |
151 |
|
152 | |||
152 | def self.find_by_autologin_key(key) |
|
153 | def self.find_by_autologin_key(key) | |
153 | token = Token.find_by_action_and_value('autologin', key) |
|
154 | token = Token.find_by_action_and_value('autologin', key) | |
154 | token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil |
|
155 | token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil | |
155 | end |
|
156 | end | |
156 |
|
157 | |||
157 | def <=>(user) |
|
158 | def <=>(user) | |
158 | lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname |
|
159 | lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname | |
159 | end |
|
160 | end | |
160 |
|
161 | |||
161 | private |
|
162 | private | |
162 | # Return password digest |
|
163 | # Return password digest | |
163 | def self.hash_password(clear_password) |
|
164 | def self.hash_password(clear_password) | |
164 | Digest::SHA1.hexdigest(clear_password || "") |
|
165 | Digest::SHA1.hexdigest(clear_password || "") | |
165 | end |
|
166 | end | |
166 | end |
|
167 | end |
@@ -1,7 +1,6 | |||||
1 |
<%= error_messages_for ' |
|
1 | <%= error_messages_for 'category' %> | |
2 |
|
||||
3 | <!--[form:issue_category]--> |
|
|||
4 | <p><label for="issue_category_name"><%l(:field_name)%></label> |
|
|||
5 | <%= text_field 'issue_category', 'name' %></p> |
|
|||
6 | <!--[eoform:issue_category]--> |
|
|||
7 |
|
2 | |||
|
3 | <div class="box"> | |||
|
4 | <p><%= f.text_field :name, :size => 30, :required => true %></p> | |||
|
5 | <p><%= f.select :assigned_to_id, @project.users.collect{|u| [u.name, u.id]}, :include_blank => true %></p> | |||
|
6 | </div> |
@@ -1,6 +1,6 | |||||
1 | <h2><%=l(:label_issue_category)%></h2> |
|
1 | <h2><%=l(:label_issue_category)%></h2> | |
2 |
|
2 | |||
3 | <% form_tag({:action => 'edit', :id => @category}, :class => "tabular") do %> |
|
3 | <% labelled_tabular_form_for :category, @category, :url => { :action => 'edit', :id => @category } do |f| %> | |
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'issue_categories/form', :locals => { :f => f } %> | |
5 |
|
|
5 | <%= submit_tag l(:button_create) %> | |
6 | <% end %> |
|
6 | <% end %> |
@@ -1,93 +1,84 | |||||
1 | <h2><%=l(:label_settings)%></h2> |
|
1 | <h2><%=l(:label_settings)%></h2> | |
2 |
|
2 | |||
3 | <div class="tabs"> |
|
3 | <div class="tabs"> | |
4 | <ul> |
|
4 | <ul> | |
5 | <li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li> |
|
5 | <li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li> | |
6 | <li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li> |
|
6 | <li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li> | |
7 | <li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li> |
|
7 | <li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li> | |
8 | <li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li> |
|
8 | <li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li> | |
9 | <li><%= link_to l(:label_board_plural), {}, :id=> "tab-boards", :onclick => "showTab('boards'); this.blur(); return false;" %></li> |
|
9 | <li><%= link_to l(:label_board_plural), {}, :id=> "tab-boards", :onclick => "showTab('boards'); this.blur(); return false;" %></li> | |
10 | </ul> |
|
10 | </ul> | |
11 | </div> |
|
11 | </div> | |
12 |
|
12 | |||
13 | <div id="tab-content-info" class="tab-content"> |
|
13 | <div id="tab-content-info" class="tab-content"> | |
14 | <% if authorize_for('projects', 'edit') %> |
|
14 | <% if authorize_for('projects', 'edit') %> | |
15 | <% labelled_tabular_form_for :project, @project, :url => { :action => "edit", :id => @project } do |f| %> |
|
15 | <% labelled_tabular_form_for :project, @project, :url => { :action => "edit", :id => @project } do |f| %> | |
16 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
16 | <%= render :partial => 'form', :locals => { :f => f } %> | |
17 | <%= submit_tag l(:button_save) %> |
|
17 | <%= submit_tag l(:button_save) %> | |
18 | <% end %> |
|
18 | <% end %> | |
19 | <% end %> |
|
19 | <% end %> | |
20 | </div> |
|
20 | </div> | |
21 |
|
21 | |||
22 | <div id="tab-content-members" class="tab-content" style="display:none;"> |
|
22 | <div id="tab-content-members" class="tab-content" style="display:none;"> | |
23 | <%= render :partial => 'members' %> |
|
23 | <%= render :partial => 'members' %> | |
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
26 | <div id="tab-content-versions" class="tab-content" style="display:none;"> |
|
26 | <div id="tab-content-versions" class="tab-content" style="display:none;"> | |
27 | <table class="list"> |
|
27 | <table class="list"> | |
28 | <thead> |
|
28 | <thead> | |
29 | <th><%= l(:label_version) %></th> |
|
29 | <th><%= l(:label_version) %></th> | |
30 | <th><%= l(:field_effective_date) %></th> |
|
30 | <th><%= l(:field_effective_date) %></th> | |
31 | <th><%= l(:field_description) %></th> |
|
31 | <th><%= l(:field_description) %></th> | |
32 | <th><%= l(:label_wiki_page) unless @project.wiki.nil? %></th> |
|
32 | <th><%= l(:label_wiki_page) unless @project.wiki.nil? %></th> | |
33 | <th style="width:15%"></th> |
|
33 | <th style="width:15%"></th> | |
34 | <th style="width:15%"></th> |
|
34 | <th style="width:15%"></th> | |
35 | </thead> |
|
35 | </thead> | |
36 | <tbody> |
|
36 | <tbody> | |
37 | <% for version in @project.versions.sort %> |
|
37 | <% for version in @project.versions.sort %> | |
38 | <tr class="<%= cycle 'odd', 'even' %>"> |
|
38 | <tr class="<%= cycle 'odd', 'even' %>"> | |
39 | <td><%=h version.name %></td> |
|
39 | <td><%=h version.name %></td> | |
40 | <td align="center"><%= format_date(version.effective_date) %></td> |
|
40 | <td align="center"><%= format_date(version.effective_date) %></td> | |
41 | <td><%=h version.description %></td> |
|
41 | <td><%=h version.description %></td> | |
42 | <td><%= link_to(version.wiki_page_title, :controller => 'wiki', :page => Wiki.titleize(version.wiki_page_title)) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td> |
|
42 | <td><%= link_to(version.wiki_page_title, :controller => 'wiki', :page => Wiki.titleize(version.wiki_page_title)) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td> | |
43 | <td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></small></td> |
|
43 | <td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></small></td> | |
44 | <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td> |
|
44 | <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td> | |
45 | </td> |
|
45 | </td> | |
46 | </tr> |
|
46 | </tr> | |
47 | <% end; reset_cycle %> |
|
47 | <% end; reset_cycle %> | |
48 | </tbody> |
|
48 | </tbody> | |
49 | </table> |
|
49 | </table> | |
50 | |
|
50 | | |
51 | <p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p> |
|
51 | <p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p> | |
52 | </div> |
|
52 | </div> | |
53 |
|
53 | |||
54 | <div id="tab-content-categories" class="tab-content" style="display:none;"> |
|
54 | <div id="tab-content-categories" class="tab-content" style="display:none;"> | |
55 | <table class="list"> |
|
55 | <table class="list"> | |
56 | <thead><th><%= l(:label_issue_category) %></th><th style="width:15%"></th></thead> |
|
56 | <thead> | |
|
57 | <th><%= l(:label_issue_category) %></th> | |||
|
58 | <th><%= l(:field_assigned_to) %></th> | |||
|
59 | <th style="width:15%"></th> | |||
|
60 | <th style="width:15%"></th> | |||
|
61 | </thead> | |||
57 | <tbody> |
|
62 | <tbody> | |
58 |
<% for |
|
63 | <% for category in @project.issue_categories %> | |
59 |
<% unless |
|
64 | <% unless category.new_record? %> | |
60 | <tr class="<%= cycle 'odd', 'even' %>"> |
|
65 | <tr class="<%= cycle 'odd', 'even' %>"> | |
61 | <td> |
|
66 | <td><%=h(category.name) %></td> | |
62 | <% form_tag({:controller => 'issue_categories', :action => 'edit', :id => @category}) do %> |
|
67 | <td><%=h(category.assigned_to.name) if category.assigned_to %></td> | |
63 | <%= text_field 'category', 'name', :size => 25 %> |
|
68 | <td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'issue_categories', :action => 'edit', :id => category }, :class => 'icon icon-edit' %></small></td> | |
64 | <% if authorize_for('issue_categories', 'edit') %> |
|
69 | <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td> | |
65 | <%= submit_tag l(:button_save), :class => "button-small" %> |
|
|||
66 | <% end %> |
|
|||
67 | <% end %> |
|
|||
68 | </td> |
|
|||
69 | <td align="center"> |
|
|||
70 | <small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => @category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small> |
|
|||
71 | </td> |
|
|||
72 | </tr> |
|
70 | </tr> | |
73 | <% end %> |
|
71 | <% end %> | |
74 | <% end %> |
|
72 | <% end %> | |
75 | </tbody> |
|
73 | </tbody> | |
76 | </table> |
|
74 | </table> | |
77 | |
|
75 | | |
78 | <% if authorize_for('projects', 'add_issue_category') %> |
|
76 | <p><%= link_to_if_authorized l(:label_issue_category_new), :controller => 'projects', :action => 'add_issue_category', :id => @project %></p> | |
79 | <% form_tag({:action => 'add_issue_category', :tab => 'categories', :id => @project}) do %> |
|
|||
80 | <p><label for="issue_category_name"><%=l(:label_issue_category_new)%></label><br /> |
|
|||
81 | <%= error_messages_for 'issue_category' %> |
|
|||
82 | <%= text_field 'issue_category', 'name', :size => 25 %> |
|
|||
83 | <%= submit_tag l(:button_add) %></p> |
|
|||
84 | <% end %> |
|
|||
85 | <% end %> |
|
|||
86 | </div> |
|
77 | </div> | |
87 |
|
78 | |||
88 | <div id="tab-content-boards" class="tab-content" style="display:none;"> |
|
79 | <div id="tab-content-boards" class="tab-content" style="display:none;"> | |
89 | <%= render :partial => 'boards' %> |
|
80 | <%= render :partial => 'boards' %> | |
90 | </div> |
|
81 | </div> | |
91 |
|
82 | |||
92 | <%= tab = params[:tab] ? h(params[:tab]) : 'info' |
|
83 | <%= tab = params[:tab] ? h(params[:tab]) : 'info' | |
93 | javascript_tag "showTab('#{tab}');" %> No newline at end of file |
|
84 | javascript_tag "showTab('#{tab}');" %> |
@@ -1,9 +1,11 | |||||
1 | --- |
|
1 | --- | |
2 | issue_categories_001: |
|
2 | issue_categories_001: | |
3 | name: Printing |
|
3 | name: Printing | |
4 | project_id: 1 |
|
4 | project_id: 1 | |
|
5 | assigned_to_id: 2 | |||
5 | id: 1 |
|
6 | id: 1 | |
6 | issue_categories_002: |
|
7 | issue_categories_002: | |
7 | name: Recipes |
|
8 | name: Recipes | |
8 | project_id: 1 |
|
9 | project_id: 1 | |
|
10 | assigned_to_id: | |||
9 | id: 2 |
|
11 | id: 2 |
General Comments 0
You need to be logged in to leave comments.
Login now