@@ -1,147 +1,147 | |||||
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 ApplicationController < ActionController::Base |
|
18 | class ApplicationController < ActionController::Base | |
19 | before_filter :check_if_login_required, :set_localization |
|
19 | before_filter :check_if_login_required, :set_localization | |
20 | filter_parameter_logging :password |
|
20 | filter_parameter_logging :password | |
21 |
|
21 | |||
22 | def logged_in_user=(user) |
|
22 | def logged_in_user=(user) | |
23 | @logged_in_user = user |
|
23 | @logged_in_user = user | |
24 | session[:user_id] = (user ? user.id : nil) |
|
24 | session[:user_id] = (user ? user.id : nil) | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def logged_in_user |
|
27 | def logged_in_user | |
28 | if session[:user_id] |
|
28 | if session[:user_id] | |
29 | @logged_in_user ||= User.find(session[:user_id]) |
|
29 | @logged_in_user ||= User.find(session[:user_id]) | |
30 | else |
|
30 | else | |
31 | nil |
|
31 | nil | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def logged_in_user_membership |
|
35 | def logged_in_user_membership | |
36 | @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id]) |
|
36 | @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id]) | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | # check if login is globally required to access the application |
|
39 | # check if login is globally required to access the application | |
40 | def check_if_login_required |
|
40 | def check_if_login_required | |
41 | require_login if Setting.login_required? |
|
41 | require_login if Setting.login_required? | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def set_localization |
|
44 | def set_localization | |
45 | lang = begin |
|
45 | lang = begin | |
46 | if self.logged_in_user and self.logged_in_user.language and !self.logged_in_user.language.empty? and GLoc.valid_languages.include? self.logged_in_user.language.to_sym |
|
46 | if self.logged_in_user and self.logged_in_user.language and !self.logged_in_user.language.empty? and GLoc.valid_languages.include? self.logged_in_user.language.to_sym | |
47 | self.logged_in_user.language |
|
47 | self.logged_in_user.language | |
48 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] |
|
48 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] | |
49 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first |
|
49 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first | |
50 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym |
|
50 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym | |
51 | accept_lang |
|
51 | accept_lang | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | rescue |
|
54 | rescue | |
55 | nil |
|
55 | nil | |
56 | end || Setting.default_language |
|
56 | end || Setting.default_language | |
57 | set_language_if_valid(lang) |
|
57 | set_language_if_valid(lang) | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def require_login |
|
60 | def require_login | |
61 | unless self.logged_in_user |
|
61 | unless self.logged_in_user | |
62 | store_location |
|
62 | store_location | |
63 | redirect_to :controller => "account", :action => "login" |
|
63 | redirect_to :controller => "account", :action => "login" | |
64 | return false |
|
64 | return false | |
65 | end |
|
65 | end | |
66 | true |
|
66 | true | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def require_admin |
|
69 | def require_admin | |
70 | return unless require_login |
|
70 | return unless require_login | |
71 | unless self.logged_in_user.admin? |
|
71 | unless self.logged_in_user.admin? | |
72 | render :nothing => true, :status => 403 |
|
72 | render :nothing => true, :status => 403 | |
73 | return false |
|
73 | return false | |
74 | end |
|
74 | end | |
75 | true |
|
75 | true | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | # authorizes the user for the requested action. |
|
78 | # authorizes the user for the requested action. | |
79 | def authorize(ctrl = params[:controller], action = params[:action]) |
|
79 | def authorize(ctrl = params[:controller], action = params[:action]) | |
80 | # check if action is allowed on public projects |
|
80 | # check if action is allowed on public projects | |
81 | if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ ctrl, action ] |
|
81 | if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ ctrl, action ] | |
82 | return true |
|
82 | return true | |
83 | end |
|
83 | end | |
84 | # if action is not public, force login |
|
84 | # if action is not public, force login | |
85 | return unless require_login |
|
85 | return unless require_login | |
86 | # admin is always authorized |
|
86 | # admin is always authorized | |
87 | return true if self.logged_in_user.admin? |
|
87 | return true if self.logged_in_user.admin? | |
88 | # if not admin, check membership permission |
|
88 | # if not admin, check membership permission | |
89 | @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id]) |
|
89 | @user_membership ||= logged_in_user.role_for_project(@project) | |
90 |
if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership |
|
90 | if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership ) | |
91 | return true |
|
91 | return true | |
92 | end |
|
92 | end | |
93 | render :nothing => true, :status => 403 |
|
93 | render :nothing => true, :status => 403 | |
94 | false |
|
94 | false | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | # make sure that the user is a member of the project (or admin) if project is private |
|
97 | # make sure that the user is a member of the project (or admin) if project is private | |
98 | # used as a before_filter for actions that do not require any particular permission on the project |
|
98 | # used as a before_filter for actions that do not require any particular permission on the project | |
99 | def check_project_privacy |
|
99 | def check_project_privacy | |
100 | return true if @project.is_public? |
|
100 | return true if @project.is_public? | |
101 | return false unless logged_in_user |
|
101 | return false unless logged_in_user | |
102 | return true if logged_in_user.admin? || logged_in_user_membership |
|
102 | return true if logged_in_user.admin? || logged_in_user_membership | |
103 | render :nothing => true, :status => 403 |
|
103 | render :nothing => true, :status => 403 | |
104 | false |
|
104 | false | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | # store current uri in session. |
|
107 | # store current uri in session. | |
108 | # return to this location by calling redirect_back_or_default |
|
108 | # return to this location by calling redirect_back_or_default | |
109 | def store_location |
|
109 | def store_location | |
110 | session[:return_to_params] = params |
|
110 | session[:return_to_params] = params | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | # move to the last store_location call or to the passed default one |
|
113 | # move to the last store_location call or to the passed default one | |
114 | def redirect_back_or_default(default) |
|
114 | def redirect_back_or_default(default) | |
115 | if session[:return_to_params].nil? |
|
115 | if session[:return_to_params].nil? | |
116 | redirect_to default |
|
116 | redirect_to default | |
117 | else |
|
117 | else | |
118 | redirect_to session[:return_to_params] |
|
118 | redirect_to session[:return_to_params] | |
119 | session[:return_to_params] = nil |
|
119 | session[:return_to_params] = nil | |
120 | end |
|
120 | end | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | def render_404 |
|
123 | def render_404 | |
124 | @html_title = "404" |
|
124 | @html_title = "404" | |
125 | render :template => "common/404", :layout => true, :status => 404 |
|
125 | render :template => "common/404", :layout => true, :status => 404 | |
126 | return false |
|
126 | return false | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | # qvalues http header parser |
|
129 | # qvalues http header parser | |
130 | # code taken from webrick |
|
130 | # code taken from webrick | |
131 | def parse_qvalues(value) |
|
131 | def parse_qvalues(value) | |
132 | tmp = [] |
|
132 | tmp = [] | |
133 | if value |
|
133 | if value | |
134 | parts = value.split(/,\s*/) |
|
134 | parts = value.split(/,\s*/) | |
135 | parts.each {|part| |
|
135 | parts.each {|part| | |
136 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) |
|
136 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) | |
137 | val = m[1] |
|
137 | val = m[1] | |
138 | q = (m[2] or 1).to_f |
|
138 | q = (m[2] or 1).to_f | |
139 | tmp.push([val, q]) |
|
139 | tmp.push([val, q]) | |
140 | end |
|
140 | end | |
141 | } |
|
141 | } | |
142 | tmp = tmp.sort_by{|val, q| -q} |
|
142 | tmp = tmp.sort_by{|val, q| -q} | |
143 | tmp.collect!{|val, q| val} |
|
143 | tmp.collect!{|val, q| val} | |
144 | end |
|
144 | end | |
145 | return tmp |
|
145 | return tmp | |
146 | end |
|
146 | end | |
147 | end No newline at end of file |
|
147 | end |
@@ -1,96 +1,96 | |||||
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 FeedsController < ApplicationController |
|
18 | class FeedsController < ApplicationController | |
19 | before_filter :find_scope |
|
19 | before_filter :find_scope | |
20 | session :off |
|
20 | session :off | |
21 |
|
21 | |||
22 | helper :issues |
|
22 | helper :issues | |
23 | include IssuesHelper |
|
23 | include IssuesHelper | |
24 | helper :custom_fields |
|
24 | helper :custom_fields | |
25 | include CustomFieldsHelper |
|
25 | include CustomFieldsHelper | |
26 |
|
26 | |||
27 | # news feeds |
|
27 | # news feeds | |
28 | def news |
|
28 | def news | |
29 | News.with_scope(:find => @find_options) do |
|
29 | News.with_scope(:find => @find_options) do | |
30 | @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ] |
|
30 | @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ] | |
31 | end |
|
31 | end | |
32 | headers["Content-Type"] = "application/rss+xml" |
|
32 | headers["Content-Type"] = "application/rss+xml" | |
33 | render :action => 'news_atom' if 'atom' == params[:format] |
|
33 | render :action => 'news_atom' if 'atom' == params[:format] | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | # issue feeds |
|
36 | # issue feeds | |
37 | def issues |
|
37 | def issues | |
38 | if @project && params[:query_id] |
|
38 | if @project && params[:query_id] | |
39 | query = Query.find(params[:query_id]) |
|
39 | query = Query.find(params[:query_id]) | |
40 | # ignore query if it's not valid |
|
40 | # ignore query if it's not valid | |
41 | query = nil unless query.valid? |
|
41 | query = nil unless query.valid? | |
42 | # override with query conditions |
|
42 | # override with query conditions | |
43 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project |
|
43 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | Issue.with_scope(:find => @find_options) do |
|
46 | Issue.with_scope(:find => @find_options) do | |
47 | @issues = Issue.find :all, :include => [:project, :author, :tracker, :status], |
|
47 | @issues = Issue.find :all, :include => [:project, :author, :tracker, :status], | |
48 | :order => "#{Issue.table_name}.created_on DESC" |
|
48 | :order => "#{Issue.table_name}.created_on DESC" | |
49 | end |
|
49 | end | |
50 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) |
|
50 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) | |
51 | headers["Content-Type"] = "application/rss+xml" |
|
51 | headers["Content-Type"] = "application/rss+xml" | |
52 | render :action => 'issues_atom' if 'atom' == params[:format] |
|
52 | render :action => 'issues_atom' if 'atom' == params[:format] | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | # issue changes feeds |
|
55 | # issue changes feeds | |
56 | def history |
|
56 | def history | |
57 | if @project && params[:query_id] |
|
57 | if @project && params[:query_id] | |
58 | query = Query.find(params[:query_id]) |
|
58 | query = Query.find(params[:query_id]) | |
59 | # ignore query if it's not valid |
|
59 | # ignore query if it's not valid | |
60 | query = nil unless query.valid? |
|
60 | query = nil unless query.valid? | |
61 | # override with query conditions |
|
61 | # override with query conditions | |
62 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project |
|
62 | @find_options[:conditions] = query.statement if query.valid? and @project == query.project | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | Journal.with_scope(:find => @find_options) do |
|
65 | Journal.with_scope(:find => @find_options) do | |
66 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], |
|
66 | @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | |
67 | :order => "#{Journal.table_name}.created_on DESC" |
|
67 | :order => "#{Journal.table_name}.created_on DESC" | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) |
|
70 | @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues)) | |
71 | headers["Content-Type"] = "application/rss+xml" |
|
71 | headers["Content-Type"] = "application/rss+xml" | |
72 | render :action => 'history_atom' if 'atom' == params[:format] |
|
72 | render :action => 'history_atom' if 'atom' == params[:format] | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | private |
|
75 | private | |
76 | # override for feeds specific authentication |
|
76 | # override for feeds specific authentication | |
77 | def check_if_login_required |
|
77 | def check_if_login_required | |
78 | @user = User.find_by_rss_key(params[:key]) |
|
78 | @user = User.find_by_rss_key(params[:key]) | |
79 | render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required? |
|
79 | render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required? | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def find_scope |
|
82 | def find_scope | |
83 | if params[:project_id] |
|
83 | if params[:project_id] | |
84 | # project feed |
|
84 | # project feed | |
85 | # check if project is public or if the user is a member |
|
85 | # check if project is public or if the user is a member | |
86 | @project = Project.find(params[:project_id]) |
|
86 | @project = Project.find(params[:project_id]) | |
87 |
render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project |
|
87 | render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project)) | |
88 | scope = ["#{Project.table_name}.id=?", params[:project_id].to_i] |
|
88 | scope = ["#{Project.table_name}.id=?", params[:project_id].to_i] | |
89 | else |
|
89 | else | |
90 | # global feed |
|
90 | # global feed | |
91 | scope = ["#{Project.table_name}.is_public=?", true] |
|
91 | scope = ["#{Project.table_name}.is_public=?", true] | |
92 | end |
|
92 | end | |
93 | @find_options = {:conditions => scope, :limit => Setting.feeds_limit} |
|
93 | @find_options = {:conditions => scope, :limit => Setting.feeds_limit} | |
94 | return true |
|
94 | return true | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end |
@@ -1,149 +1,139 | |||||
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 IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | layout 'base', :except => :export_pdf |
|
19 | layout 'base', :except => :export_pdf | |
20 | before_filter :find_project, :authorize |
|
20 | before_filter :find_project, :authorize | |
21 |
|
21 | |||
22 | helper :custom_fields |
|
22 | helper :custom_fields | |
23 | include CustomFieldsHelper |
|
23 | include CustomFieldsHelper | |
24 | helper :ifpdf |
|
24 | helper :ifpdf | |
25 | include IfpdfHelper |
|
25 | include IfpdfHelper | |
26 |
|
26 | |||
27 | def show |
|
27 | def show | |
28 |
@status_options = |
|
28 | @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
29 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field) |
|
29 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field) | |
30 | @journals_count = @issue.journals.count |
|
30 | @journals_count = @issue.journals.count | |
31 | @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "#{Journal.table_name}.created_on desc") |
|
31 | @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "#{Journal.table_name}.created_on desc") | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def history |
|
34 | def history | |
35 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on desc") |
|
35 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on desc") | |
36 | @journals_count = @journals.length |
|
36 | @journals_count = @journals.length | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def export_pdf |
|
39 | def export_pdf | |
40 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field) |
|
40 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field) | |
41 | @options_for_rfpdf ||= {} |
|
41 | @options_for_rfpdf ||= {} | |
42 | @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.long_id}.pdf" |
|
42 | @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.long_id}.pdf" | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def edit |
|
45 | def edit | |
46 | @priorities = Enumeration::get_values('IPRI') |
|
46 | @priorities = Enumeration::get_values('IPRI') | |
47 | if request.get? |
|
47 | if request.get? | |
48 | @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) } |
|
48 | @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) } | |
49 | else |
|
49 | else | |
50 | begin |
|
50 | begin | |
51 | @issue.init_journal(self.logged_in_user) |
|
51 | @issue.init_journal(self.logged_in_user) | |
52 | # Retrieve custom fields and values |
|
52 | # Retrieve custom fields and values | |
53 | @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
53 | @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } | |
54 | @issue.custom_values = @custom_values |
|
54 | @issue.custom_values = @custom_values | |
55 | @issue.attributes = params[:issue] |
|
55 | @issue.attributes = params[:issue] | |
56 | if @issue.save |
|
56 | if @issue.save | |
57 | flash[:notice] = l(:notice_successful_update) |
|
57 | flash[:notice] = l(:notice_successful_update) | |
58 | redirect_to :action => 'show', :id => @issue |
|
58 | redirect_to :action => 'show', :id => @issue | |
59 | end |
|
59 | end | |
60 | rescue ActiveRecord::StaleObjectError |
|
60 | rescue ActiveRecord::StaleObjectError | |
61 | # Optimistic locking exception |
|
61 | # Optimistic locking exception | |
62 | flash[:notice] = l(:notice_locking_conflict) |
|
62 | flash[:notice] = l(:notice_locking_conflict) | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def add_note |
|
67 | def add_note | |
68 | unless params[:notes].empty? |
|
68 | unless params[:notes].empty? | |
69 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) |
|
69 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) | |
70 | #@history = @issue.histories.build(params[:history]) |
|
|||
71 | #@history.author_id = self.logged_in_user.id if self.logged_in_user |
|
|||
72 | #@history.status = @issue.status |
|
|||
73 | if @issue.save |
|
70 | if @issue.save | |
74 | flash[:notice] = l(:notice_successful_update) |
|
71 | flash[:notice] = l(:notice_successful_update) | |
75 | Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
72 | Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
76 | redirect_to :action => 'show', :id => @issue |
|
73 | redirect_to :action => 'show', :id => @issue | |
77 | return |
|
74 | return | |
78 | end |
|
75 | end | |
79 | end |
|
76 | end | |
80 | show |
|
77 | show | |
81 | render :action => 'show' |
|
78 | render :action => 'show' | |
82 | end |
|
79 | end | |
83 |
|
80 | |||
84 | def change_status |
|
81 | def change_status | |
85 | #@history = @issue.histories.build(params[:history]) |
|
82 | @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
86 | @status_options = ([@issue.status] + @issue.status.workflows.find(:all, :order => 'position', :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status }) if self.logged_in_user |
|
|||
87 | @new_status = IssueStatus.find(params[:new_status_id]) |
|
83 | @new_status = IssueStatus.find(params[:new_status_id]) | |
88 | if params[:confirm] |
|
84 | if params[:confirm] | |
89 | begin |
|
85 | begin | |
90 | #@history.author_id = self.logged_in_user.id if self.logged_in_user |
|
|||
91 | #@issue.status = @history.status |
|
|||
92 | #@issue.fixed_version_id = (params[:issue][:fixed_version_id]) |
|
|||
93 | #@issue.assigned_to_id = (params[:issue][:assigned_to_id]) |
|
|||
94 | #@issue.done_ratio = (params[:issue][:done_ratio]) |
|
|||
95 | #@issue.lock_version = (params[:issue][:lock_version]) |
|
|||
96 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) |
|
86 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) | |
97 | @issue.status = @new_status |
|
87 | @issue.status = @new_status | |
98 | if @issue.update_attributes(params[:issue]) |
|
88 | if @issue.update_attributes(params[:issue]) | |
99 | flash[:notice] = l(:notice_successful_update) |
|
89 | flash[:notice] = l(:notice_successful_update) | |
100 | Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
90 | Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
101 | redirect_to :action => 'show', :id => @issue |
|
91 | redirect_to :action => 'show', :id => @issue | |
102 | end |
|
92 | end | |
103 | rescue ActiveRecord::StaleObjectError |
|
93 | rescue ActiveRecord::StaleObjectError | |
104 | # Optimistic locking exception |
|
94 | # Optimistic locking exception | |
105 | flash[:notice] = l(:notice_locking_conflict) |
|
95 | flash[:notice] = l(:notice_locking_conflict) | |
106 | end |
|
96 | end | |
107 | end |
|
97 | end | |
108 | @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user } |
|
98 | @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user } | |
109 | end |
|
99 | end | |
110 |
|
100 | |||
111 | def destroy |
|
101 | def destroy | |
112 | @issue.destroy |
|
102 | @issue.destroy | |
113 | redirect_to :controller => 'projects', :action => 'list_issues', :id => @project |
|
103 | redirect_to :controller => 'projects', :action => 'list_issues', :id => @project | |
114 | end |
|
104 | end | |
115 |
|
105 | |||
116 | def add_attachment |
|
106 | def add_attachment | |
117 | # Save the attachments |
|
107 | # Save the attachments | |
118 | @attachments = [] |
|
108 | @attachments = [] | |
119 | params[:attachments].each { |file| |
|
109 | params[:attachments].each { |file| | |
120 | next unless file.size > 0 |
|
110 | next unless file.size > 0 | |
121 | a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user) |
|
111 | a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user) | |
122 | @attachments << a unless a.new_record? |
|
112 | @attachments << a unless a.new_record? | |
123 | } if params[:attachments] and params[:attachments].is_a? Array |
|
113 | } if params[:attachments] and params[:attachments].is_a? Array | |
124 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
114 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
125 | redirect_to :action => 'show', :id => @issue |
|
115 | redirect_to :action => 'show', :id => @issue | |
126 | end |
|
116 | end | |
127 |
|
117 | |||
128 | def destroy_attachment |
|
118 | def destroy_attachment | |
129 | @issue.attachments.find(params[:attachment_id]).destroy |
|
119 | @issue.attachments.find(params[:attachment_id]).destroy | |
130 | redirect_to :action => 'show', :id => @issue |
|
120 | redirect_to :action => 'show', :id => @issue | |
131 | end |
|
121 | end | |
132 |
|
122 | |||
133 | # Send the file in stream mode |
|
123 | # Send the file in stream mode | |
134 | def download |
|
124 | def download | |
135 | @attachment = @issue.attachments.find(params[:attachment_id]) |
|
125 | @attachment = @issue.attachments.find(params[:attachment_id]) | |
136 | send_file @attachment.diskfile, :filename => @attachment.filename |
|
126 | send_file @attachment.diskfile, :filename => @attachment.filename | |
137 | rescue |
|
127 | rescue | |
138 | render_404 |
|
128 | render_404 | |
139 | end |
|
129 | end | |
140 |
|
130 | |||
141 | private |
|
131 | private | |
142 | def find_project |
|
132 | def find_project | |
143 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
133 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
144 | @project = @issue.project |
|
134 | @project = @issue.project | |
145 | @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}" |
|
135 | @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}" | |
146 | rescue ActiveRecord::RecordNotFound |
|
136 | rescue ActiveRecord::RecordNotFound | |
147 | render_404 |
|
137 | render_404 | |
148 | end |
|
138 | end | |
149 | end |
|
139 | end |
@@ -1,686 +1,685 | |||||
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 "#{Project.table_name}.name", "asc" |
|
42 | sort_init "#{Project.table_name}.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 => ["#{Project.table_name}.is_public=?", true], |
|
49 | :conditions => ["#{Project.table_name}.is_public=?", true], | |
50 | :include => :parent, |
|
50 | :include => :parent, | |
51 | :limit => @project_pages.items_per_page, |
|
51 | :limit => @project_pages.items_per_page, | |
52 | :offset => @project_pages.current.offset |
|
52 | :offset => @project_pages.current.offset | |
53 |
|
53 | |||
54 | render :action => "list", :layout => false if request.xhr? |
|
54 | render :action => "list", :layout => false if request.xhr? | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | # Add a new project |
|
57 | # Add a new project | |
58 | def add |
|
58 | def add | |
59 | @custom_fields = IssueCustomField.find(:all) |
|
59 | @custom_fields = IssueCustomField.find(:all) | |
60 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
60 | @root_projects = Project.find(:all, :conditions => "parent_id is null") | |
61 | @project = Project.new(params[:project]) |
|
61 | @project = Project.new(params[:project]) | |
62 | if request.get? |
|
62 | if request.get? | |
63 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
63 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
64 | else |
|
64 | else | |
65 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
65 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
66 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
66 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
67 | @project.custom_values = @custom_values |
|
67 | @project.custom_values = @custom_values | |
68 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
68 | if params[:repository_enabled] && params[:repository_enabled] == "1" | |
69 | @project.repository = Repository.new |
|
69 | @project.repository = Repository.new | |
70 | @project.repository.attributes = params[:repository] |
|
70 | @project.repository.attributes = params[:repository] | |
71 | end |
|
71 | end | |
72 | if "1" == params[:wiki_enabled] |
|
72 | if "1" == params[:wiki_enabled] | |
73 | @project.wiki = Wiki.new |
|
73 | @project.wiki = Wiki.new | |
74 | @project.wiki.attributes = params[:wiki] |
|
74 | @project.wiki.attributes = params[:wiki] | |
75 | end |
|
75 | end | |
76 | if @project.save |
|
76 | if @project.save | |
77 | flash[:notice] = l(:notice_successful_create) |
|
77 | flash[:notice] = l(:notice_successful_create) | |
78 | redirect_to :controller => 'admin', :action => 'projects' |
|
78 | redirect_to :controller => 'admin', :action => 'projects' | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | # Show @project |
|
83 | # Show @project | |
84 | def show |
|
84 | def show | |
85 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
85 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
86 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') |
|
86 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') | |
87 | @subprojects = @project.children if @project.children.size > 0 |
|
87 | @subprojects = @project.children if @project.children.size > 0 | |
88 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
88 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
89 | @trackers = Tracker.find(:all, :order => 'position') |
|
89 | @trackers = Tracker.find(:all, :order => 'position') | |
90 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) |
|
90 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) | |
91 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
91 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def settings |
|
94 | def settings | |
95 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
95 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) | |
96 | @custom_fields = IssueCustomField.find(:all) |
|
96 | @custom_fields = IssueCustomField.find(:all) | |
97 | @issue_category ||= IssueCategory.new |
|
97 | @issue_category ||= IssueCategory.new | |
98 | @member ||= @project.members.new |
|
98 | @member ||= @project.members.new | |
99 | @roles = Role.find(:all, :order => 'position') |
|
99 | @roles = Role.find(:all, :order => 'position') | |
100 | @users = User.find_active(:all) - @project.users |
|
100 | @users = User.find_active(:all) - @project.users | |
101 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
101 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | # Edit @project |
|
104 | # Edit @project | |
105 | def edit |
|
105 | def edit | |
106 | if request.post? |
|
106 | if request.post? | |
107 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
107 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
108 | if params[:custom_fields] |
|
108 | if params[:custom_fields] | |
109 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
109 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
110 | @project.custom_values = @custom_values |
|
110 | @project.custom_values = @custom_values | |
111 | end |
|
111 | end | |
112 | if params[:repository_enabled] |
|
112 | if params[:repository_enabled] | |
113 | case params[:repository_enabled] |
|
113 | case params[:repository_enabled] | |
114 | when "0" |
|
114 | when "0" | |
115 | @project.repository = nil |
|
115 | @project.repository = nil | |
116 | when "1" |
|
116 | when "1" | |
117 | @project.repository ||= Repository.new |
|
117 | @project.repository ||= Repository.new | |
118 | @project.repository.update_attributes params[:repository] |
|
118 | @project.repository.update_attributes params[:repository] | |
119 | end |
|
119 | end | |
120 | end |
|
120 | end | |
121 | if params[:wiki_enabled] |
|
121 | if params[:wiki_enabled] | |
122 | case params[:wiki_enabled] |
|
122 | case params[:wiki_enabled] | |
123 | when "0" |
|
123 | when "0" | |
124 | @project.wiki.destroy if @project.wiki |
|
124 | @project.wiki.destroy if @project.wiki | |
125 | when "1" |
|
125 | when "1" | |
126 | @project.wiki ||= Wiki.new |
|
126 | @project.wiki ||= Wiki.new | |
127 | @project.wiki.update_attributes params[:wiki] |
|
127 | @project.wiki.update_attributes params[:wiki] | |
128 | end |
|
128 | end | |
129 | end |
|
129 | end | |
130 | @project.attributes = params[:project] |
|
130 | @project.attributes = params[:project] | |
131 | if @project.save |
|
131 | if @project.save | |
132 | flash[:notice] = l(:notice_successful_update) |
|
132 | flash[:notice] = l(:notice_successful_update) | |
133 | redirect_to :action => 'settings', :id => @project |
|
133 | redirect_to :action => 'settings', :id => @project | |
134 | else |
|
134 | else | |
135 | settings |
|
135 | settings | |
136 | render :action => 'settings' |
|
136 | render :action => 'settings' | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | # Delete @project |
|
141 | # Delete @project | |
142 | def destroy |
|
142 | def destroy | |
143 | if request.post? and params[:confirm] |
|
143 | if request.post? and params[:confirm] | |
144 | @project.destroy |
|
144 | @project.destroy | |
145 | redirect_to :controller => 'admin', :action => 'projects' |
|
145 | redirect_to :controller => 'admin', :action => 'projects' | |
146 | end |
|
146 | end | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | # Add a new issue category to @project |
|
149 | # Add a new issue category to @project | |
150 | def add_issue_category |
|
150 | def add_issue_category | |
151 | if request.post? |
|
151 | if request.post? | |
152 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
152 | @issue_category = @project.issue_categories.build(params[:issue_category]) | |
153 | if @issue_category.save |
|
153 | if @issue_category.save | |
154 | flash[:notice] = l(:notice_successful_create) |
|
154 | flash[:notice] = l(:notice_successful_create) | |
155 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
155 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
156 | else |
|
156 | else | |
157 | settings |
|
157 | settings | |
158 | render :action => 'settings' |
|
158 | render :action => 'settings' | |
159 | end |
|
159 | end | |
160 | end |
|
160 | end | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | # Add a new version to @project |
|
163 | # Add a new version to @project | |
164 | def add_version |
|
164 | def add_version | |
165 | @version = @project.versions.build(params[:version]) |
|
165 | @version = @project.versions.build(params[:version]) | |
166 | if request.post? and @version.save |
|
166 | if request.post? and @version.save | |
167 | flash[:notice] = l(:notice_successful_create) |
|
167 | flash[:notice] = l(:notice_successful_create) | |
168 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
168 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
169 | end |
|
169 | end | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | # Add a new member to @project |
|
172 | # Add a new member to @project | |
173 | def add_member |
|
173 | def add_member | |
174 | @member = @project.members.build(params[:member]) |
|
174 | @member = @project.members.build(params[:member]) | |
175 | if request.post? |
|
175 | if request.post? | |
176 | if @member.save |
|
176 | if @member.save | |
177 | flash[:notice] = l(:notice_successful_create) |
|
177 | flash[:notice] = l(:notice_successful_create) | |
178 | redirect_to :action => 'settings', :tab => 'members', :id => @project |
|
178 | redirect_to :action => 'settings', :tab => 'members', :id => @project | |
179 | else |
|
179 | else | |
180 | settings |
|
180 | settings | |
181 | render :action => 'settings' |
|
181 | render :action => 'settings' | |
182 | end |
|
182 | end | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | # Show members list of @project |
|
186 | # Show members list of @project | |
187 | def list_members |
|
187 | def list_members | |
188 | @members = @project.members.find(:all) |
|
188 | @members = @project.members.find(:all) | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | # Add a new document to @project |
|
191 | # Add a new document to @project | |
192 | def add_document |
|
192 | def add_document | |
193 | @categories = Enumeration::get_values('DCAT') |
|
193 | @categories = Enumeration::get_values('DCAT') | |
194 | @document = @project.documents.build(params[:document]) |
|
194 | @document = @project.documents.build(params[:document]) | |
195 | if request.post? and @document.save |
|
195 | if request.post? and @document.save | |
196 | # Save the attachments |
|
196 | # Save the attachments | |
197 | params[:attachments].each { |a| |
|
197 | params[:attachments].each { |a| | |
198 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
198 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
199 | } if params[:attachments] and params[:attachments].is_a? Array |
|
199 | } if params[:attachments] and params[:attachments].is_a? Array | |
200 | flash[:notice] = l(:notice_successful_create) |
|
200 | flash[:notice] = l(:notice_successful_create) | |
201 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
201 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
202 | redirect_to :action => 'list_documents', :id => @project |
|
202 | redirect_to :action => 'list_documents', :id => @project | |
203 | end |
|
203 | end | |
204 | end |
|
204 | end | |
205 |
|
205 | |||
206 | # Show documents list of @project |
|
206 | # Show documents list of @project | |
207 | def list_documents |
|
207 | def list_documents | |
208 | @documents = @project.documents.find :all, :include => :category |
|
208 | @documents = @project.documents.find :all, :include => :category | |
209 | end |
|
209 | end | |
210 |
|
210 | |||
211 | # Add a new issue to @project |
|
211 | # Add a new issue to @project | |
212 | def add_issue |
|
212 | def add_issue | |
213 | @tracker = Tracker.find(params[:tracker_id]) |
|
213 | @tracker = Tracker.find(params[:tracker_id]) | |
214 | @priorities = Enumeration::get_values('IPRI') |
|
214 | @priorities = Enumeration::get_values('IPRI') | |
215 |
|
215 | |||
216 | default_status = IssueStatus.default |
|
216 | default_status = IssueStatus.default | |
217 | @issue = Issue.new(:project => @project, :tracker => @tracker, :status => default_status) |
|
217 | @issue = Issue.new(:project => @project, :tracker => @tracker, :status => default_status) | |
218 | @allowed_statuses = [default_status] + default_status.workflows.find(:all, :order => 'position', :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } |
|
218 | @allowed_statuses = default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
219 |
|
||||
220 | if request.get? |
|
219 | if request.get? | |
221 | @issue.start_date = Date.today |
|
220 | @issue.start_date = Date.today | |
222 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
221 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
223 | else |
|
222 | else | |
224 | @issue.attributes = params[:issue] |
|
223 | @issue.attributes = params[:issue] | |
225 |
|
224 | |||
226 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
225 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
227 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
226 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
228 |
|
227 | |||
229 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
228 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
230 | # Multiple file upload |
|
229 | # Multiple file upload | |
231 | @attachments = [] |
|
230 | @attachments = [] | |
232 | params[:attachments].each { |a| |
|
231 | params[:attachments].each { |a| | |
233 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
232 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
234 | } if params[:attachments] and params[:attachments].is_a? Array |
|
233 | } if params[:attachments] and params[:attachments].is_a? Array | |
235 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
234 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } | |
236 | @issue.custom_values = @custom_values |
|
235 | @issue.custom_values = @custom_values | |
237 | if @issue.save |
|
236 | if @issue.save | |
238 | @attachments.each(&:save) |
|
237 | @attachments.each(&:save) | |
239 | flash[:notice] = l(:notice_successful_create) |
|
238 | flash[:notice] = l(:notice_successful_create) | |
240 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
239 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
241 | redirect_to :action => 'list_issues', :id => @project |
|
240 | redirect_to :action => 'list_issues', :id => @project | |
242 | end |
|
241 | end | |
243 | end |
|
242 | end | |
244 | end |
|
243 | end | |
245 |
|
244 | |||
246 | # Show filtered/sorted issues list of @project |
|
245 | # Show filtered/sorted issues list of @project | |
247 | def list_issues |
|
246 | def list_issues | |
248 | sort_init "#{Issue.table_name}.id", "desc" |
|
247 | sort_init "#{Issue.table_name}.id", "desc" | |
249 | sort_update |
|
248 | sort_update | |
250 |
|
249 | |||
251 | retrieve_query |
|
250 | retrieve_query | |
252 |
|
251 | |||
253 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
252 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
254 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
253 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
255 | @results_per_page = params[:per_page].to_i |
|
254 | @results_per_page = params[:per_page].to_i | |
256 | session[:results_per_page] = @results_per_page |
|
255 | session[:results_per_page] = @results_per_page | |
257 | else |
|
256 | else | |
258 | @results_per_page = session[:results_per_page] || 25 |
|
257 | @results_per_page = session[:results_per_page] || 25 | |
259 | end |
|
258 | end | |
260 |
|
259 | |||
261 | if @query.valid? |
|
260 | if @query.valid? | |
262 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
261 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
263 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
262 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
264 | @issues = Issue.find :all, :order => sort_clause, |
|
263 | @issues = Issue.find :all, :order => sort_clause, | |
265 | :include => [ :author, :status, :tracker, :project, :priority ], |
|
264 | :include => [ :author, :status, :tracker, :project, :priority ], | |
266 | :conditions => @query.statement, |
|
265 | :conditions => @query.statement, | |
267 | :limit => @issue_pages.items_per_page, |
|
266 | :limit => @issue_pages.items_per_page, | |
268 | :offset => @issue_pages.current.offset |
|
267 | :offset => @issue_pages.current.offset | |
269 | end |
|
268 | end | |
270 | @trackers = Tracker.find :all, :order => 'position' |
|
269 | @trackers = Tracker.find :all, :order => 'position' | |
271 | render :layout => false if request.xhr? |
|
270 | render :layout => false if request.xhr? | |
272 | end |
|
271 | end | |
273 |
|
272 | |||
274 | # Export filtered/sorted issues list to CSV |
|
273 | # Export filtered/sorted issues list to CSV | |
275 | def export_issues_csv |
|
274 | def export_issues_csv | |
276 | sort_init "#{Issue.table_name}.id", "desc" |
|
275 | sort_init "#{Issue.table_name}.id", "desc" | |
277 | sort_update |
|
276 | sort_update | |
278 |
|
277 | |||
279 | retrieve_query |
|
278 | retrieve_query | |
280 | render :action => 'list_issues' and return unless @query.valid? |
|
279 | render :action => 'list_issues' and return unless @query.valid? | |
281 |
|
280 | |||
282 | @issues = Issue.find :all, :order => sort_clause, |
|
281 | @issues = Issue.find :all, :order => sort_clause, | |
283 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], |
|
282 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], | |
284 | :conditions => @query.statement, |
|
283 | :conditions => @query.statement, | |
285 | :limit => Setting.issues_export_limit |
|
284 | :limit => Setting.issues_export_limit | |
286 |
|
285 | |||
287 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
286 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
288 | export = StringIO.new |
|
287 | export = StringIO.new | |
289 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
288 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
290 | # csv header fields |
|
289 | # csv header fields | |
291 | headers = [ "#", l(:field_status), |
|
290 | headers = [ "#", l(:field_status), | |
292 | l(:field_tracker), |
|
291 | l(:field_tracker), | |
293 | l(:field_priority), |
|
292 | l(:field_priority), | |
294 | l(:field_subject), |
|
293 | l(:field_subject), | |
295 | l(:field_author), |
|
294 | l(:field_author), | |
296 | l(:field_start_date), |
|
295 | l(:field_start_date), | |
297 | l(:field_due_date), |
|
296 | l(:field_due_date), | |
298 | l(:field_done_ratio), |
|
297 | l(:field_done_ratio), | |
299 | l(:field_created_on), |
|
298 | l(:field_created_on), | |
300 | l(:field_updated_on) |
|
299 | l(:field_updated_on) | |
301 | ] |
|
300 | ] | |
302 | for custom_field in @project.all_custom_fields |
|
301 | for custom_field in @project.all_custom_fields | |
303 | headers << custom_field.name |
|
302 | headers << custom_field.name | |
304 | end |
|
303 | end | |
305 | csv << headers.collect {|c| ic.iconv(c) } |
|
304 | csv << headers.collect {|c| ic.iconv(c) } | |
306 | # csv lines |
|
305 | # csv lines | |
307 | @issues.each do |issue| |
|
306 | @issues.each do |issue| | |
308 | fields = [issue.id, issue.status.name, |
|
307 | fields = [issue.id, issue.status.name, | |
309 | issue.tracker.name, |
|
308 | issue.tracker.name, | |
310 | issue.priority.name, |
|
309 | issue.priority.name, | |
311 | issue.subject, |
|
310 | issue.subject, | |
312 | issue.author.display_name, |
|
311 | issue.author.display_name, | |
313 | issue.start_date ? l_date(issue.start_date) : nil, |
|
312 | issue.start_date ? l_date(issue.start_date) : nil, | |
314 | issue.due_date ? l_date(issue.due_date) : nil, |
|
313 | issue.due_date ? l_date(issue.due_date) : nil, | |
315 | issue.done_ratio, |
|
314 | issue.done_ratio, | |
316 | l_datetime(issue.created_on), |
|
315 | l_datetime(issue.created_on), | |
317 | l_datetime(issue.updated_on) |
|
316 | l_datetime(issue.updated_on) | |
318 | ] |
|
317 | ] | |
319 | for custom_field in @project.all_custom_fields |
|
318 | for custom_field in @project.all_custom_fields | |
320 | fields << (show_value issue.custom_value_for(custom_field)) |
|
319 | fields << (show_value issue.custom_value_for(custom_field)) | |
321 | end |
|
320 | end | |
322 | csv << fields.collect {|c| ic.iconv(c.to_s) } |
|
321 | csv << fields.collect {|c| ic.iconv(c.to_s) } | |
323 | end |
|
322 | end | |
324 | end |
|
323 | end | |
325 | export.rewind |
|
324 | export.rewind | |
326 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
325 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
327 | end |
|
326 | end | |
328 |
|
327 | |||
329 | # Export filtered/sorted issues to PDF |
|
328 | # Export filtered/sorted issues to PDF | |
330 | def export_issues_pdf |
|
329 | def export_issues_pdf | |
331 | sort_init "#{Issue.table_name}.id", "desc" |
|
330 | sort_init "#{Issue.table_name}.id", "desc" | |
332 | sort_update |
|
331 | sort_update | |
333 |
|
332 | |||
334 | retrieve_query |
|
333 | retrieve_query | |
335 | render :action => 'list_issues' and return unless @query.valid? |
|
334 | render :action => 'list_issues' and return unless @query.valid? | |
336 |
|
335 | |||
337 | @issues = Issue.find :all, :order => sort_clause, |
|
336 | @issues = Issue.find :all, :order => sort_clause, | |
338 | :include => [ :author, :status, :tracker, :priority ], |
|
337 | :include => [ :author, :status, :tracker, :priority ], | |
339 | :conditions => @query.statement, |
|
338 | :conditions => @query.statement, | |
340 | :limit => Setting.issues_export_limit |
|
339 | :limit => Setting.issues_export_limit | |
341 |
|
340 | |||
342 | @options_for_rfpdf ||= {} |
|
341 | @options_for_rfpdf ||= {} | |
343 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
342 | @options_for_rfpdf[:file_name] = "export.pdf" | |
344 | render :layout => false |
|
343 | render :layout => false | |
345 | end |
|
344 | end | |
346 |
|
345 | |||
347 | def move_issues |
|
346 | def move_issues | |
348 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
347 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
349 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
348 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
350 | @projects = [] |
|
349 | @projects = [] | |
351 | # find projects to which the user is allowed to move the issue |
|
350 | # find projects to which the user is allowed to move the issue | |
352 |
@logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role |
|
351 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} | |
353 | # issue can be moved to any tracker |
|
352 | # issue can be moved to any tracker | |
354 | @trackers = Tracker.find(:all) |
|
353 | @trackers = Tracker.find(:all) | |
355 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
354 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
356 | new_project = Project.find(params[:new_project_id]) |
|
355 | new_project = Project.find(params[:new_project_id]) | |
357 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
356 | new_tracker = Tracker.find(params[:new_tracker_id]) | |
358 | @issues.each { |i| |
|
357 | @issues.each { |i| | |
359 | # project dependent properties |
|
358 | # project dependent properties | |
360 | unless i.project_id == new_project.id |
|
359 | unless i.project_id == new_project.id | |
361 | i.category = nil |
|
360 | i.category = nil | |
362 | i.fixed_version = nil |
|
361 | i.fixed_version = nil | |
363 | end |
|
362 | end | |
364 | # move the issue |
|
363 | # move the issue | |
365 | i.project = new_project |
|
364 | i.project = new_project | |
366 | i.tracker = new_tracker |
|
365 | i.tracker = new_tracker | |
367 | i.save |
|
366 | i.save | |
368 | } |
|
367 | } | |
369 | flash[:notice] = l(:notice_successful_update) |
|
368 | flash[:notice] = l(:notice_successful_update) | |
370 | redirect_to :action => 'list_issues', :id => @project |
|
369 | redirect_to :action => 'list_issues', :id => @project | |
371 | end |
|
370 | end | |
372 | end |
|
371 | end | |
373 |
|
372 | |||
374 | def add_query |
|
373 | def add_query | |
375 | @query = Query.new(params[:query]) |
|
374 | @query = Query.new(params[:query]) | |
376 | @query.project = @project |
|
375 | @query.project = @project | |
377 | @query.user = logged_in_user |
|
376 | @query.user = logged_in_user | |
378 |
|
377 | |||
379 | params[:fields].each do |field| |
|
378 | params[:fields].each do |field| | |
380 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
379 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
381 | end if params[:fields] |
|
380 | end if params[:fields] | |
382 |
|
381 | |||
383 | if request.post? and @query.save |
|
382 | if request.post? and @query.save | |
384 | flash[:notice] = l(:notice_successful_create) |
|
383 | flash[:notice] = l(:notice_successful_create) | |
385 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project |
|
384 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project | |
386 | end |
|
385 | end | |
387 | render :layout => false if request.xhr? |
|
386 | render :layout => false if request.xhr? | |
388 | end |
|
387 | end | |
389 |
|
388 | |||
390 | # Add a news to @project |
|
389 | # Add a news to @project | |
391 | def add_news |
|
390 | def add_news | |
392 | @news = News.new(:project => @project) |
|
391 | @news = News.new(:project => @project) | |
393 | if request.post? |
|
392 | if request.post? | |
394 | @news.attributes = params[:news] |
|
393 | @news.attributes = params[:news] | |
395 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
394 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
396 | if @news.save |
|
395 | if @news.save | |
397 | flash[:notice] = l(:notice_successful_create) |
|
396 | flash[:notice] = l(:notice_successful_create) | |
398 | redirect_to :action => 'list_news', :id => @project |
|
397 | redirect_to :action => 'list_news', :id => @project | |
399 | end |
|
398 | end | |
400 | end |
|
399 | end | |
401 | end |
|
400 | end | |
402 |
|
401 | |||
403 | # Show news list of @project |
|
402 | # Show news list of @project | |
404 | def list_news |
|
403 | def list_news | |
405 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
404 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" | |
406 | render :action => "list_news", :layout => false if request.xhr? |
|
405 | render :action => "list_news", :layout => false if request.xhr? | |
407 | end |
|
406 | end | |
408 |
|
407 | |||
409 | def add_file |
|
408 | def add_file | |
410 | if request.post? |
|
409 | if request.post? | |
411 | @version = @project.versions.find_by_id(params[:version_id]) |
|
410 | @version = @project.versions.find_by_id(params[:version_id]) | |
412 | # Save the attachments |
|
411 | # Save the attachments | |
413 | @attachments = [] |
|
412 | @attachments = [] | |
414 | params[:attachments].each { |file| |
|
413 | params[:attachments].each { |file| | |
415 | next unless file.size > 0 |
|
414 | next unless file.size > 0 | |
416 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
415 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) | |
417 | @attachments << a unless a.new_record? |
|
416 | @attachments << a unless a.new_record? | |
418 | } if params[:attachments] and params[:attachments].is_a? Array |
|
417 | } if params[:attachments] and params[:attachments].is_a? Array | |
419 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
418 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
420 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
419 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
421 | end |
|
420 | end | |
422 | @versions = @project.versions |
|
421 | @versions = @project.versions | |
423 | end |
|
422 | end | |
424 |
|
423 | |||
425 | def list_files |
|
424 | def list_files | |
426 | @versions = @project.versions |
|
425 | @versions = @project.versions | |
427 | end |
|
426 | end | |
428 |
|
427 | |||
429 | # Show changelog for @project |
|
428 | # Show changelog for @project | |
430 | def changelog |
|
429 | def changelog | |
431 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
430 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
432 | retrieve_selected_tracker_ids(@trackers) |
|
431 | retrieve_selected_tracker_ids(@trackers) | |
433 |
|
432 | |||
434 | @fixed_issues = @project.issues.find(:all, |
|
433 | @fixed_issues = @project.issues.find(:all, | |
435 | :include => [ :fixed_version, :status, :tracker ], |
|
434 | :include => [ :fixed_version, :status, :tracker ], | |
436 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], |
|
435 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], | |
437 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" |
|
436 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" | |
438 | ) unless @selected_tracker_ids.empty? |
|
437 | ) unless @selected_tracker_ids.empty? | |
439 | @fixed_issues ||= [] |
|
438 | @fixed_issues ||= [] | |
440 | end |
|
439 | end | |
441 |
|
440 | |||
442 | def roadmap |
|
441 | def roadmap | |
443 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
442 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') | |
444 | retrieve_selected_tracker_ids(@trackers) |
|
443 | retrieve_selected_tracker_ids(@trackers) | |
445 |
|
444 | |||
446 | @versions = @project.versions.find(:all, |
|
445 | @versions = @project.versions.find(:all, | |
447 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], |
|
446 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], | |
448 | :order => "#{Version.table_name}.effective_date ASC" |
|
447 | :order => "#{Version.table_name}.effective_date ASC" | |
449 | ) |
|
448 | ) | |
450 | end |
|
449 | end | |
451 |
|
450 | |||
452 | def activity |
|
451 | def activity | |
453 | if params[:year] and params[:year].to_i > 1900 |
|
452 | if params[:year] and params[:year].to_i > 1900 | |
454 | @year = params[:year].to_i |
|
453 | @year = params[:year].to_i | |
455 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
454 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
456 | @month = params[:month].to_i |
|
455 | @month = params[:month].to_i | |
457 | end |
|
456 | end | |
458 | end |
|
457 | end | |
459 | @year ||= Date.today.year |
|
458 | @year ||= Date.today.year | |
460 | @month ||= Date.today.month |
|
459 | @month ||= Date.today.month | |
461 |
|
460 | |||
462 | @date_from = Date.civil(@year, @month, 1) |
|
461 | @date_from = Date.civil(@year, @month, 1) | |
463 | @date_to = (@date_from >> 1)-1 |
|
462 | @date_to = (@date_from >> 1)-1 | |
464 |
|
463 | |||
465 | @events_by_day = {} |
|
464 | @events_by_day = {} | |
466 |
|
465 | |||
467 | unless params[:show_issues] == "0" |
|
466 | unless params[:show_issues] == "0" | |
468 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
467 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
469 | @events_by_day[i.created_on.to_date] ||= [] |
|
468 | @events_by_day[i.created_on.to_date] ||= [] | |
470 | @events_by_day[i.created_on.to_date] << i |
|
469 | @events_by_day[i.created_on.to_date] << i | |
471 | } |
|
470 | } | |
472 | @show_issues = 1 |
|
471 | @show_issues = 1 | |
473 | end |
|
472 | end | |
474 |
|
473 | |||
475 | unless params[:show_news] == "0" |
|
474 | unless params[:show_news] == "0" | |
476 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
475 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| | |
477 | @events_by_day[i.created_on.to_date] ||= [] |
|
476 | @events_by_day[i.created_on.to_date] ||= [] | |
478 | @events_by_day[i.created_on.to_date] << i |
|
477 | @events_by_day[i.created_on.to_date] << i | |
479 | } |
|
478 | } | |
480 | @show_news = 1 |
|
479 | @show_news = 1 | |
481 | end |
|
480 | end | |
482 |
|
481 | |||
483 | unless params[:show_files] == "0" |
|
482 | unless params[:show_files] == "0" | |
484 | 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| |
|
483 | 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| | |
485 | @events_by_day[i.created_on.to_date] ||= [] |
|
484 | @events_by_day[i.created_on.to_date] ||= [] | |
486 | @events_by_day[i.created_on.to_date] << i |
|
485 | @events_by_day[i.created_on.to_date] << i | |
487 | } |
|
486 | } | |
488 | @show_files = 1 |
|
487 | @show_files = 1 | |
489 | end |
|
488 | end | |
490 |
|
489 | |||
491 | unless params[:show_documents] == "0" |
|
490 | unless params[:show_documents] == "0" | |
492 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
491 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
493 | @events_by_day[i.created_on.to_date] ||= [] |
|
492 | @events_by_day[i.created_on.to_date] ||= [] | |
494 | @events_by_day[i.created_on.to_date] << i |
|
493 | @events_by_day[i.created_on.to_date] << i | |
495 | } |
|
494 | } | |
496 | 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| |
|
495 | 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| | |
497 | @events_by_day[i.created_on.to_date] ||= [] |
|
496 | @events_by_day[i.created_on.to_date] ||= [] | |
498 | @events_by_day[i.created_on.to_date] << i |
|
497 | @events_by_day[i.created_on.to_date] << i | |
499 | } |
|
498 | } | |
500 | @show_documents = 1 |
|
499 | @show_documents = 1 | |
501 | end |
|
500 | end | |
502 |
|
501 | |||
503 | unless params[:show_wiki_edits] == "0" |
|
502 | unless params[:show_wiki_edits] == "0" | |
504 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + |
|
503 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + | |
505 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
504 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" | |
506 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
505 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
507 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
506 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
508 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
507 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
509 | @project.id, @date_from, @date_to] |
|
508 | @project.id, @date_from, @date_to] | |
510 |
|
509 | |||
511 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
510 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| | |
512 | # We provide this alias so all events can be treated in the same manner |
|
511 | # We provide this alias so all events can be treated in the same manner | |
513 | def i.created_on |
|
512 | def i.created_on | |
514 | self.updated_on |
|
513 | self.updated_on | |
515 | end |
|
514 | end | |
516 |
|
515 | |||
517 | @events_by_day[i.created_on.to_date] ||= [] |
|
516 | @events_by_day[i.created_on.to_date] ||= [] | |
518 | @events_by_day[i.created_on.to_date] << i |
|
517 | @events_by_day[i.created_on.to_date] << i | |
519 | } |
|
518 | } | |
520 | @show_wiki_edits = 1 |
|
519 | @show_wiki_edits = 1 | |
521 | end |
|
520 | end | |
522 |
|
521 | |||
523 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
522 | unless @project.repository.nil? || params[:show_changesets] == "0" | |
524 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
523 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| | |
525 | def i.created_on |
|
524 | def i.created_on | |
526 | self.committed_on |
|
525 | self.committed_on | |
527 | end |
|
526 | end | |
528 | @events_by_day[i.created_on.to_date] ||= [] |
|
527 | @events_by_day[i.created_on.to_date] ||= [] | |
529 | @events_by_day[i.created_on.to_date] << i |
|
528 | @events_by_day[i.created_on.to_date] << i | |
530 | } |
|
529 | } | |
531 | @show_changesets = 1 |
|
530 | @show_changesets = 1 | |
532 | end |
|
531 | end | |
533 |
|
532 | |||
534 | render :layout => false if request.xhr? |
|
533 | render :layout => false if request.xhr? | |
535 | end |
|
534 | end | |
536 |
|
535 | |||
537 | def calendar |
|
536 | def calendar | |
538 | @trackers = Tracker.find(:all, :order => 'position') |
|
537 | @trackers = Tracker.find(:all, :order => 'position') | |
539 | retrieve_selected_tracker_ids(@trackers) |
|
538 | retrieve_selected_tracker_ids(@trackers) | |
540 |
|
539 | |||
541 | if params[:year] and params[:year].to_i > 1900 |
|
540 | if params[:year] and params[:year].to_i > 1900 | |
542 | @year = params[:year].to_i |
|
541 | @year = params[:year].to_i | |
543 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
542 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
544 | @month = params[:month].to_i |
|
543 | @month = params[:month].to_i | |
545 | end |
|
544 | end | |
546 | end |
|
545 | end | |
547 | @year ||= Date.today.year |
|
546 | @year ||= Date.today.year | |
548 | @month ||= Date.today.month |
|
547 | @month ||= Date.today.month | |
549 |
|
548 | |||
550 | @date_from = Date.civil(@year, @month, 1) |
|
549 | @date_from = Date.civil(@year, @month, 1) | |
551 | @date_to = (@date_from >> 1)-1 |
|
550 | @date_to = (@date_from >> 1)-1 | |
552 | # start on monday |
|
551 | # start on monday | |
553 | @date_from = @date_from - (@date_from.cwday-1) |
|
552 | @date_from = @date_from - (@date_from.cwday-1) | |
554 | # finish on sunday |
|
553 | # finish on sunday | |
555 | @date_to = @date_to + (7-@date_to.cwday) |
|
554 | @date_to = @date_to + (7-@date_to.cwday) | |
556 |
|
555 | |||
557 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
556 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
558 | @issues = Issue.find(:all, |
|
557 | @issues = Issue.find(:all, | |
559 | :include => [:tracker, :status, :assigned_to, :priority], |
|
558 | :include => [:tracker, :status, :assigned_to, :priority], | |
560 | :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] | |
561 | ) unless @selected_tracker_ids.empty? |
|
560 | ) unless @selected_tracker_ids.empty? | |
562 | end |
|
561 | end | |
563 | @issues ||=[] |
|
562 | @issues ||=[] | |
564 |
|
563 | |||
565 | @ending_issues_by_days = @issues.group_by {|issue| issue.due_date} |
|
564 | @ending_issues_by_days = @issues.group_by {|issue| issue.due_date} | |
566 | @starting_issues_by_days = @issues.group_by {|issue| issue.start_date} |
|
565 | @starting_issues_by_days = @issues.group_by {|issue| issue.start_date} | |
567 |
|
566 | |||
568 | render :layout => false if request.xhr? |
|
567 | render :layout => false if request.xhr? | |
569 | end |
|
568 | end | |
570 |
|
569 | |||
571 | def gantt |
|
570 | def gantt | |
572 | @trackers = Tracker.find(:all, :order => 'position') |
|
571 | @trackers = Tracker.find(:all, :order => 'position') | |
573 | retrieve_selected_tracker_ids(@trackers) |
|
572 | retrieve_selected_tracker_ids(@trackers) | |
574 |
|
573 | |||
575 | if params[:year] and params[:year].to_i >0 |
|
574 | if params[:year] and params[:year].to_i >0 | |
576 | @year_from = params[:year].to_i |
|
575 | @year_from = params[:year].to_i | |
577 | 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 | |
578 | @month_from = params[:month].to_i |
|
577 | @month_from = params[:month].to_i | |
579 | else |
|
578 | else | |
580 | @month_from = 1 |
|
579 | @month_from = 1 | |
581 | end |
|
580 | end | |
582 | else |
|
581 | else | |
583 | @month_from ||= (Date.today << 1).month |
|
582 | @month_from ||= (Date.today << 1).month | |
584 | @year_from ||= (Date.today << 1).year |
|
583 | @year_from ||= (Date.today << 1).year | |
585 | end |
|
584 | end | |
586 |
|
585 | |||
587 | @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 | |
588 | @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 | |
589 |
|
588 | |||
590 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
589 | @date_from = Date.civil(@year_from, @month_from, 1) | |
591 | @date_to = (@date_from >> @months) - 1 |
|
590 | @date_to = (@date_from >> @months) - 1 | |
592 |
|
591 | |||
593 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
592 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
594 | @issues = Issue.find(:all, |
|
593 | @issues = Issue.find(:all, | |
595 | :order => "start_date, due_date", |
|
594 | :order => "start_date, due_date", | |
596 | :include => [:tracker, :status, :assigned_to, :priority], |
|
595 | :include => [:tracker, :status, :assigned_to, :priority], | |
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] |
|
596 | :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] | |
598 | ) unless @selected_tracker_ids.empty? |
|
597 | ) unless @selected_tracker_ids.empty? | |
599 | end |
|
598 | end | |
600 | @issues ||=[] |
|
599 | @issues ||=[] | |
601 |
|
600 | |||
602 | if params[:output]=='pdf' |
|
601 | if params[:output]=='pdf' | |
603 | @options_for_rfpdf ||= {} |
|
602 | @options_for_rfpdf ||= {} | |
604 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
603 | @options_for_rfpdf[:file_name] = "gantt.pdf" | |
605 | render :template => "projects/gantt.rfpdf", :layout => false |
|
604 | render :template => "projects/gantt.rfpdf", :layout => false | |
606 | else |
|
605 | else | |
607 | render :template => "projects/gantt.rhtml" |
|
606 | render :template => "projects/gantt.rhtml" | |
608 | end |
|
607 | end | |
609 | end |
|
608 | end | |
610 |
|
609 | |||
611 | def search |
|
610 | def search | |
612 | @question = params[:q] || "" |
|
611 | @question = params[:q] || "" | |
613 | @question.strip! |
|
612 | @question.strip! | |
614 | @all_words = params[:all_words] || (params[:submit] ? false : true) |
|
613 | @all_words = params[:all_words] || (params[:submit] ? false : true) | |
615 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) |
|
614 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) | |
616 | # tokens must be at least 3 character long |
|
615 | # tokens must be at least 3 character long | |
617 | @tokens = @question.split.uniq.select {|w| w.length > 2 } |
|
616 | @tokens = @question.split.uniq.select {|w| w.length > 2 } | |
618 | if !@tokens.empty? |
|
617 | if !@tokens.empty? | |
619 | # no more than 5 tokens to search for |
|
618 | # no more than 5 tokens to search for | |
620 | @tokens.slice! 5..-1 if @tokens.size > 5 |
|
619 | @tokens.slice! 5..-1 if @tokens.size > 5 | |
621 | # strings used in sql like statement |
|
620 | # strings used in sql like statement | |
622 | like_tokens = @tokens.collect {|w| "%#{w}%"} |
|
621 | like_tokens = @tokens.collect {|w| "%#{w}%"} | |
623 | operator = @all_words ? " AND " : " OR " |
|
622 | operator = @all_words ? " AND " : " OR " | |
624 | limit = 10 |
|
623 | limit = 10 | |
625 | @results = [] |
|
624 | @results = [] | |
626 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' |
|
625 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' | |
627 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' |
|
626 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' | |
628 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' |
|
627 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' | |
629 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') |
|
628 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') | |
630 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') |
|
629 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') | |
631 | @question = @tokens.join(" ") |
|
630 | @question = @tokens.join(" ") | |
632 | else |
|
631 | else | |
633 | @question = "" |
|
632 | @question = "" | |
634 | end |
|
633 | end | |
635 | end |
|
634 | end | |
636 |
|
635 | |||
637 | def feeds |
|
636 | def feeds | |
638 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
637 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] | |
639 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
638 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user | |
640 | end |
|
639 | end | |
641 |
|
640 | |||
642 | private |
|
641 | private | |
643 | # Find project of id params[:id] |
|
642 | # Find project of id params[:id] | |
644 | # if not found, redirect to project list |
|
643 | # if not found, redirect to project list | |
645 | # Used as a before_filter |
|
644 | # Used as a before_filter | |
646 | def find_project |
|
645 | def find_project | |
647 | @project = Project.find(params[:id]) |
|
646 | @project = Project.find(params[:id]) | |
648 | @html_title = @project.name |
|
647 | @html_title = @project.name | |
649 | rescue ActiveRecord::RecordNotFound |
|
648 | rescue ActiveRecord::RecordNotFound | |
650 | render_404 |
|
649 | render_404 | |
651 | end |
|
650 | end | |
652 |
|
651 | |||
653 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
652 | def retrieve_selected_tracker_ids(selectable_trackers) | |
654 | if ids = params[:tracker_ids] |
|
653 | if ids = params[:tracker_ids] | |
655 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
654 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
656 | else |
|
655 | else | |
657 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
656 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
658 | end |
|
657 | end | |
659 | end |
|
658 | end | |
660 |
|
659 | |||
661 | # Retrieve query from session or build a new query |
|
660 | # Retrieve query from session or build a new query | |
662 | def retrieve_query |
|
661 | def retrieve_query | |
663 | if params[:query_id] |
|
662 | if params[:query_id] | |
664 | @query = @project.queries.find(params[:query_id]) |
|
663 | @query = @project.queries.find(params[:query_id]) | |
665 | session[:query] = @query |
|
664 | session[:query] = @query | |
666 | else |
|
665 | else | |
667 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
666 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id | |
668 | # Give it a name, required to be valid |
|
667 | # Give it a name, required to be valid | |
669 | @query = Query.new(:name => "_") |
|
668 | @query = Query.new(:name => "_") | |
670 | @query.project = @project |
|
669 | @query.project = @project | |
671 | if params[:fields] and params[:fields].is_a? Array |
|
670 | if params[:fields] and params[:fields].is_a? Array | |
672 | params[:fields].each do |field| |
|
671 | params[:fields].each do |field| | |
673 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
672 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
674 | end |
|
673 | end | |
675 | else |
|
674 | else | |
676 | @query.available_filters.keys.each do |field| |
|
675 | @query.available_filters.keys.each do |field| | |
677 | @query.add_short_filter(field, params[field]) if params[field] |
|
676 | @query.add_short_filter(field, params[field]) if params[field] | |
678 | end |
|
677 | end | |
679 | end |
|
678 | end | |
680 | session[:query] = @query |
|
679 | session[:query] = @query | |
681 | else |
|
680 | else | |
682 | @query = session[:query] |
|
681 | @query = session[:query] | |
683 | end |
|
682 | end | |
684 | end |
|
683 | end | |
685 | end |
|
684 | end | |
686 | end |
|
685 | end |
@@ -1,230 +1,230 | |||||
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 | module ApplicationHelper |
|
18 | module ApplicationHelper | |
19 |
|
19 | |||
20 | # Return current logged in user or nil |
|
20 | # Return current logged in user or nil | |
21 | def loggedin? |
|
21 | def loggedin? | |
22 | @logged_in_user |
|
22 | @logged_in_user | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | # Return true if user is logged in and is admin, otherwise false |
|
25 | # Return true if user is logged in and is admin, otherwise false | |
26 | def admin_loggedin? |
|
26 | def admin_loggedin? | |
27 | @logged_in_user and @logged_in_user.admin? |
|
27 | @logged_in_user and @logged_in_user.admin? | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | # Return true if user is authorized for controller/action, otherwise false |
|
30 | # Return true if user is authorized for controller/action, otherwise false | |
31 | def authorize_for(controller, action) |
|
31 | def authorize_for(controller, action) | |
32 | # check if action is allowed on public projects |
|
32 | # check if action is allowed on public projects | |
33 | if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ] |
|
33 | if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ] | |
34 | return true |
|
34 | return true | |
35 | end |
|
35 | end | |
36 | # check if user is authorized |
|
36 | # check if user is authorized | |
37 |
if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project |
|
37 | if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project) ) ) | |
38 | return true |
|
38 | return true | |
39 | end |
|
39 | end | |
40 | return false |
|
40 | return false | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | # Display a link if user is authorized |
|
43 | # Display a link if user is authorized | |
44 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
44 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) | |
45 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action]) |
|
45 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action]) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | # Display a link to user's account page |
|
48 | # Display a link to user's account page | |
49 | def link_to_user(user) |
|
49 | def link_to_user(user) | |
50 | link_to user.display_name, :controller => 'account', :action => 'show', :id => user |
|
50 | link_to user.display_name, :controller => 'account', :action => 'show', :id => user | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def image_to_function(name, function, html_options = {}) |
|
53 | def image_to_function(name, function, html_options = {}) | |
54 | html_options.symbolize_keys! |
|
54 | html_options.symbolize_keys! | |
55 | tag(:input, html_options.merge({ |
|
55 | tag(:input, html_options.merge({ | |
56 | :type => "image", :src => image_path(name), |
|
56 | :type => "image", :src => image_path(name), | |
57 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" |
|
57 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" | |
58 | })) |
|
58 | })) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def format_date(date) |
|
61 | def format_date(date) | |
62 | l_date(date) if date |
|
62 | l_date(date) if date | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def format_time(time) |
|
65 | def format_time(time) | |
66 | l_datetime((time.is_a? String) ? time.to_time : time) if time |
|
66 | l_datetime((time.is_a? String) ? time.to_time : time) if time | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def day_name(day) |
|
69 | def day_name(day) | |
70 | l(:general_day_names).split(',')[day-1] |
|
70 | l(:general_day_names).split(',')[day-1] | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def month_name(month) |
|
73 | def month_name(month) | |
74 | l(:actionview_datehelper_select_month_names).split(',')[month-1] |
|
74 | l(:actionview_datehelper_select_month_names).split(',')[month-1] | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def pagination_links_full(paginator, options={}, html_options={}) |
|
77 | def pagination_links_full(paginator, options={}, html_options={}) | |
78 | html = '' |
|
78 | html = '' | |
79 | html << link_to_remote(('« ' + l(:label_previous)), |
|
79 | html << link_to_remote(('« ' + l(:label_previous)), | |
80 | {:update => "content", :url => options.merge(:page => paginator.current.previous)}, |
|
80 | {:update => "content", :url => options.merge(:page => paginator.current.previous)}, | |
81 | {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous |
|
81 | {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous | |
82 |
|
82 | |||
83 | html << (pagination_links_each(paginator, options) do |n| |
|
83 | html << (pagination_links_each(paginator, options) do |n| | |
84 | link_to_remote(n.to_s, |
|
84 | link_to_remote(n.to_s, | |
85 | {:url => {:action => 'list', :params => options.merge(:page => n)}, :update => 'content'}, |
|
85 | {:url => {:action => 'list', :params => options.merge(:page => n)}, :update => 'content'}, | |
86 | {:href => url_for(:params => options.merge(:page => n))}) |
|
86 | {:href => url_for(:params => options.merge(:page => n))}) | |
87 | end || '') |
|
87 | end || '') | |
88 |
|
88 | |||
89 | html << ' ' + link_to_remote((l(:label_next) + ' »'), |
|
89 | html << ' ' + link_to_remote((l(:label_next) + ' »'), | |
90 | {:update => "content", :url => options.merge(:page => paginator.current.next)}, |
|
90 | {:update => "content", :url => options.merge(:page => paginator.current.next)}, | |
91 | {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next |
|
91 | {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next | |
92 | html |
|
92 | html | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | # textilize text according to system settings and RedCloth availability |
|
95 | # textilize text according to system settings and RedCloth availability | |
96 | def textilizable(text, options = {}) |
|
96 | def textilizable(text, options = {}) | |
97 | # different methods for formatting wiki links |
|
97 | # different methods for formatting wiki links | |
98 | case options[:wiki_links] |
|
98 | case options[:wiki_links] | |
99 | when :local |
|
99 | when :local | |
100 | # used for local links to html files |
|
100 | # used for local links to html files | |
101 | format_wiki_link = Proc.new {|title| "#{title}.html" } |
|
101 | format_wiki_link = Proc.new {|title| "#{title}.html" } | |
102 | when :anchor |
|
102 | when :anchor | |
103 | # used for single-file wiki export |
|
103 | # used for single-file wiki export | |
104 | format_wiki_link = Proc.new {|title| "##{title}" } |
|
104 | format_wiki_link = Proc.new {|title| "##{title}" } | |
105 | else |
|
105 | else | |
106 | if @project |
|
106 | if @project | |
107 | format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title } |
|
107 | format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title } | |
108 | else |
|
108 | else | |
109 | format_wiki_link = Proc.new {|title| title } |
|
109 | format_wiki_link = Proc.new {|title| title } | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | # turn wiki links into textile links: |
|
113 | # turn wiki links into textile links: | |
114 | # example: |
|
114 | # example: | |
115 | # [[link]] -> "link":link |
|
115 | # [[link]] -> "link":link | |
116 | # [[link|title]] -> "title":link |
|
116 | # [[link|title]] -> "title":link | |
117 | text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) } |
|
117 | text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) } | |
118 |
|
118 | |||
119 | # turn issue ids to textile links |
|
119 | # turn issue ids to textile links | |
120 | # example: |
|
120 | # example: | |
121 | # #52 -> "#52":/issues/show/52 |
|
121 | # #52 -> "#52":/issues/show/52 | |
122 | text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) } |
|
122 | text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) } | |
123 |
|
123 | |||
124 | # turn revision ids to textile links (@project needed) |
|
124 | # turn revision ids to textile links (@project needed) | |
125 | # example: |
|
125 | # example: | |
126 | # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6) |
|
126 | # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6) | |
127 | text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project |
|
127 | text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project | |
128 |
|
128 | |||
129 | # finally textilize text |
|
129 | # finally textilize text | |
130 | @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") |
|
130 | @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize") | |
131 | text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text))) |
|
131 | text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text))) | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def error_messages_for(object_name, options = {}) |
|
134 | def error_messages_for(object_name, options = {}) | |
135 | options = options.symbolize_keys |
|
135 | options = options.symbolize_keys | |
136 | object = instance_variable_get("@#{object_name}") |
|
136 | object = instance_variable_get("@#{object_name}") | |
137 | if object && !object.errors.empty? |
|
137 | if object && !object.errors.empty? | |
138 | # build full_messages here with controller current language |
|
138 | # build full_messages here with controller current language | |
139 | full_messages = [] |
|
139 | full_messages = [] | |
140 | object.errors.each do |attr, msg| |
|
140 | object.errors.each do |attr, msg| | |
141 | next if msg.nil? |
|
141 | next if msg.nil? | |
142 | msg = msg.first if msg.is_a? Array |
|
142 | msg = msg.first if msg.is_a? Array | |
143 | if attr == "base" |
|
143 | if attr == "base" | |
144 | full_messages << l(msg) |
|
144 | full_messages << l(msg) | |
145 | else |
|
145 | else | |
146 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" |
|
146 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" | |
147 | end |
|
147 | end | |
148 | end |
|
148 | end | |
149 | # retrieve custom values error messages |
|
149 | # retrieve custom values error messages | |
150 | if object.errors[:custom_values] |
|
150 | if object.errors[:custom_values] | |
151 | object.custom_values.each do |v| |
|
151 | object.custom_values.each do |v| | |
152 | v.errors.each do |attr, msg| |
|
152 | v.errors.each do |attr, msg| | |
153 | next if msg.nil? |
|
153 | next if msg.nil? | |
154 | msg = msg.first if msg.is_a? Array |
|
154 | msg = msg.first if msg.is_a? Array | |
155 | full_messages << "« " + v.custom_field.name + " » " + l(msg) |
|
155 | full_messages << "« " + v.custom_field.name + " » " + l(msg) | |
156 | end |
|
156 | end | |
157 | end |
|
157 | end | |
158 | end |
|
158 | end | |
159 | content_tag("div", |
|
159 | content_tag("div", | |
160 | content_tag( |
|
160 | content_tag( | |
161 | options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :" |
|
161 | options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :" | |
162 | ) + |
|
162 | ) + | |
163 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), |
|
163 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), | |
164 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" |
|
164 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" | |
165 | ) |
|
165 | ) | |
166 | else |
|
166 | else | |
167 | "" |
|
167 | "" | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | def lang_options_for_select(blank=true) |
|
171 | def lang_options_for_select(blank=true) | |
172 | (blank ? [["(auto)", ""]] : []) + |
|
172 | (blank ? [["(auto)", ""]] : []) + | |
173 | (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]} |
|
173 | (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]} | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | def label_tag_for(name, option_tags = nil, options = {}) |
|
176 | def label_tag_for(name, option_tags = nil, options = {}) | |
177 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
177 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") | |
178 | content_tag("label", label_text) |
|
178 | content_tag("label", label_text) | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def labelled_tabular_form_for(name, object, options, &proc) |
|
181 | def labelled_tabular_form_for(name, object, options, &proc) | |
182 | options[:html] ||= {} |
|
182 | options[:html] ||= {} | |
183 | options[:html].store :class, "tabular" |
|
183 | options[:html].store :class, "tabular" | |
184 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) |
|
184 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def check_all_links(form_name) |
|
187 | def check_all_links(form_name) | |
188 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
188 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + | |
189 | " | " + |
|
189 | " | " + | |
190 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
190 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | def calendar_for(field_id) |
|
193 | def calendar_for(field_id) | |
194 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + |
|
194 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + | |
195 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") |
|
195 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") | |
196 | end |
|
196 | end | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | class TabularFormBuilder < ActionView::Helpers::FormBuilder |
|
199 | class TabularFormBuilder < ActionView::Helpers::FormBuilder | |
200 | include GLoc |
|
200 | include GLoc | |
201 |
|
201 | |||
202 | def initialize(object_name, object, template, options, proc) |
|
202 | def initialize(object_name, object, template, options, proc) | |
203 | set_language_if_valid options.delete(:lang) |
|
203 | set_language_if_valid options.delete(:lang) | |
204 | @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc |
|
204 | @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector| |
|
207 | (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector| | |
208 | src = <<-END_SRC |
|
208 | src = <<-END_SRC | |
209 | def #{selector}(field, options = {}) |
|
209 | def #{selector}(field, options = {}) | |
210 | return super if options.delete :no_label |
|
210 | return super if options.delete :no_label | |
211 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
211 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") | |
212 | label = @template.content_tag("label", label_text, |
|
212 | label = @template.content_tag("label", label_text, | |
213 | :class => (@object && @object.errors[field] ? "error" : nil), |
|
213 | :class => (@object && @object.errors[field] ? "error" : nil), | |
214 | :for => (@object_name.to_s + "_" + field.to_s)) |
|
214 | :for => (@object_name.to_s + "_" + field.to_s)) | |
215 | label + super |
|
215 | label + super | |
216 | end |
|
216 | end | |
217 | END_SRC |
|
217 | END_SRC | |
218 | class_eval src, __FILE__, __LINE__ |
|
218 | class_eval src, __FILE__, __LINE__ | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def select(field, choices, options = {}, html_options = {}) |
|
221 | def select(field, choices, options = {}, html_options = {}) | |
222 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
222 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") | |
223 | label = @template.content_tag("label", label_text, |
|
223 | label = @template.content_tag("label", label_text, | |
224 | :class => (@object && @object.errors[field] ? "error" : nil), |
|
224 | :class => (@object && @object.errors[field] ? "error" : nil), | |
225 | :for => (@object_name.to_s + "_" + field.to_s)) |
|
225 | :for => (@object_name.to_s + "_" + field.to_s)) | |
226 | label + super |
|
226 | label + super | |
227 | end |
|
227 | end | |
228 |
|
228 | |||
229 | end |
|
229 | end | |
230 |
|
230 |
@@ -1,51 +1,58 | |||||
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 IssueStatus < ActiveRecord::Base |
|
18 | class IssueStatus < ActiveRecord::Base | |
19 | before_destroy :check_integrity |
|
19 | before_destroy :check_integrity | |
20 | has_many :workflows, :foreign_key => "old_status_id" |
|
20 | has_many :workflows, :foreign_key => "old_status_id" | |
21 | acts_as_list |
|
21 | acts_as_list | |
22 |
|
22 | |||
23 | validates_presence_of :name |
|
23 | validates_presence_of :name | |
24 | validates_uniqueness_of :name |
|
24 | validates_uniqueness_of :name | |
25 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
25 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i | |
26 | validates_length_of :html_color, :is => 6 |
|
26 | validates_length_of :html_color, :is => 6 | |
27 | validates_format_of :html_color, :with => /^[a-f0-9]*$/i |
|
27 | validates_format_of :html_color, :with => /^[a-f0-9]*$/i | |
28 |
|
28 | |||
29 | def before_save |
|
29 | def before_save | |
30 | IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default? |
|
30 | IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default? | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | # Returns the default status for new issues |
|
33 | # Returns the default status for new issues | |
34 | def self.default |
|
34 | def self.default | |
35 | find(:first, :conditions =>["is_default=?", true]) |
|
35 | find(:first, :conditions =>["is_default=?", true]) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | # Returns an array of all statuses the given role can switch to |
|
38 | # Returns an array of all statuses the given role can switch to | |
|
39 | # Uses association cache when called more than one time | |||
39 | def new_statuses_allowed_to(role, tracker) |
|
40 | def new_statuses_allowed_to(role, tracker) | |
40 | statuses = [] |
|
41 | new_statuses = [self] + workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} | |
41 | for workflow in self.workflows |
|
42 | new_statuses.sort{|x, y| x.position <=> y.position } | |
42 | statuses << workflow.new_status if workflow.role_id == role.id and workflow.tracker_id == tracker.id |
|
43 | end | |
43 | end unless role.nil? or tracker.nil? |
|
44 | ||
44 | statuses |
|
45 | # Same thing as above but uses a database query | |
|
46 | # More efficient than the previous method if called just once | |||
|
47 | def find_new_statuses_allowed_to(role, tracker) | |||
|
48 | new_statuses = [self] + workflows.find(:all, | |||
|
49 | :include => :new_status, | |||
|
50 | :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status } | |||
|
51 | new_statuses.sort{|x, y| x.position <=> y.position } | |||
45 | end |
|
52 | end | |
46 |
|
53 | |||
47 | private |
|
54 | private | |
48 | def check_integrity |
|
55 | def check_integrity | |
49 | raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) |
|
56 | raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) | |
50 | end |
|
57 | end | |
51 | end |
|
58 | end |
@@ -1,66 +1,66 | |||||
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 Permission < ActiveRecord::Base |
|
18 | class Permission < ActiveRecord::Base | |
19 | has_and_belongs_to_many :roles |
|
19 | has_and_belongs_to_many :roles | |
20 |
|
20 | |||
21 | validates_presence_of :controller, :action, :description |
|
21 | validates_presence_of :controller, :action, :description | |
22 |
|
22 | |||
23 | GROUPS = { |
|
23 | GROUPS = { | |
24 | 100 => :label_project, |
|
24 | 100 => :label_project, | |
25 | 200 => :label_member_plural, |
|
25 | 200 => :label_member_plural, | |
26 | 300 => :label_version_plural, |
|
26 | 300 => :label_version_plural, | |
27 | 400 => :label_issue_category_plural, |
|
27 | 400 => :label_issue_category_plural, | |
28 | 600 => :label_query_plural, |
|
28 | 600 => :label_query_plural, | |
29 | 1000 => :label_issue_plural, |
|
29 | 1000 => :label_issue_plural, | |
30 | 1100 => :label_news_plural, |
|
30 | 1100 => :label_news_plural, | |
31 | 1200 => :label_document_plural, |
|
31 | 1200 => :label_document_plural, | |
32 | 1300 => :label_attachment_plural, |
|
32 | 1300 => :label_attachment_plural, | |
33 | 1400 => :label_repository, |
|
33 | 1400 => :label_repository, | |
34 | 1500 => :label_time_tracking |
|
34 | 1500 => :label_time_tracking | |
35 | }.freeze |
|
35 | }.freeze | |
36 |
|
36 | |||
37 | @@cached_perms_for_public = nil |
|
37 | @@cached_perms_for_public = nil | |
38 | @@cached_perms_for_roles = nil |
|
38 | @@cached_perms_for_roles = nil | |
39 |
|
39 | |||
40 | def name |
|
40 | def name | |
41 | self.controller + "/" + self.action |
|
41 | self.controller + "/" + self.action | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def group_id |
|
44 | def group_id | |
45 | (self.sort / 100)*100 |
|
45 | (self.sort / 100)*100 | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def self.allowed_to_public(action) |
|
48 | def self.allowed_to_public(action) | |
49 | @@cached_perms_for_public ||= find(:all, :conditions => ["is_public=?", true]).collect {|p| "#{p.controller}/#{p.action}"} |
|
49 | @@cached_perms_for_public ||= find(:all, :conditions => ["is_public=?", true]).collect {|p| "#{p.controller}/#{p.action}"} | |
50 | @@cached_perms_for_public.include? action |
|
50 | @@cached_perms_for_public.include? action | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def self.allowed_to_role(action, role) |
|
53 | def self.allowed_to_role(action, role) | |
54 | @@cached_perms_for_roles ||= |
|
54 | @@cached_perms_for_roles ||= | |
55 | begin |
|
55 | begin | |
56 | perms = {} |
|
56 | perms = {} | |
57 | find(:all, :include => :roles).each {|p| perms.store "#{p.controller}/#{p.action}", p.roles.collect {|r| r.id } } |
|
57 | find(:all, :include => :roles).each {|p| perms.store "#{p.controller}/#{p.action}", p.roles.collect {|r| r.id } } | |
58 | perms |
|
58 | perms | |
59 | end |
|
59 | end | |
60 |
allowed_to_public(action) or (@@cached_perms_for_roles[action] |
|
60 | allowed_to_public(action) or (role && @@cached_perms_for_roles[action] && @@cached_perms_for_roles[action].include?(role.id)) | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def self.allowed_to_role_expired |
|
63 | def self.allowed_to_role_expired | |
64 | @@cached_perms_for_roles = nil |
|
64 | @@cached_perms_for_roles = nil | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end |
@@ -1,155 +1,149 | |||||
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 | has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" |
|
25 | has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" | |
26 | belongs_to :auth_source |
|
26 | belongs_to :auth_source | |
27 |
|
27 | |||
28 | attr_accessor :password, :password_confirmation |
|
28 | attr_accessor :password, :password_confirmation | |
29 | attr_accessor :last_before_login_on |
|
29 | attr_accessor :last_before_login_on | |
30 | # Prevents unauthorized assignments |
|
30 | # Prevents unauthorized assignments | |
31 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
31 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password | |
32 |
|
32 | |||
33 | validates_presence_of :login, :firstname, :lastname, :mail |
|
33 | validates_presence_of :login, :firstname, :lastname, :mail | |
34 | validates_uniqueness_of :login, :mail |
|
34 | validates_uniqueness_of :login, :mail | |
35 | # Login must contain lettres, numbers, underscores only |
|
35 | # Login must contain lettres, numbers, underscores only | |
36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i |
|
36 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i | |
37 | validates_length_of :login, :maximum => 30 |
|
37 | validates_length_of :login, :maximum => 30 | |
38 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
38 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i | |
39 | validates_length_of :firstname, :lastname, :maximum => 30 |
|
39 | validates_length_of :firstname, :lastname, :maximum => 30 | |
40 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i |
|
40 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i | |
41 | validates_length_of :mail, :maximum => 60 |
|
41 | validates_length_of :mail, :maximum => 60 | |
42 | # Password length between 4 and 12 |
|
42 | # Password length between 4 and 12 | |
43 | validates_length_of :password, :in => 4..12, :allow_nil => true |
|
43 | validates_length_of :password, :in => 4..12, :allow_nil => true | |
44 | validates_confirmation_of :password, :allow_nil => true |
|
44 | validates_confirmation_of :password, :allow_nil => true | |
45 | validates_associated :custom_values, :on => :update |
|
45 | validates_associated :custom_values, :on => :update | |
46 |
|
46 | |||
47 | # Account statuses |
|
47 | # Account statuses | |
48 | STATUS_ACTIVE = 1 |
|
48 | STATUS_ACTIVE = 1 | |
49 | STATUS_REGISTERED = 2 |
|
49 | STATUS_REGISTERED = 2 | |
50 | STATUS_LOCKED = 3 |
|
50 | STATUS_LOCKED = 3 | |
51 |
|
51 | |||
52 | def before_save |
|
52 | def before_save | |
53 | # update hashed_password if password was set |
|
53 | # update hashed_password if password was set | |
54 | self.hashed_password = User.hash_password(self.password) if self.password |
|
54 | self.hashed_password = User.hash_password(self.password) if self.password | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def self.active |
|
57 | def self.active | |
58 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do |
|
58 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do | |
59 | yield |
|
59 | yield | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def self.find_active(*args) |
|
63 | def self.find_active(*args) | |
64 | active do |
|
64 | active do | |
65 | find(*args) |
|
65 | find(*args) | |
66 | end |
|
66 | end | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | # Returns the user that matches provided login and password, or nil |
|
69 | # Returns the user that matches provided login and password, or nil | |
70 | def self.try_to_login(login, password) |
|
70 | def self.try_to_login(login, password) | |
71 | user = find(:first, :conditions => ["login=?", login]) |
|
71 | user = find(:first, :conditions => ["login=?", login]) | |
72 | if user |
|
72 | if user | |
73 | # user is already in local database |
|
73 | # user is already in local database | |
74 | return nil if !user.active? |
|
74 | return nil if !user.active? | |
75 | if user.auth_source |
|
75 | if user.auth_source | |
76 | # user has an external authentication method |
|
76 | # user has an external authentication method | |
77 | return nil unless user.auth_source.authenticate(login, password) |
|
77 | return nil unless user.auth_source.authenticate(login, password) | |
78 | else |
|
78 | else | |
79 | # authentication with local password |
|
79 | # authentication with local password | |
80 | return nil unless User.hash_password(password) == user.hashed_password |
|
80 | return nil unless User.hash_password(password) == user.hashed_password | |
81 | end |
|
81 | end | |
82 | else |
|
82 | else | |
83 | # user is not yet registered, try to authenticate with available sources |
|
83 | # user is not yet registered, try to authenticate with available sources | |
84 | attrs = AuthSource.authenticate(login, password) |
|
84 | attrs = AuthSource.authenticate(login, password) | |
85 | if attrs |
|
85 | if attrs | |
86 | onthefly = new(*attrs) |
|
86 | onthefly = new(*attrs) | |
87 | onthefly.login = login |
|
87 | onthefly.login = login | |
88 | onthefly.language = Setting.default_language |
|
88 | onthefly.language = Setting.default_language | |
89 | if onthefly.save |
|
89 | if onthefly.save | |
90 | user = find(:first, :conditions => ["login=?", login]) |
|
90 | user = find(:first, :conditions => ["login=?", login]) | |
91 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
91 | logger.info("User '#{user.login}' created on the fly.") if logger | |
92 | end |
|
92 | end | |
93 | end |
|
93 | end | |
94 | end |
|
94 | end | |
95 | user.update_attribute(:last_login_on, Time.now) if user |
|
95 | user.update_attribute(:last_login_on, Time.now) if user | |
96 | user |
|
96 | user | |
97 |
|
97 | |||
98 | rescue => text |
|
98 | rescue => text | |
99 | raise text |
|
99 | raise text | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | # Return user's full name for display |
|
102 | # Return user's full name for display | |
103 | def display_name |
|
103 | def display_name | |
104 | firstname + " " + lastname |
|
104 | firstname + " " + lastname | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def name |
|
107 | def name | |
108 | display_name |
|
108 | display_name | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def active? |
|
111 | def active? | |
112 | self.status == STATUS_ACTIVE |
|
112 | self.status == STATUS_ACTIVE | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def registered? |
|
115 | def registered? | |
116 | self.status == STATUS_REGISTERED |
|
116 | self.status == STATUS_REGISTERED | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def locked? |
|
119 | def locked? | |
120 | self.status == STATUS_LOCKED |
|
120 | self.status == STATUS_LOCKED | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | def check_password?(clear_password) |
|
123 | def check_password?(clear_password) | |
124 | User.hash_password(clear_password) == self.hashed_password |
|
124 | User.hash_password(clear_password) == self.hashed_password | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 |
def role_for_project(project |
|
127 | def role_for_project(project) | |
128 | @role_for_projects ||= |
|
128 | memberships.detect {|m| m.project_id == project.id} | |
129 | begin |
|
|||
130 | roles = {} |
|
|||
131 | self.memberships.each { |m| roles.store m.project_id, m.role_id } |
|
|||
132 | roles |
|
|||
133 | end |
|
|||
134 | @role_for_projects[project_id] |
|
|||
135 | end |
|
129 | end | |
136 |
|
130 | |||
137 | def pref |
|
131 | def pref | |
138 | self.preference ||= UserPreference.new(:user => self) |
|
132 | self.preference ||= UserPreference.new(:user => self) | |
139 | end |
|
133 | end | |
140 |
|
134 | |||
141 | def get_or_create_rss_key |
|
135 | def get_or_create_rss_key | |
142 | self.rss_key || Token.create(:user => self, :action => 'feeds') |
|
136 | self.rss_key || Token.create(:user => self, :action => 'feeds') | |
143 | end |
|
137 | end | |
144 |
|
138 | |||
145 | def self.find_by_rss_key(key) |
|
139 | def self.find_by_rss_key(key) | |
146 | token = Token.find_by_value(key) |
|
140 | token = Token.find_by_value(key) | |
147 | token && token.user.active? ? token.user : nil |
|
141 | token && token.user.active? ? token.user : nil | |
148 | end |
|
142 | end | |
149 |
|
143 | |||
150 | private |
|
144 | private | |
151 | # Return password digest |
|
145 | # Return password digest | |
152 | def self.hash_password(clear_password) |
|
146 | def self.hash_password(clear_password) | |
153 | Digest::SHA1.hexdigest(clear_password || "") |
|
147 | Digest::SHA1.hexdigest(clear_password || "") | |
154 | end |
|
148 | end | |
155 | end |
|
149 | end |
General Comments 0
You need to be logged in to leave comments.
Login now