@@ -1,556 +1,556 | |||||
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, :authorize, :except => [ :index, :list, :add ] |
|
22 | before_filter :find_project, :authorize, :except => [ :index, :list, :add ] | |
23 | before_filter :require_admin, :only => [ :add, :destroy ] |
|
23 | before_filter :require_admin, :only => [ :add, :destroy ] | |
24 |
|
24 | |||
25 | helper :sort |
|
25 | helper :sort | |
26 | include SortHelper |
|
26 | include SortHelper | |
27 | helper :custom_fields |
|
27 | helper :custom_fields | |
28 | include CustomFieldsHelper |
|
28 | include CustomFieldsHelper | |
29 | helper :ifpdf |
|
29 | helper :ifpdf | |
30 | include IfpdfHelper |
|
30 | include IfpdfHelper | |
31 | helper IssuesHelper |
|
31 | helper IssuesHelper | |
32 | helper :queries |
|
32 | helper :queries | |
33 | include QueriesHelper |
|
33 | include QueriesHelper | |
34 |
|
34 | |||
35 | def index |
|
35 | def index | |
36 | list |
|
36 | list | |
37 | render :action => 'list' unless request.xhr? |
|
37 | render :action => 'list' unless request.xhr? | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | # Lists public projects |
|
40 | # Lists public projects | |
41 | def list |
|
41 | def list | |
42 | sort_init 'name', 'asc' |
|
42 | sort_init 'name', 'asc' | |
43 | sort_update |
|
43 | sort_update | |
44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) |
|
44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) | |
45 | @project_pages = Paginator.new self, @project_count, |
|
45 | @project_pages = Paginator.new self, @project_count, | |
46 | 15, |
|
46 | 15, | |
47 | params['page'] |
|
47 | params['page'] | |
48 | @projects = Project.find :all, :order => sort_clause, |
|
48 | @projects = Project.find :all, :order => sort_clause, | |
49 | :conditions => ["is_public=?", true], |
|
49 | :conditions => ["is_public=?", true], | |
50 | :limit => @project_pages.items_per_page, |
|
50 | :limit => @project_pages.items_per_page, | |
51 | :offset => @project_pages.current.offset |
|
51 | :offset => @project_pages.current.offset | |
52 |
|
52 | |||
53 | render :action => "list", :layout => false if request.xhr? |
|
53 | render :action => "list", :layout => false if request.xhr? | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | # Add a new project |
|
56 | # Add a new project | |
57 | def add |
|
57 | def add | |
58 | @custom_fields = IssueCustomField.find(:all) |
|
58 | @custom_fields = IssueCustomField.find(:all) | |
59 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
59 | @root_projects = Project.find(:all, :conditions => "parent_id is null") | |
60 | @project = Project.new(params[:project]) |
|
60 | @project = Project.new(params[:project]) | |
61 | if request.get? |
|
61 | if request.get? | |
62 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
62 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
63 | else |
|
63 | else | |
64 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
64 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
65 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
65 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
66 | @project.custom_values = @custom_values |
|
66 | @project.custom_values = @custom_values | |
67 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
67 | if params[:repository_enabled] && params[:repository_enabled] == "1" | |
68 | @project.repository = Repository.new |
|
68 | @project.repository = Repository.new | |
69 | @project.repository.attributes = params[:repository] |
|
69 | @project.repository.attributes = params[:repository] | |
70 | end |
|
70 | end | |
71 | if @project.save |
|
71 | if @project.save | |
72 | flash[:notice] = l(:notice_successful_create) |
|
72 | flash[:notice] = l(:notice_successful_create) | |
73 | redirect_to :controller => 'admin', :action => 'projects' |
|
73 | redirect_to :controller => 'admin', :action => 'projects' | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | # Show @project |
|
78 | # Show @project | |
79 | def show |
|
79 | def show | |
80 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
80 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
81 | @members = @project.members.find(:all, :include => [:user, :role]) |
|
81 | @members = @project.members.find(:all, :include => [:user, :role]) | |
82 | @subprojects = @project.children if @project.children.size > 0 |
|
82 | @subprojects = @project.children if @project.children.size > 0 | |
83 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC") |
|
83 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC") | |
84 | @trackers = Tracker.find(:all) |
|
84 | @trackers = Tracker.find(:all) | |
85 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id", :conditions => ["project_id=? and issue_statuses.is_closed=?", @project.id, false]) |
|
85 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id", :conditions => ["project_id=? and issue_statuses.is_closed=?", @project.id, false]) | |
86 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
86 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def settings |
|
89 | def settings | |
90 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
90 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) | |
91 | @custom_fields = IssueCustomField.find(:all) |
|
91 | @custom_fields = IssueCustomField.find(:all) | |
92 | @issue_category ||= IssueCategory.new |
|
92 | @issue_category ||= IssueCategory.new | |
93 | @member ||= @project.members.new |
|
93 | @member ||= @project.members.new | |
94 | @roles = Role.find(:all) |
|
94 | @roles = Role.find(:all) | |
95 |
@users = User.find(:all) - @project. |
|
95 | @users = User.find_active(:all) - @project.users | |
96 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
96 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | # Edit @project |
|
99 | # Edit @project | |
100 | def edit |
|
100 | def edit | |
101 | if request.post? |
|
101 | if request.post? | |
102 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
102 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
103 | if params[:custom_fields] |
|
103 | if params[:custom_fields] | |
104 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
104 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
105 | @project.custom_values = @custom_values |
|
105 | @project.custom_values = @custom_values | |
106 | end |
|
106 | end | |
107 | if params[:repository_enabled] |
|
107 | if params[:repository_enabled] | |
108 | case params[:repository_enabled] |
|
108 | case params[:repository_enabled] | |
109 | when "0" |
|
109 | when "0" | |
110 | @project.repository = nil |
|
110 | @project.repository = nil | |
111 | when "1" |
|
111 | when "1" | |
112 | @project.repository ||= Repository.new |
|
112 | @project.repository ||= Repository.new | |
113 | @project.repository.attributes = params[:repository] |
|
113 | @project.repository.attributes = params[:repository] | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 | @project.attributes = params[:project] |
|
116 | @project.attributes = params[:project] | |
117 | if @project.save |
|
117 | if @project.save | |
118 | flash[:notice] = l(:notice_successful_update) |
|
118 | flash[:notice] = l(:notice_successful_update) | |
119 | redirect_to :action => 'settings', :id => @project |
|
119 | redirect_to :action => 'settings', :id => @project | |
120 | else |
|
120 | else | |
121 | settings |
|
121 | settings | |
122 | render :action => 'settings' |
|
122 | render :action => 'settings' | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | # Delete @project |
|
127 | # Delete @project | |
128 | def destroy |
|
128 | def destroy | |
129 | if request.post? and params[:confirm] |
|
129 | if request.post? and params[:confirm] | |
130 | @project.destroy |
|
130 | @project.destroy | |
131 | redirect_to :controller => 'admin', :action => 'projects' |
|
131 | redirect_to :controller => 'admin', :action => 'projects' | |
132 | end |
|
132 | end | |
133 | end |
|
133 | end | |
134 |
|
134 | |||
135 | # Add a new issue category to @project |
|
135 | # Add a new issue category to @project | |
136 | def add_issue_category |
|
136 | def add_issue_category | |
137 | if request.post? |
|
137 | if request.post? | |
138 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
138 | @issue_category = @project.issue_categories.build(params[:issue_category]) | |
139 | if @issue_category.save |
|
139 | if @issue_category.save | |
140 | flash[:notice] = l(:notice_successful_create) |
|
140 | flash[:notice] = l(:notice_successful_create) | |
141 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
141 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
142 | else |
|
142 | else | |
143 | settings |
|
143 | settings | |
144 | render :action => 'settings' |
|
144 | render :action => 'settings' | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | # Add a new version to @project |
|
149 | # Add a new version to @project | |
150 | def add_version |
|
150 | def add_version | |
151 | @version = @project.versions.build(params[:version]) |
|
151 | @version = @project.versions.build(params[:version]) | |
152 | if request.post? and @version.save |
|
152 | if request.post? and @version.save | |
153 | flash[:notice] = l(:notice_successful_create) |
|
153 | flash[:notice] = l(:notice_successful_create) | |
154 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
154 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
155 | end |
|
155 | end | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | # Add a new member to @project |
|
158 | # Add a new member to @project | |
159 | def add_member |
|
159 | def add_member | |
160 | @member = @project.members.build(params[:member]) |
|
160 | @member = @project.members.build(params[:member]) | |
161 | if request.post? |
|
161 | if request.post? | |
162 | if @member.save |
|
162 | if @member.save | |
163 | flash[:notice] = l(:notice_successful_create) |
|
163 | flash[:notice] = l(:notice_successful_create) | |
164 | redirect_to :action => 'settings', :tab => 'members', :id => @project |
|
164 | redirect_to :action => 'settings', :tab => 'members', :id => @project | |
165 | else |
|
165 | else | |
166 | settings |
|
166 | settings | |
167 | render :action => 'settings' |
|
167 | render :action => 'settings' | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | # Show members list of @project |
|
172 | # Show members list of @project | |
173 | def list_members |
|
173 | def list_members | |
174 | @members = @project.members |
|
174 | @members = @project.members | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | # Add a new document to @project |
|
177 | # Add a new document to @project | |
178 | def add_document |
|
178 | def add_document | |
179 | @categories = Enumeration::get_values('DCAT') |
|
179 | @categories = Enumeration::get_values('DCAT') | |
180 | @document = @project.documents.build(params[:document]) |
|
180 | @document = @project.documents.build(params[:document]) | |
181 | if request.post? and @document.save |
|
181 | if request.post? and @document.save | |
182 | # Save the attachments |
|
182 | # Save the attachments | |
183 | params[:attachments].each { |a| |
|
183 | params[:attachments].each { |a| | |
184 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
184 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
185 | } if params[:attachments] and params[:attachments].is_a? Array |
|
185 | } if params[:attachments] and params[:attachments].is_a? Array | |
186 | flash[:notice] = l(:notice_successful_create) |
|
186 | flash[:notice] = l(:notice_successful_create) | |
187 | redirect_to :action => 'list_documents', :id => @project |
|
187 | redirect_to :action => 'list_documents', :id => @project | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | # Show documents list of @project |
|
191 | # Show documents list of @project | |
192 | def list_documents |
|
192 | def list_documents | |
193 | @documents = @project.documents.find :all, :include => :category |
|
193 | @documents = @project.documents.find :all, :include => :category | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | # Add a new issue to @project |
|
196 | # Add a new issue to @project | |
197 | def add_issue |
|
197 | def add_issue | |
198 | @tracker = Tracker.find(params[:tracker_id]) |
|
198 | @tracker = Tracker.find(params[:tracker_id]) | |
199 | @priorities = Enumeration::get_values('IPRI') |
|
199 | @priorities = Enumeration::get_values('IPRI') | |
200 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
200 | @issue = Issue.new(:project => @project, :tracker => @tracker) | |
201 | if request.get? |
|
201 | if request.get? | |
202 | @issue.start_date = Date.today |
|
202 | @issue.start_date = Date.today | |
203 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
203 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
204 | else |
|
204 | else | |
205 | @issue.attributes = params[:issue] |
|
205 | @issue.attributes = params[:issue] | |
206 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
206 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
207 | # Multiple file upload |
|
207 | # Multiple file upload | |
208 | @attachments = [] |
|
208 | @attachments = [] | |
209 | params[:attachments].each { |a| |
|
209 | params[:attachments].each { |a| | |
210 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
210 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
211 | } if params[:attachments] and params[:attachments].is_a? Array |
|
211 | } if params[:attachments] and params[:attachments].is_a? Array | |
212 | @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]) } |
|
212 | @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]) } | |
213 | @issue.custom_values = @custom_values |
|
213 | @issue.custom_values = @custom_values | |
214 | if @issue.save |
|
214 | if @issue.save | |
215 | @attachments.each(&:save) |
|
215 | @attachments.each(&:save) | |
216 | flash[:notice] = l(:notice_successful_create) |
|
216 | flash[:notice] = l(:notice_successful_create) | |
217 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
217 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
218 | redirect_to :action => 'list_issues', :id => @project |
|
218 | redirect_to :action => 'list_issues', :id => @project | |
219 | end |
|
219 | end | |
220 | end |
|
220 | end | |
221 | end |
|
221 | end | |
222 |
|
222 | |||
223 | # Show filtered/sorted issues list of @project |
|
223 | # Show filtered/sorted issues list of @project | |
224 | def list_issues |
|
224 | def list_issues | |
225 | sort_init 'issues.id', 'desc' |
|
225 | sort_init 'issues.id', 'desc' | |
226 | sort_update |
|
226 | sort_update | |
227 |
|
227 | |||
228 | retrieve_query |
|
228 | retrieve_query | |
229 |
|
229 | |||
230 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
230 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
231 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
231 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
232 | @results_per_page = params[:per_page].to_i |
|
232 | @results_per_page = params[:per_page].to_i | |
233 | session[:results_per_page] = @results_per_page |
|
233 | session[:results_per_page] = @results_per_page | |
234 | else |
|
234 | else | |
235 | @results_per_page = session[:results_per_page] || 25 |
|
235 | @results_per_page = session[:results_per_page] || 25 | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
238 | if @query.valid? |
|
238 | if @query.valid? | |
239 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
239 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
240 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
240 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
241 | @issues = Issue.find :all, :order => sort_clause, |
|
241 | @issues = Issue.find :all, :order => sort_clause, | |
242 | :include => [ :author, :status, :tracker, :project ], |
|
242 | :include => [ :author, :status, :tracker, :project ], | |
243 | :conditions => @query.statement, |
|
243 | :conditions => @query.statement, | |
244 | :limit => @issue_pages.items_per_page, |
|
244 | :limit => @issue_pages.items_per_page, | |
245 | :offset => @issue_pages.current.offset |
|
245 | :offset => @issue_pages.current.offset | |
246 | end |
|
246 | end | |
247 | @trackers = Tracker.find :all |
|
247 | @trackers = Tracker.find :all | |
248 | render :layout => false if request.xhr? |
|
248 | render :layout => false if request.xhr? | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | # Export filtered/sorted issues list to CSV |
|
251 | # Export filtered/sorted issues list to CSV | |
252 | def export_issues_csv |
|
252 | def export_issues_csv | |
253 | sort_init 'issues.id', 'desc' |
|
253 | sort_init 'issues.id', 'desc' | |
254 | sort_update |
|
254 | sort_update | |
255 |
|
255 | |||
256 | retrieve_query |
|
256 | retrieve_query | |
257 | render :action => 'list_issues' and return unless @query.valid? |
|
257 | render :action => 'list_issues' and return unless @query.valid? | |
258 |
|
258 | |||
259 | @issues = Issue.find :all, :order => sort_clause, |
|
259 | @issues = Issue.find :all, :order => sort_clause, | |
260 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], |
|
260 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], | |
261 | :conditions => @query.statement |
|
261 | :conditions => @query.statement | |
262 |
|
262 | |||
263 | ic = Iconv.new('ISO-8859-1', 'UTF-8') |
|
263 | ic = Iconv.new('ISO-8859-1', 'UTF-8') | |
264 | export = StringIO.new |
|
264 | export = StringIO.new | |
265 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
265 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
266 | # csv header fields |
|
266 | # csv header fields | |
267 | headers = [ "#", l(:field_status), |
|
267 | headers = [ "#", l(:field_status), | |
268 | l(:field_tracker), |
|
268 | l(:field_tracker), | |
269 | l(:field_priority), |
|
269 | l(:field_priority), | |
270 | l(:field_subject), |
|
270 | l(:field_subject), | |
271 | l(:field_author), |
|
271 | l(:field_author), | |
272 | l(:field_start_date), |
|
272 | l(:field_start_date), | |
273 | l(:field_due_date), |
|
273 | l(:field_due_date), | |
274 | l(:field_done_ratio), |
|
274 | l(:field_done_ratio), | |
275 | l(:field_created_on), |
|
275 | l(:field_created_on), | |
276 | l(:field_updated_on) |
|
276 | l(:field_updated_on) | |
277 | ] |
|
277 | ] | |
278 | for custom_field in @project.all_custom_fields |
|
278 | for custom_field in @project.all_custom_fields | |
279 | headers << custom_field.name |
|
279 | headers << custom_field.name | |
280 | end |
|
280 | end | |
281 | csv << headers.collect {|c| ic.iconv(c) } |
|
281 | csv << headers.collect {|c| ic.iconv(c) } | |
282 | # csv lines |
|
282 | # csv lines | |
283 | @issues.each do |issue| |
|
283 | @issues.each do |issue| | |
284 | fields = [issue.id, issue.status.name, |
|
284 | fields = [issue.id, issue.status.name, | |
285 | issue.tracker.name, |
|
285 | issue.tracker.name, | |
286 | issue.priority.name, |
|
286 | issue.priority.name, | |
287 | issue.subject, |
|
287 | issue.subject, | |
288 | issue.author.display_name, |
|
288 | issue.author.display_name, | |
289 | issue.start_date ? l_date(issue.start_date) : nil, |
|
289 | issue.start_date ? l_date(issue.start_date) : nil, | |
290 | issue.due_date ? l_date(issue.due_date) : nil, |
|
290 | issue.due_date ? l_date(issue.due_date) : nil, | |
291 | issue.done_ratio, |
|
291 | issue.done_ratio, | |
292 | l_datetime(issue.created_on), |
|
292 | l_datetime(issue.created_on), | |
293 | l_datetime(issue.updated_on) |
|
293 | l_datetime(issue.updated_on) | |
294 | ] |
|
294 | ] | |
295 | for custom_field in @project.all_custom_fields |
|
295 | for custom_field in @project.all_custom_fields | |
296 | fields << (show_value issue.custom_value_for(custom_field)) |
|
296 | fields << (show_value issue.custom_value_for(custom_field)) | |
297 | end |
|
297 | end | |
298 | csv << fields.collect {|c| ic.iconv(c.to_s) } |
|
298 | csv << fields.collect {|c| ic.iconv(c.to_s) } | |
299 | end |
|
299 | end | |
300 | end |
|
300 | end | |
301 | export.rewind |
|
301 | export.rewind | |
302 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
302 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
303 | end |
|
303 | end | |
304 |
|
304 | |||
305 | # Export filtered/sorted issues to PDF |
|
305 | # Export filtered/sorted issues to PDF | |
306 | def export_issues_pdf |
|
306 | def export_issues_pdf | |
307 | sort_init 'issues.id', 'desc' |
|
307 | sort_init 'issues.id', 'desc' | |
308 | sort_update |
|
308 | sort_update | |
309 |
|
309 | |||
310 | retrieve_query |
|
310 | retrieve_query | |
311 | render :action => 'list_issues' and return unless @query.valid? |
|
311 | render :action => 'list_issues' and return unless @query.valid? | |
312 |
|
312 | |||
313 | @issues = Issue.find :all, :order => sort_clause, |
|
313 | @issues = Issue.find :all, :order => sort_clause, | |
314 | :include => [ :author, :status, :tracker, :project, :custom_values ], |
|
314 | :include => [ :author, :status, :tracker, :project, :custom_values ], | |
315 | :conditions => @query.statement |
|
315 | :conditions => @query.statement | |
316 |
|
316 | |||
317 | @options_for_rfpdf ||= {} |
|
317 | @options_for_rfpdf ||= {} | |
318 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
318 | @options_for_rfpdf[:file_name] = "export.pdf" | |
319 | render :layout => false |
|
319 | render :layout => false | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | def move_issues |
|
322 | def move_issues | |
323 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
323 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
324 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
324 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
325 | @projects = [] |
|
325 | @projects = [] | |
326 | # find projects to which the user is allowed to move the issue |
|
326 | # find projects to which the user is allowed to move the issue | |
327 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)} |
|
327 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)} | |
328 | # issue can be moved to any tracker |
|
328 | # issue can be moved to any tracker | |
329 | @trackers = Tracker.find(:all) |
|
329 | @trackers = Tracker.find(:all) | |
330 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
330 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
331 | new_project = Project.find(params[:new_project_id]) |
|
331 | new_project = Project.find(params[:new_project_id]) | |
332 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
332 | new_tracker = Tracker.find(params[:new_tracker_id]) | |
333 | @issues.each { |i| |
|
333 | @issues.each { |i| | |
334 | # project dependent properties |
|
334 | # project dependent properties | |
335 | unless i.project_id == new_project.id |
|
335 | unless i.project_id == new_project.id | |
336 | i.category = nil |
|
336 | i.category = nil | |
337 | i.fixed_version = nil |
|
337 | i.fixed_version = nil | |
338 | end |
|
338 | end | |
339 | # move the issue |
|
339 | # move the issue | |
340 | i.project = new_project |
|
340 | i.project = new_project | |
341 | i.tracker = new_tracker |
|
341 | i.tracker = new_tracker | |
342 | i.save |
|
342 | i.save | |
343 | } |
|
343 | } | |
344 | flash[:notice] = l(:notice_successful_update) |
|
344 | flash[:notice] = l(:notice_successful_update) | |
345 | redirect_to :action => 'list_issues', :id => @project |
|
345 | redirect_to :action => 'list_issues', :id => @project | |
346 | end |
|
346 | end | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def add_query |
|
349 | def add_query | |
350 | @query = Query.new(params[:query]) |
|
350 | @query = Query.new(params[:query]) | |
351 | @query.project = @project |
|
351 | @query.project = @project | |
352 | @query.user = logged_in_user |
|
352 | @query.user = logged_in_user | |
353 |
|
353 | |||
354 | params[:fields].each do |field| |
|
354 | params[:fields].each do |field| | |
355 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
355 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
356 | end if params[:fields] |
|
356 | end if params[:fields] | |
357 |
|
357 | |||
358 | if request.post? and @query.save |
|
358 | if request.post? and @query.save | |
359 | flash[:notice] = l(:notice_successful_create) |
|
359 | flash[:notice] = l(:notice_successful_create) | |
360 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project |
|
360 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project | |
361 | end |
|
361 | end | |
362 | render :layout => false if request.xhr? |
|
362 | render :layout => false if request.xhr? | |
363 | end |
|
363 | end | |
364 |
|
364 | |||
365 | # Add a news to @project |
|
365 | # Add a news to @project | |
366 | def add_news |
|
366 | def add_news | |
367 | @news = News.new(:project => @project) |
|
367 | @news = News.new(:project => @project) | |
368 | if request.post? |
|
368 | if request.post? | |
369 | @news.attributes = params[:news] |
|
369 | @news.attributes = params[:news] | |
370 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
370 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
371 | if @news.save |
|
371 | if @news.save | |
372 | flash[:notice] = l(:notice_successful_create) |
|
372 | flash[:notice] = l(:notice_successful_create) | |
373 | redirect_to :action => 'list_news', :id => @project |
|
373 | redirect_to :action => 'list_news', :id => @project | |
374 | end |
|
374 | end | |
375 | end |
|
375 | end | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | # Show news list of @project |
|
378 | # Show news list of @project | |
379 | def list_news |
|
379 | def list_news | |
380 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC" |
|
380 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC" | |
381 | render :action => "list_news", :layout => false if request.xhr? |
|
381 | render :action => "list_news", :layout => false if request.xhr? | |
382 | end |
|
382 | end | |
383 |
|
383 | |||
384 | def add_file |
|
384 | def add_file | |
385 | if request.post? |
|
385 | if request.post? | |
386 | @version = @project.versions.find_by_id(params[:version_id]) |
|
386 | @version = @project.versions.find_by_id(params[:version_id]) | |
387 | # Save the attachments |
|
387 | # Save the attachments | |
388 | params[:attachments].each { |a| |
|
388 | params[:attachments].each { |a| | |
389 | Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0 |
|
389 | Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0 | |
390 | } if params[:attachments] and params[:attachments].is_a? Array |
|
390 | } if params[:attachments] and params[:attachments].is_a? Array | |
391 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
391 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
392 | end |
|
392 | end | |
393 | @versions = @project.versions |
|
393 | @versions = @project.versions | |
394 | end |
|
394 | end | |
395 |
|
395 | |||
396 | def list_files |
|
396 | def list_files | |
397 | @versions = @project.versions |
|
397 | @versions = @project.versions | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | # Show changelog for @project |
|
400 | # Show changelog for @project | |
401 | def changelog |
|
401 | def changelog | |
402 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true]) |
|
402 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true]) | |
403 | if request.get? |
|
403 | if request.get? | |
404 | @selected_tracker_ids = @trackers.collect {|t| t.id.to_s } |
|
404 | @selected_tracker_ids = @trackers.collect {|t| t.id.to_s } | |
405 | else |
|
405 | else | |
406 | @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array |
|
406 | @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array | |
407 | end |
|
407 | end | |
408 | @selected_tracker_ids ||= [] |
|
408 | @selected_tracker_ids ||= [] | |
409 | @fixed_issues = @project.issues.find(:all, |
|
409 | @fixed_issues = @project.issues.find(:all, | |
410 | :include => [ :fixed_version, :status, :tracker ], |
|
410 | :include => [ :fixed_version, :status, :tracker ], | |
411 | :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true], |
|
411 | :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true], | |
412 | :order => "versions.effective_date DESC, issues.id DESC" |
|
412 | :order => "versions.effective_date DESC, issues.id DESC" | |
413 | ) unless @selected_tracker_ids.empty? |
|
413 | ) unless @selected_tracker_ids.empty? | |
414 | @fixed_issues ||= [] |
|
414 | @fixed_issues ||= [] | |
415 | end |
|
415 | end | |
416 |
|
416 | |||
417 | def activity |
|
417 | def activity | |
418 | if params[:year] and params[:year].to_i > 1900 |
|
418 | if params[:year] and params[:year].to_i > 1900 | |
419 | @year = params[:year].to_i |
|
419 | @year = params[:year].to_i | |
420 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
420 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
421 | @month = params[:month].to_i |
|
421 | @month = params[:month].to_i | |
422 | end |
|
422 | end | |
423 | end |
|
423 | end | |
424 | @year ||= Date.today.year |
|
424 | @year ||= Date.today.year | |
425 | @month ||= Date.today.month |
|
425 | @month ||= Date.today.month | |
426 |
|
426 | |||
427 | @date_from = Date.civil(@year, @month, 1) |
|
427 | @date_from = Date.civil(@year, @month, 1) | |
428 | @date_to = (@date_from >> 1)-1 |
|
428 | @date_to = (@date_from >> 1)-1 | |
429 |
|
429 | |||
430 | @events_by_day = {} |
|
430 | @events_by_day = {} | |
431 |
|
431 | |||
432 | unless params[:show_issues] == "0" |
|
432 | unless params[:show_issues] == "0" | |
433 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i| |
|
433 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i| | |
434 | @events_by_day[i.created_on.to_date] ||= [] |
|
434 | @events_by_day[i.created_on.to_date] ||= [] | |
435 | @events_by_day[i.created_on.to_date] << i |
|
435 | @events_by_day[i.created_on.to_date] << i | |
436 | } |
|
436 | } | |
437 | @show_issues = 1 |
|
437 | @show_issues = 1 | |
438 | end |
|
438 | end | |
439 |
|
439 | |||
440 | unless params[:show_news] == "0" |
|
440 | unless params[:show_news] == "0" | |
441 | @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
441 | @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| | |
442 | @events_by_day[i.created_on.to_date] ||= [] |
|
442 | @events_by_day[i.created_on.to_date] ||= [] | |
443 | @events_by_day[i.created_on.to_date] << i |
|
443 | @events_by_day[i.created_on.to_date] << i | |
444 | } |
|
444 | } | |
445 | @show_news = 1 |
|
445 | @show_news = 1 | |
446 | end |
|
446 | end | |
447 |
|
447 | |||
448 | unless params[:show_files] == "0" |
|
448 | unless params[:show_files] == "0" | |
449 | Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| |
|
449 | Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| | |
450 | @events_by_day[i.created_on.to_date] ||= [] |
|
450 | @events_by_day[i.created_on.to_date] ||= [] | |
451 | @events_by_day[i.created_on.to_date] << i |
|
451 | @events_by_day[i.created_on.to_date] << i | |
452 | } |
|
452 | } | |
453 | @show_files = 1 |
|
453 | @show_files = 1 | |
454 | end |
|
454 | end | |
455 |
|
455 | |||
456 | unless params[:show_documents] == "0" |
|
456 | unless params[:show_documents] == "0" | |
457 | @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i| |
|
457 | @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i| | |
458 | @events_by_day[i.created_on.to_date] ||= [] |
|
458 | @events_by_day[i.created_on.to_date] ||= [] | |
459 | @events_by_day[i.created_on.to_date] << i |
|
459 | @events_by_day[i.created_on.to_date] << i | |
460 | } |
|
460 | } | |
461 | Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| |
|
461 | Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| | |
462 | @events_by_day[i.created_on.to_date] ||= [] |
|
462 | @events_by_day[i.created_on.to_date] ||= [] | |
463 | @events_by_day[i.created_on.to_date] << i |
|
463 | @events_by_day[i.created_on.to_date] << i | |
464 | } |
|
464 | } | |
465 | @show_documents = 1 |
|
465 | @show_documents = 1 | |
466 | end |
|
466 | end | |
467 |
|
467 | |||
468 | render :layout => false if request.xhr? |
|
468 | render :layout => false if request.xhr? | |
469 | end |
|
469 | end | |
470 |
|
470 | |||
471 | def calendar |
|
471 | def calendar | |
472 | if params[:year] and params[:year].to_i > 1900 |
|
472 | if params[:year] and params[:year].to_i > 1900 | |
473 | @year = params[:year].to_i |
|
473 | @year = params[:year].to_i | |
474 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
474 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
475 | @month = params[:month].to_i |
|
475 | @month = params[:month].to_i | |
476 | end |
|
476 | end | |
477 | end |
|
477 | end | |
478 | @year ||= Date.today.year |
|
478 | @year ||= Date.today.year | |
479 | @month ||= Date.today.month |
|
479 | @month ||= Date.today.month | |
480 |
|
480 | |||
481 | @date_from = Date.civil(@year, @month, 1) |
|
481 | @date_from = Date.civil(@year, @month, 1) | |
482 | @date_to = (@date_from >> 1)-1 |
|
482 | @date_to = (@date_from >> 1)-1 | |
483 | # start on monday |
|
483 | # start on monday | |
484 | @date_from = @date_from - (@date_from.cwday-1) |
|
484 | @date_from = @date_from - (@date_from.cwday-1) | |
485 | # finish on sunday |
|
485 | # finish on sunday | |
486 | @date_to = @date_to + (7-@date_to.cwday) |
|
486 | @date_to = @date_to + (7-@date_to.cwday) | |
487 |
|
487 | |||
488 | @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to]) |
|
488 | @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to]) | |
489 | render :layout => false if request.xhr? |
|
489 | render :layout => false if request.xhr? | |
490 | end |
|
490 | end | |
491 |
|
491 | |||
492 | def gantt |
|
492 | def gantt | |
493 | if params[:year] and params[:year].to_i >0 |
|
493 | if params[:year] and params[:year].to_i >0 | |
494 | @year_from = params[:year].to_i |
|
494 | @year_from = params[:year].to_i | |
495 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
495 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
496 | @month_from = params[:month].to_i |
|
496 | @month_from = params[:month].to_i | |
497 | else |
|
497 | else | |
498 | @month_from = 1 |
|
498 | @month_from = 1 | |
499 | end |
|
499 | end | |
500 | else |
|
500 | else | |
501 | @month_from ||= (Date.today << 1).month |
|
501 | @month_from ||= (Date.today << 1).month | |
502 | @year_from ||= (Date.today << 1).year |
|
502 | @year_from ||= (Date.today << 1).year | |
503 | end |
|
503 | end | |
504 |
|
504 | |||
505 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
505 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 | |
506 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
506 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 | |
507 |
|
507 | |||
508 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
508 | @date_from = Date.civil(@year_from, @month_from, 1) | |
509 | @date_to = (@date_from >> @months) - 1 |
|
509 | @date_to = (@date_from >> @months) - 1 | |
510 | @issues = @project.issues.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :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)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]) |
|
510 | @issues = @project.issues.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :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)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]) | |
511 |
|
511 | |||
512 | if params[:output]=='pdf' |
|
512 | if params[:output]=='pdf' | |
513 | @options_for_rfpdf ||= {} |
|
513 | @options_for_rfpdf ||= {} | |
514 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
514 | @options_for_rfpdf[:file_name] = "gantt.pdf" | |
515 | render :template => "projects/gantt.rfpdf", :layout => false |
|
515 | render :template => "projects/gantt.rfpdf", :layout => false | |
516 | else |
|
516 | else | |
517 | render :template => "projects/gantt.rhtml" |
|
517 | render :template => "projects/gantt.rhtml" | |
518 | end |
|
518 | end | |
519 | end |
|
519 | end | |
520 |
|
520 | |||
521 | private |
|
521 | private | |
522 | # Find project of id params[:id] |
|
522 | # Find project of id params[:id] | |
523 | # if not found, redirect to project list |
|
523 | # if not found, redirect to project list | |
524 | # Used as a before_filter |
|
524 | # Used as a before_filter | |
525 | def find_project |
|
525 | def find_project | |
526 | @project = Project.find(params[:id]) |
|
526 | @project = Project.find(params[:id]) | |
527 | @html_title = @project.name |
|
527 | @html_title = @project.name | |
528 | rescue ActiveRecord::RecordNotFound |
|
528 | rescue ActiveRecord::RecordNotFound | |
529 | render_404 |
|
529 | render_404 | |
530 | end |
|
530 | end | |
531 |
|
531 | |||
532 | # Retrieve query from session or build a new query |
|
532 | # Retrieve query from session or build a new query | |
533 | def retrieve_query |
|
533 | def retrieve_query | |
534 | if params[:query_id] |
|
534 | if params[:query_id] | |
535 | @query = @project.queries.find(params[:query_id]) |
|
535 | @query = @project.queries.find(params[:query_id]) | |
536 | else |
|
536 | else | |
537 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
537 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id | |
538 | # Give it a name, required to be valid |
|
538 | # Give it a name, required to be valid | |
539 | @query = Query.new(:name => "_") |
|
539 | @query = Query.new(:name => "_") | |
540 | @query.project = @project |
|
540 | @query.project = @project | |
541 | if params[:fields] and params[:fields].is_a? Array |
|
541 | if params[:fields] and params[:fields].is_a? Array | |
542 | params[:fields].each do |field| |
|
542 | params[:fields].each do |field| | |
543 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
543 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
544 | end |
|
544 | end | |
545 | else |
|
545 | else | |
546 | @query.available_filters.keys.each do |field| |
|
546 | @query.available_filters.keys.each do |field| | |
547 | @query.add_short_filter(field, params[field]) if params[field] |
|
547 | @query.add_short_filter(field, params[field]) if params[field] | |
548 | end |
|
548 | end | |
549 | end |
|
549 | end | |
550 | session[:query] = @query |
|
550 | session[:query] = @query | |
551 | else |
|
551 | else | |
552 | @query = session[:query] |
|
552 | @query = session[:query] | |
553 | end |
|
553 | end | |
554 | end |
|
554 | end | |
555 | end |
|
555 | end | |
556 | end |
|
556 | end |
@@ -1,130 +1,142 | |||||
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 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => :delete_all |
|
21 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => :delete_all | |
22 | has_many :projects, :through => :memberships |
|
22 | has_many :projects, :through => :memberships | |
23 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
23 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
24 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' |
|
24 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' | |
25 | belongs_to :auth_source |
|
25 | belongs_to :auth_source | |
26 |
|
26 | |||
27 | attr_accessor :password, :password_confirmation |
|
27 | attr_accessor :password, :password_confirmation | |
28 | attr_accessor :last_before_login_on |
|
28 | attr_accessor :last_before_login_on | |
29 | # Prevents unauthorized assignments |
|
29 | # Prevents unauthorized assignments | |
30 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
30 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password | |
31 |
|
31 | |||
32 | validates_presence_of :login, :firstname, :lastname, :mail |
|
32 | validates_presence_of :login, :firstname, :lastname, :mail | |
33 | validates_uniqueness_of :login, :mail |
|
33 | validates_uniqueness_of :login, :mail | |
34 | # Login must contain lettres, numbers, underscores only |
|
34 | # Login must contain lettres, numbers, underscores only | |
35 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
35 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i | |
36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i |
|
36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i | |
37 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i |
|
37 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i | |
38 | # Password length between 4 and 12 |
|
38 | # Password length between 4 and 12 | |
39 | validates_length_of :password, :in => 4..12, :allow_nil => true |
|
39 | validates_length_of :password, :in => 4..12, :allow_nil => true | |
40 | validates_confirmation_of :password, :allow_nil => true |
|
40 | validates_confirmation_of :password, :allow_nil => true | |
41 | validates_associated :custom_values, :on => :update |
|
41 | validates_associated :custom_values, :on => :update | |
42 |
|
42 | |||
43 | # Account statuses |
|
43 | # Account statuses | |
44 | STATUS_ACTIVE = 1 |
|
44 | STATUS_ACTIVE = 1 | |
45 | STATUS_REGISTERED = 2 |
|
45 | STATUS_REGISTERED = 2 | |
46 | STATUS_LOCKED = 3 |
|
46 | STATUS_LOCKED = 3 | |
47 |
|
47 | |||
48 | def before_save |
|
48 | def before_save | |
49 | # update hashed_password if password was set |
|
49 | # update hashed_password if password was set | |
50 | self.hashed_password = User.hash_password(self.password) if self.password |
|
50 | self.hashed_password = User.hash_password(self.password) if self.password | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
|
53 | def self.active | |||
|
54 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do | |||
|
55 | yield | |||
|
56 | end | |||
|
57 | end | |||
|
58 | ||||
|
59 | def self.find_active(*args) | |||
|
60 | active do | |||
|
61 | find(*args) | |||
|
62 | end | |||
|
63 | end | |||
|
64 | ||||
53 | # Returns the user that matches provided login and password, or nil |
|
65 | # Returns the user that matches provided login and password, or nil | |
54 | def self.try_to_login(login, password) |
|
66 | def self.try_to_login(login, password) | |
55 | user = find(:first, :conditions => ["login=?", login]) |
|
67 | user = find(:first, :conditions => ["login=?", login]) | |
56 | if user |
|
68 | if user | |
57 | # user is already in local database |
|
69 | # user is already in local database | |
58 | return nil if !user.active? |
|
70 | return nil if !user.active? | |
59 | if user.auth_source |
|
71 | if user.auth_source | |
60 | # user has an external authentication method |
|
72 | # user has an external authentication method | |
61 | return nil unless user.auth_source.authenticate(login, password) |
|
73 | return nil unless user.auth_source.authenticate(login, password) | |
62 | else |
|
74 | else | |
63 | # authentication with local password |
|
75 | # authentication with local password | |
64 | return nil unless User.hash_password(password) == user.hashed_password |
|
76 | return nil unless User.hash_password(password) == user.hashed_password | |
65 | end |
|
77 | end | |
66 | else |
|
78 | else | |
67 | # user is not yet registered, try to authenticate with available sources |
|
79 | # user is not yet registered, try to authenticate with available sources | |
68 | attrs = AuthSource.authenticate(login, password) |
|
80 | attrs = AuthSource.authenticate(login, password) | |
69 | if attrs |
|
81 | if attrs | |
70 | onthefly = new(*attrs) |
|
82 | onthefly = new(*attrs) | |
71 | onthefly.login = login |
|
83 | onthefly.login = login | |
72 | onthefly.language = Setting.default_language |
|
84 | onthefly.language = Setting.default_language | |
73 | if onthefly.save |
|
85 | if onthefly.save | |
74 | user = find(:first, :conditions => ["login=?", login]) |
|
86 | user = find(:first, :conditions => ["login=?", login]) | |
75 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
87 | logger.info("User '#{user.login}' created on the fly.") if logger | |
76 | end |
|
88 | end | |
77 | end |
|
89 | end | |
78 | end |
|
90 | end | |
79 | user.update_attribute(:last_login_on, Time.now) if user |
|
91 | user.update_attribute(:last_login_on, Time.now) if user | |
80 | user |
|
92 | user | |
81 |
|
93 | |||
82 | rescue => text |
|
94 | rescue => text | |
83 | raise text |
|
95 | raise text | |
84 | end |
|
96 | end | |
85 |
|
97 | |||
86 | # Return user's full name for display |
|
98 | # Return user's full name for display | |
87 | def display_name |
|
99 | def display_name | |
88 | firstname + " " + lastname |
|
100 | firstname + " " + lastname | |
89 | end |
|
101 | end | |
90 |
|
102 | |||
91 | def name |
|
103 | def name | |
92 | display_name |
|
104 | display_name | |
93 | end |
|
105 | end | |
94 |
|
106 | |||
95 | def active? |
|
107 | def active? | |
96 | self.status == STATUS_ACTIVE |
|
108 | self.status == STATUS_ACTIVE | |
97 | end |
|
109 | end | |
98 |
|
110 | |||
99 | def registered? |
|
111 | def registered? | |
100 | self.status == STATUS_REGISTERED |
|
112 | self.status == STATUS_REGISTERED | |
101 | end |
|
113 | end | |
102 |
|
114 | |||
103 | def locked? |
|
115 | def locked? | |
104 | self.status == STATUS_LOCKED |
|
116 | self.status == STATUS_LOCKED | |
105 | end |
|
117 | end | |
106 |
|
118 | |||
107 | def check_password?(clear_password) |
|
119 | def check_password?(clear_password) | |
108 | User.hash_password(clear_password) == self.hashed_password |
|
120 | User.hash_password(clear_password) == self.hashed_password | |
109 | end |
|
121 | end | |
110 |
|
122 | |||
111 | def role_for_project(project_id) |
|
123 | def role_for_project(project_id) | |
112 | @role_for_projects ||= |
|
124 | @role_for_projects ||= | |
113 | begin |
|
125 | begin | |
114 | roles = {} |
|
126 | roles = {} | |
115 | self.memberships.each { |m| roles.store m.project_id, m.role_id } |
|
127 | self.memberships.each { |m| roles.store m.project_id, m.role_id } | |
116 | roles |
|
128 | roles | |
117 | end |
|
129 | end | |
118 | @role_for_projects[project_id] |
|
130 | @role_for_projects[project_id] | |
119 | end |
|
131 | end | |
120 |
|
132 | |||
121 | def pref |
|
133 | def pref | |
122 | self.preference ||= UserPreference.new(:user => self) |
|
134 | self.preference ||= UserPreference.new(:user => self) | |
123 | end |
|
135 | end | |
124 |
|
136 | |||
125 | private |
|
137 | private | |
126 | # Return password digest |
|
138 | # Return password digest | |
127 | def self.hash_password(clear_password) |
|
139 | def self.hash_password(clear_password) | |
128 | Digest::SHA1.hexdigest(clear_password || "") |
|
140 | Digest::SHA1.hexdigest(clear_password || "") | |
129 | end |
|
141 | end | |
130 | end |
|
142 | end |
General Comments 0
You need to be logged in to leave comments.
Login now