@@ -1,166 +1,179 | |||||
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 :user_setup, :check_if_login_required, :set_localization |
|
19 | before_filter :user_setup, :check_if_login_required, :set_localization | |
20 | filter_parameter_logging :password |
|
20 | filter_parameter_logging :password | |
21 |
|
21 | |||
22 | REDMINE_SUPPORTED_SCM.each do |scm| |
|
22 | REDMINE_SUPPORTED_SCM.each do |scm| | |
23 | require_dependency "repository/#{scm.underscore}" |
|
23 | require_dependency "repository/#{scm.underscore}" | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def current_role |
|
26 | def current_role | |
27 | @current_role ||= User.current.role_for_project(@project) |
|
27 | @current_role ||= User.current.role_for_project(@project) | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def user_setup |
|
30 | def user_setup | |
31 | Setting.check_cache |
|
31 | Setting.check_cache | |
32 | if session[:user_id] |
|
32 | if session[:user_id] | |
33 | # existing session |
|
33 | # existing session | |
34 | User.current = User.find(session[:user_id]) |
|
34 | User.current = User.find(session[:user_id]) | |
35 | elsif cookies[:autologin] && Setting.autologin? |
|
35 | elsif cookies[:autologin] && Setting.autologin? | |
36 | # auto-login feature |
|
36 | # auto-login feature | |
37 | User.current = User.find_by_autologin_key(cookies[:autologin]) |
|
37 | User.current = User.find_by_autologin_key(cookies[:autologin]) | |
38 | elsif params[:key] && accept_key_auth_actions.include?(params[:action]) |
|
38 | elsif params[:key] && accept_key_auth_actions.include?(params[:action]) | |
39 | # RSS key authentication |
|
39 | # RSS key authentication | |
40 | User.current = User.find_by_rss_key(params[:key]) |
|
40 | User.current = User.find_by_rss_key(params[:key]) | |
41 | else |
|
41 | else | |
42 | User.current = User.anonymous |
|
42 | User.current = User.anonymous | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | # check if login is globally required to access the application |
|
46 | # check if login is globally required to access the application | |
47 | def check_if_login_required |
|
47 | def check_if_login_required | |
48 | # no check needed if user is already logged in |
|
48 | # no check needed if user is already logged in | |
49 | return true if User.current.logged? |
|
49 | return true if User.current.logged? | |
50 | require_login if Setting.login_required? |
|
50 | require_login if Setting.login_required? | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def set_localization |
|
53 | def set_localization | |
54 | lang = begin |
|
54 | lang = begin | |
55 | if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym |
|
55 | if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym | |
56 | User.current.language |
|
56 | User.current.language | |
57 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] |
|
57 | elsif request.env['HTTP_ACCEPT_LANGUAGE'] | |
58 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first |
|
58 | accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first | |
59 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym |
|
59 | if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym | |
60 | accept_lang |
|
60 | accept_lang | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 | rescue |
|
63 | rescue | |
64 | nil |
|
64 | nil | |
65 | end || Setting.default_language |
|
65 | end || Setting.default_language | |
66 | set_language_if_valid(lang) |
|
66 | set_language_if_valid(lang) | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def require_login |
|
69 | def require_login | |
70 | if !User.current.logged? |
|
70 | if !User.current.logged? | |
71 | store_location |
|
71 | store_location | |
72 | redirect_to :controller => "account", :action => "login" |
|
72 | redirect_to :controller => "account", :action => "login" | |
73 | return false |
|
73 | return false | |
74 | end |
|
74 | end | |
75 | true |
|
75 | true | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def require_admin |
|
78 | def require_admin | |
79 | return unless require_login |
|
79 | return unless require_login | |
80 | if !User.current.admin? |
|
80 | if !User.current.admin? | |
81 | render_403 |
|
81 | render_403 | |
82 | return false |
|
82 | return false | |
83 | end |
|
83 | end | |
84 | true |
|
84 | true | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | # Authorize the user for the requested action |
|
87 | # Authorize the user for the requested action | |
88 | def authorize(ctrl = params[:controller], action = params[:action]) |
|
88 | def authorize(ctrl = params[:controller], action = params[:action]) | |
89 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project) |
|
89 | allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project) | |
90 | allowed ? true : (User.current.logged? ? render_403 : require_login) |
|
90 | allowed ? true : (User.current.logged? ? render_403 : require_login) | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | # make sure that the user is a member of the project (or admin) if project is private |
|
93 | # make sure that the user is a member of the project (or admin) if project is private | |
94 | # used as a before_filter for actions that do not require any particular permission on the project |
|
94 | # used as a before_filter for actions that do not require any particular permission on the project | |
95 | def check_project_privacy |
|
95 | def check_project_privacy | |
96 | unless @project.active? |
|
96 | unless @project.active? | |
97 | @project = nil |
|
97 | @project = nil | |
98 | render_404 |
|
98 | render_404 | |
99 | return false |
|
99 | return false | |
100 | end |
|
100 | end | |
101 | return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin? |
|
101 | return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin? | |
102 | User.current.logged? ? render_403 : require_login |
|
102 | User.current.logged? ? render_403 : require_login | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | # store current uri in session. |
|
105 | # store current uri in session. | |
106 | # return to this location by calling redirect_back_or_default |
|
106 | # return to this location by calling redirect_back_or_default | |
107 | def store_location |
|
107 | def store_location | |
108 | session[:return_to_params] = params |
|
108 | session[:return_to_params] = params | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | # move to the last store_location call or to the passed default one |
|
111 | # move to the last store_location call or to the passed default one | |
112 | def redirect_back_or_default(default) |
|
112 | def redirect_back_or_default(default) | |
113 | if session[:return_to_params].nil? |
|
113 | if session[:return_to_params].nil? | |
114 | redirect_to default |
|
114 | redirect_to default | |
115 | else |
|
115 | else | |
116 | redirect_to session[:return_to_params] |
|
116 | redirect_to session[:return_to_params] | |
117 | session[:return_to_params] = nil |
|
117 | session[:return_to_params] = nil | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def render_403 |
|
121 | def render_403 | |
122 | @project = nil |
|
122 | @project = nil | |
123 | render :template => "common/403", :layout => !request.xhr?, :status => 403 |
|
123 | render :template => "common/403", :layout => !request.xhr?, :status => 403 | |
124 | return false |
|
124 | return false | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def render_404 |
|
127 | def render_404 | |
128 | render :template => "common/404", :layout => !request.xhr?, :status => 404 |
|
128 | render :template => "common/404", :layout => !request.xhr?, :status => 404 | |
129 | return false |
|
129 | return false | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def render_feed(items, options={}) |
|
132 | def render_feed(items, options={}) | |
133 | @items = items || [] |
|
133 | @items = items || [] | |
134 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } |
|
134 | @items.sort! {|x,y| y.event_datetime <=> x.event_datetime } | |
135 | @title = options[:title] || Setting.app_title |
|
135 | @title = options[:title] || Setting.app_title | |
136 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' |
|
136 | render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml' | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def self.accept_key_auth(*actions) |
|
139 | def self.accept_key_auth(*actions) | |
140 | actions = actions.flatten.map(&:to_s) |
|
140 | actions = actions.flatten.map(&:to_s) | |
141 | write_inheritable_attribute('accept_key_auth_actions', actions) |
|
141 | write_inheritable_attribute('accept_key_auth_actions', actions) | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def accept_key_auth_actions |
|
144 | def accept_key_auth_actions | |
145 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] |
|
145 | self.class.read_inheritable_attribute('accept_key_auth_actions') || [] | |
146 | end |
|
146 | end | |
|
147 | ||||
|
148 | # TODO: move to model | |||
|
149 | def attach_files(obj, files) | |||
|
150 | attachments = [] | |||
|
151 | if files && files.is_a?(Array) | |||
|
152 | files.each do |file| | |||
|
153 | next unless file.size > 0 | |||
|
154 | a = Attachment.create(:container => obj, :file => file, :author => User.current) | |||
|
155 | attachments << a unless a.new_record? | |||
|
156 | end | |||
|
157 | end | |||
|
158 | attachments | |||
|
159 | end | |||
147 |
|
160 | |||
148 | # qvalues http header parser |
|
161 | # qvalues http header parser | |
149 | # code taken from webrick |
|
162 | # code taken from webrick | |
150 | def parse_qvalues(value) |
|
163 | def parse_qvalues(value) | |
151 | tmp = [] |
|
164 | tmp = [] | |
152 | if value |
|
165 | if value | |
153 | parts = value.split(/,\s*/) |
|
166 | parts = value.split(/,\s*/) | |
154 | parts.each {|part| |
|
167 | parts.each {|part| | |
155 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) |
|
168 | if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) | |
156 | val = m[1] |
|
169 | val = m[1] | |
157 | q = (m[2] or 1).to_f |
|
170 | q = (m[2] or 1).to_f | |
158 | tmp.push([val, q]) |
|
171 | tmp.push([val, q]) | |
159 | end |
|
172 | end | |
160 | } |
|
173 | } | |
161 | tmp = tmp.sort_by{|val, q| -q} |
|
174 | tmp = tmp.sort_by{|val, q| -q} | |
162 | tmp.collect!{|val, q| val} |
|
175 | tmp.collect!{|val, q| val} | |
163 | end |
|
176 | end | |
164 | return tmp |
|
177 | return tmp | |
165 | end |
|
178 | end | |
166 | end |
|
179 | end |
@@ -1,71 +1,65 | |||||
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 DocumentsController < ApplicationController |
|
18 | class DocumentsController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :find_project, :authorize |
|
20 | before_filter :find_project, :authorize | |
21 |
|
21 | |||
22 | def show |
|
22 | def show | |
23 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") |
|
23 | @attachments = @document.attachments.find(:all, :order => "created_on DESC") | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def edit |
|
26 | def edit | |
27 | @categories = Enumeration::get_values('DCAT') |
|
27 | @categories = Enumeration::get_values('DCAT') | |
28 | if request.post? and @document.update_attributes(params[:document]) |
|
28 | if request.post? and @document.update_attributes(params[:document]) | |
29 | flash[:notice] = l(:notice_successful_update) |
|
29 | flash[:notice] = l(:notice_successful_update) | |
30 | redirect_to :action => 'show', :id => @document |
|
30 | redirect_to :action => 'show', :id => @document | |
31 | end |
|
31 | end | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def destroy |
|
34 | def destroy | |
35 | @document.destroy |
|
35 | @document.destroy | |
36 | redirect_to :controller => 'projects', :action => 'list_documents', :id => @project |
|
36 | redirect_to :controller => 'projects', :action => 'list_documents', :id => @project | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def download |
|
39 | def download | |
40 | @attachment = @document.attachments.find(params[:attachment_id]) |
|
40 | @attachment = @document.attachments.find(params[:attachment_id]) | |
41 | @attachment.increment_download |
|
41 | @attachment.increment_download | |
42 | send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type |
|
42 | send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type | |
43 | rescue |
|
43 | rescue | |
44 | render_404 |
|
44 | render_404 | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def add_attachment |
|
47 | def add_attachment | |
48 | # Save the attachments |
|
48 | attachments = attach_files(@document, params[:attachments]) | |
49 | @attachments = [] |
|
49 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added') | |
50 | params[:attachments].each { |file| |
|
|||
51 | next unless file.size > 0 |
|
|||
52 | a = Attachment.create(:container => @document, :file => file, :author => User.current) |
|
|||
53 | @attachments << a unless a.new_record? |
|
|||
54 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
55 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added') |
|
|||
56 | redirect_to :action => 'show', :id => @document |
|
50 | redirect_to :action => 'show', :id => @document | |
57 | end |
|
51 | end | |
58 |
|
52 | |||
59 | def destroy_attachment |
|
53 | def destroy_attachment | |
60 | @document.attachments.find(params[:attachment_id]).destroy |
|
54 | @document.attachments.find(params[:attachment_id]).destroy | |
61 | redirect_to :action => 'show', :id => @document |
|
55 | redirect_to :action => 'show', :id => @document | |
62 | end |
|
56 | end | |
63 |
|
57 | |||
64 | private |
|
58 | private | |
65 | def find_project |
|
59 | def find_project | |
66 | @document = Document.find(params[:id]) |
|
60 | @document = Document.find(params[:id]) | |
67 | @project = @document.project |
|
61 | @project = @document.project | |
68 | rescue ActiveRecord::RecordNotFound |
|
62 | rescue ActiveRecord::RecordNotFound | |
69 | render_404 |
|
63 | render_404 | |
70 | end |
|
64 | end | |
71 | end |
|
65 | end |
@@ -1,251 +1,239 | |||||
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' |
|
19 | layout 'base' | |
20 | before_filter :find_project, :authorize, :except => [:index, :changes, :preview] |
|
20 | before_filter :find_project, :authorize, :except => [:index, :changes, :preview] | |
21 | before_filter :find_optional_project, :only => [:index, :changes] |
|
21 | before_filter :find_optional_project, :only => [:index, :changes] | |
22 | accept_key_auth :index, :changes |
|
22 | accept_key_auth :index, :changes | |
23 |
|
23 | |||
24 | cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ] |
|
24 | cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ] | |
25 |
|
25 | |||
26 | helper :projects |
|
26 | helper :projects | |
27 | include ProjectsHelper |
|
27 | include ProjectsHelper | |
28 | helper :custom_fields |
|
28 | helper :custom_fields | |
29 | include CustomFieldsHelper |
|
29 | include CustomFieldsHelper | |
30 | helper :ifpdf |
|
30 | helper :ifpdf | |
31 | include IfpdfHelper |
|
31 | include IfpdfHelper | |
32 | helper :issue_relations |
|
32 | helper :issue_relations | |
33 | include IssueRelationsHelper |
|
33 | include IssueRelationsHelper | |
34 | helper :watchers |
|
34 | helper :watchers | |
35 | include WatchersHelper |
|
35 | include WatchersHelper | |
36 | helper :attachments |
|
36 | helper :attachments | |
37 | include AttachmentsHelper |
|
37 | include AttachmentsHelper | |
38 | helper :queries |
|
38 | helper :queries | |
39 | helper :sort |
|
39 | helper :sort | |
40 | include SortHelper |
|
40 | include SortHelper | |
41 | include IssuesHelper |
|
41 | include IssuesHelper | |
42 |
|
42 | |||
43 | def index |
|
43 | def index | |
44 | sort_init "#{Issue.table_name}.id", "desc" |
|
44 | sort_init "#{Issue.table_name}.id", "desc" | |
45 | sort_update |
|
45 | sort_update | |
46 | retrieve_query |
|
46 | retrieve_query | |
47 | if @query.valid? |
|
47 | if @query.valid? | |
48 | limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25 |
|
48 | limit = %w(pdf csv).include?(params[:format]) ? Setting.issues_export_limit.to_i : 25 | |
49 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
49 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
50 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
50 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
51 | @issues = Issue.find :all, :order => sort_clause, |
|
51 | @issues = Issue.find :all, :order => sort_clause, | |
52 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], |
|
52 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ], | |
53 | :conditions => @query.statement, |
|
53 | :conditions => @query.statement, | |
54 | :limit => limit, |
|
54 | :limit => limit, | |
55 | :offset => @issue_pages.current.offset |
|
55 | :offset => @issue_pages.current.offset | |
56 | respond_to do |format| |
|
56 | respond_to do |format| | |
57 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
57 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
58 | format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } |
|
58 | format.atom { render_feed(@issues, :title => l(:label_issue_plural)) } | |
59 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
59 | format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') } | |
60 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } |
|
60 | format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') } | |
61 | end |
|
61 | end | |
62 | else |
|
62 | else | |
63 | # Send html if the query is not valid |
|
63 | # Send html if the query is not valid | |
64 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
64 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def changes |
|
68 | def changes | |
69 | sort_init "#{Issue.table_name}.id", "desc" |
|
69 | sort_init "#{Issue.table_name}.id", "desc" | |
70 | sort_update |
|
70 | sort_update | |
71 | retrieve_query |
|
71 | retrieve_query | |
72 | if @query.valid? |
|
72 | if @query.valid? | |
73 | @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], |
|
73 | @changes = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | |
74 | :conditions => @query.statement, |
|
74 | :conditions => @query.statement, | |
75 | :limit => 25, |
|
75 | :limit => 25, | |
76 | :order => "#{Journal.table_name}.created_on DESC" |
|
76 | :order => "#{Journal.table_name}.created_on DESC" | |
77 | end |
|
77 | end | |
78 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
78 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
79 | render :layout => false, :content_type => 'application/atom+xml' |
|
79 | render :layout => false, :content_type => 'application/atom+xml' | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def show |
|
82 | def show | |
83 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") |
|
83 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") | |
84 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
84 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
85 | @status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) |
|
85 | @status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) | |
86 | respond_to do |format| |
|
86 | respond_to do |format| | |
87 | format.html { render :template => 'issues/show.rhtml' } |
|
87 | format.html { render :template => 'issues/show.rhtml' } | |
88 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
88 | format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def edit |
|
92 | def edit | |
93 | @priorities = Enumeration::get_values('IPRI') |
|
93 | @priorities = Enumeration::get_values('IPRI') | |
94 | @custom_values = [] |
|
94 | @custom_values = [] | |
95 | if request.get? |
|
95 | if request.get? | |
96 | @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) } |
|
96 | @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) } | |
97 | else |
|
97 | else | |
98 | begin |
|
98 | begin | |
99 | @issue.init_journal(User.current) |
|
99 | @issue.init_journal(User.current) | |
100 | # Retrieve custom fields and values |
|
100 | # Retrieve custom fields and values | |
101 | if params["custom_fields"] |
|
101 | if params["custom_fields"] | |
102 | @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]) } |
|
102 | @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]) } | |
103 | @issue.custom_values = @custom_values |
|
103 | @issue.custom_values = @custom_values | |
104 | end |
|
104 | end | |
105 | @issue.attributes = params[:issue] |
|
105 | @issue.attributes = params[:issue] | |
106 | if @issue.save |
|
106 | if @issue.save | |
107 | flash[:notice] = l(:notice_successful_update) |
|
107 | flash[:notice] = l(:notice_successful_update) | |
108 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) |
|
108 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) | |
109 | end |
|
109 | end | |
110 | rescue ActiveRecord::StaleObjectError |
|
110 | rescue ActiveRecord::StaleObjectError | |
111 | # Optimistic locking exception |
|
111 | # Optimistic locking exception | |
112 | flash[:error] = l(:notice_locking_conflict) |
|
112 | flash[:error] = l(:notice_locking_conflict) | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def add_note |
|
117 | def add_note | |
118 | journal = @issue.init_journal(User.current, params[:notes]) |
|
118 | journal = @issue.init_journal(User.current, params[:notes]) | |
119 | params[:attachments].each { |file| |
|
119 | attachments = attach_files(@issue, params[:attachments]) | |
120 | next unless file.size > 0 |
|
120 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
121 | a = Attachment.create(:container => @issue, :file => file, :author => User.current) |
|
|||
122 | journal.details << JournalDetail.new(:property => 'attachment', |
|
|||
123 | :prop_key => a.id, |
|
|||
124 | :value => a.filename) unless a.new_record? |
|
|||
125 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
126 | if journal.save |
|
121 | if journal.save | |
127 | flash[:notice] = l(:notice_successful_update) |
|
122 | flash[:notice] = l(:notice_successful_update) | |
128 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
123 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
129 | redirect_to :action => 'show', :id => @issue |
|
124 | redirect_to :action => 'show', :id => @issue | |
130 | return |
|
125 | return | |
131 | end |
|
126 | end | |
132 | show |
|
127 | show | |
133 | end |
|
128 | end | |
134 |
|
129 | |||
135 | def change_status |
|
130 | def change_status | |
136 | @status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) |
|
131 | @status_options = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) | |
137 | @new_status = IssueStatus.find(params[:new_status_id]) |
|
132 | @new_status = IssueStatus.find(params[:new_status_id]) | |
138 | if params[:confirm] |
|
133 | if params[:confirm] | |
139 | begin |
|
134 | begin | |
140 | journal = @issue.init_journal(User.current, params[:notes]) |
|
135 | journal = @issue.init_journal(User.current, params[:notes]) | |
141 | @issue.status = @new_status |
|
136 | @issue.status = @new_status | |
142 | if @issue.update_attributes(params[:issue]) |
|
137 | if @issue.update_attributes(params[:issue]) | |
143 | # Save attachments |
|
138 | attachments = attach_files(@issue, params[:attachments]) | |
144 | params[:attachments].each { |file| |
|
139 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
145 | next unless file.size > 0 |
|
|||
146 | a = Attachment.create(:container => @issue, :file => file, :author => User.current) |
|
|||
147 | journal.details << JournalDetail.new(:property => 'attachment', |
|
|||
148 | :prop_key => a.id, |
|
|||
149 | :value => a.filename) unless a.new_record? |
|
|||
150 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
151 |
|
||||
152 | # Log time |
|
140 | # Log time | |
153 | if current_role.allowed_to?(:log_time) |
|
141 | if current_role.allowed_to?(:log_time) | |
154 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
142 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) | |
155 | @time_entry.attributes = params[:time_entry] |
|
143 | @time_entry.attributes = params[:time_entry] | |
156 | @time_entry.save |
|
144 | @time_entry.save | |
157 | end |
|
145 | end | |
158 |
|
146 | |||
159 | flash[:notice] = l(:notice_successful_update) |
|
147 | flash[:notice] = l(:notice_successful_update) | |
160 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') |
|
148 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
161 | redirect_to :action => 'show', :id => @issue |
|
149 | redirect_to :action => 'show', :id => @issue | |
162 | end |
|
150 | end | |
163 | rescue ActiveRecord::StaleObjectError |
|
151 | rescue ActiveRecord::StaleObjectError | |
164 | # Optimistic locking exception |
|
152 | # Optimistic locking exception | |
165 | flash[:error] = l(:notice_locking_conflict) |
|
153 | flash[:error] = l(:notice_locking_conflict) | |
166 | end |
|
154 | end | |
167 | end |
|
155 | end | |
168 | @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user } |
|
156 | @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user } | |
169 | @activities = Enumeration::get_values('ACTI') |
|
157 | @activities = Enumeration::get_values('ACTI') | |
170 | end |
|
158 | end | |
171 |
|
159 | |||
172 | def destroy |
|
160 | def destroy | |
173 | @issue.destroy |
|
161 | @issue.destroy | |
174 | redirect_to :action => 'index', :project_id => @project |
|
162 | redirect_to :action => 'index', :project_id => @project | |
175 | end |
|
163 | end | |
176 |
|
164 | |||
177 | def destroy_attachment |
|
165 | def destroy_attachment | |
178 | a = @issue.attachments.find(params[:attachment_id]) |
|
166 | a = @issue.attachments.find(params[:attachment_id]) | |
179 | a.destroy |
|
167 | a.destroy | |
180 | journal = @issue.init_journal(User.current) |
|
168 | journal = @issue.init_journal(User.current) | |
181 | journal.details << JournalDetail.new(:property => 'attachment', |
|
169 | journal.details << JournalDetail.new(:property => 'attachment', | |
182 | :prop_key => a.id, |
|
170 | :prop_key => a.id, | |
183 | :old_value => a.filename) |
|
171 | :old_value => a.filename) | |
184 | journal.save |
|
172 | journal.save | |
185 | redirect_to :action => 'show', :id => @issue |
|
173 | redirect_to :action => 'show', :id => @issue | |
186 | end |
|
174 | end | |
187 |
|
175 | |||
188 | def context_menu |
|
176 | def context_menu | |
189 | @priorities = Enumeration.get_values('IPRI').reverse |
|
177 | @priorities = Enumeration.get_values('IPRI').reverse | |
190 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
178 | @statuses = IssueStatus.find(:all, :order => 'position') | |
191 | @allowed_statuses = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) |
|
179 | @allowed_statuses = @issue.status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker) | |
192 | @assignables = @issue.assignable_users |
|
180 | @assignables = @issue.assignable_users | |
193 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
181 | @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
194 | @can = {:edit => User.current.allowed_to?(:edit_issues, @project), |
|
182 | @can = {:edit => User.current.allowed_to?(:edit_issues, @project), | |
195 | :change_status => User.current.allowed_to?(:change_issue_status, @project), |
|
183 | :change_status => User.current.allowed_to?(:change_issue_status, @project), | |
196 | :add => User.current.allowed_to?(:add_issues, @project), |
|
184 | :add => User.current.allowed_to?(:add_issues, @project), | |
197 | :move => User.current.allowed_to?(:move_issues, @project), |
|
185 | :move => User.current.allowed_to?(:move_issues, @project), | |
198 | :copy => (@project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
186 | :copy => (@project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
199 | :delete => User.current.allowed_to?(:delete_issues, @project)} |
|
187 | :delete => User.current.allowed_to?(:delete_issues, @project)} | |
200 | render :layout => false |
|
188 | render :layout => false | |
201 | end |
|
189 | end | |
202 |
|
190 | |||
203 | def preview |
|
191 | def preview | |
204 | issue = Issue.find_by_id(params[:id]) |
|
192 | issue = Issue.find_by_id(params[:id]) | |
205 | @attachements = issue.attachments if issue |
|
193 | @attachements = issue.attachments if issue | |
206 | @text = params[:issue][:description] |
|
194 | @text = params[:issue][:description] | |
207 | render :partial => 'common/preview' |
|
195 | render :partial => 'common/preview' | |
208 | end |
|
196 | end | |
209 |
|
197 | |||
210 | private |
|
198 | private | |
211 | def find_project |
|
199 | def find_project | |
212 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
200 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
213 | @project = @issue.project |
|
201 | @project = @issue.project | |
214 | rescue ActiveRecord::RecordNotFound |
|
202 | rescue ActiveRecord::RecordNotFound | |
215 | render_404 |
|
203 | render_404 | |
216 | end |
|
204 | end | |
217 |
|
205 | |||
218 | def find_optional_project |
|
206 | def find_optional_project | |
219 | return true unless params[:project_id] |
|
207 | return true unless params[:project_id] | |
220 | @project = Project.find(params[:project_id]) |
|
208 | @project = Project.find(params[:project_id]) | |
221 | authorize |
|
209 | authorize | |
222 | rescue ActiveRecord::RecordNotFound |
|
210 | rescue ActiveRecord::RecordNotFound | |
223 | render_404 |
|
211 | render_404 | |
224 | end |
|
212 | end | |
225 |
|
213 | |||
226 | # Retrieve query from session or build a new query |
|
214 | # Retrieve query from session or build a new query | |
227 | def retrieve_query |
|
215 | def retrieve_query | |
228 | if params[:query_id] |
|
216 | if params[:query_id] | |
229 | @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)}) |
|
217 | @query = Query.find(params[:query_id], :conditions => {:project_id => (@project ? @project.id : nil)}) | |
230 | session[:query] = @query |
|
218 | session[:query] = @query | |
231 | else |
|
219 | else | |
232 | if params[:set_filter] or !session[:query] or session[:query].project != @project |
|
220 | if params[:set_filter] or !session[:query] or session[:query].project != @project | |
233 | # Give it a name, required to be valid |
|
221 | # Give it a name, required to be valid | |
234 | @query = Query.new(:name => "_") |
|
222 | @query = Query.new(:name => "_") | |
235 | @query.project = @project |
|
223 | @query.project = @project | |
236 | if params[:fields] and params[:fields].is_a? Array |
|
224 | if params[:fields] and params[:fields].is_a? Array | |
237 | params[:fields].each do |field| |
|
225 | params[:fields].each do |field| | |
238 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
226 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
239 | end |
|
227 | end | |
240 | else |
|
228 | else | |
241 | @query.available_filters.keys.each do |field| |
|
229 | @query.available_filters.keys.each do |field| | |
242 | @query.add_short_filter(field, params[field]) if params[field] |
|
230 | @query.add_short_filter(field, params[field]) if params[field] | |
243 | end |
|
231 | end | |
244 | end |
|
232 | end | |
245 | session[:query] = @query |
|
233 | session[:query] = @query | |
246 | else |
|
234 | else | |
247 | @query = session[:query] |
|
235 | @query = session[:query] | |
248 | end |
|
236 | end | |
249 | end |
|
237 | end | |
250 | end |
|
238 | end | |
251 | end |
|
239 | end |
@@ -1,104 +1,98 | |||||
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 MessagesController < ApplicationController |
|
18 | class MessagesController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :find_board, :only => :new |
|
20 | before_filter :find_board, :only => :new | |
21 | before_filter :find_message, :except => :new |
|
21 | before_filter :find_message, :except => :new | |
22 | before_filter :authorize |
|
22 | before_filter :authorize | |
23 |
|
23 | |||
24 | verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } |
|
24 | verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } | |
25 |
|
25 | |||
26 | helper :attachments |
|
26 | helper :attachments | |
27 | include AttachmentsHelper |
|
27 | include AttachmentsHelper | |
28 |
|
28 | |||
29 | # Show a topic and its replies |
|
29 | # Show a topic and its replies | |
30 | def show |
|
30 | def show | |
31 | @reply = Message.new(:subject => "RE: #{@message.subject}") |
|
31 | @reply = Message.new(:subject => "RE: #{@message.subject}") | |
32 | render :action => "show", :layout => false if request.xhr? |
|
32 | render :action => "show", :layout => false if request.xhr? | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | # Create a new topic |
|
35 | # Create a new topic | |
36 | def new |
|
36 | def new | |
37 | @message = Message.new(params[:message]) |
|
37 | @message = Message.new(params[:message]) | |
38 | @message.author = User.current |
|
38 | @message.author = User.current | |
39 | @message.board = @board |
|
39 | @message.board = @board | |
40 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) |
|
40 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) | |
41 | @message.locked = params[:message]['locked'] |
|
41 | @message.locked = params[:message]['locked'] | |
42 | @message.sticky = params[:message]['sticky'] |
|
42 | @message.sticky = params[:message]['sticky'] | |
43 | end |
|
43 | end | |
44 | if request.post? && @message.save |
|
44 | if request.post? && @message.save | |
45 | params[:attachments].each { |file| |
|
45 | attach_files(@message, params[:attachments]) | |
46 | Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0 |
|
|||
47 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
48 | redirect_to :action => 'show', :id => @message |
|
46 | redirect_to :action => 'show', :id => @message | |
49 | end |
|
47 | end | |
50 | end |
|
48 | end | |
51 |
|
49 | |||
52 | # Reply to a topic |
|
50 | # Reply to a topic | |
53 | def reply |
|
51 | def reply | |
54 | @reply = Message.new(params[:reply]) |
|
52 | @reply = Message.new(params[:reply]) | |
55 | @reply.author = User.current |
|
53 | @reply.author = User.current | |
56 | @reply.board = @board |
|
54 | @reply.board = @board | |
57 | @topic.children << @reply |
|
55 | @topic.children << @reply | |
58 | if !@reply.new_record? |
|
56 | if !@reply.new_record? | |
59 | params[:attachments].each { |file| |
|
57 | attach_files(@reply, params[:attachments]) | |
60 | Attachment.create(:container => @reply, :file => file, :author => User.current) if file.size > 0 |
|
|||
61 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
62 | end |
|
58 | end | |
63 | redirect_to :action => 'show', :id => @topic |
|
59 | redirect_to :action => 'show', :id => @topic | |
64 | end |
|
60 | end | |
65 |
|
61 | |||
66 | # Edit a message |
|
62 | # Edit a message | |
67 | def edit |
|
63 | def edit | |
68 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) |
|
64 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) | |
69 | @message.locked = params[:message]['locked'] |
|
65 | @message.locked = params[:message]['locked'] | |
70 | @message.sticky = params[:message]['sticky'] |
|
66 | @message.sticky = params[:message]['sticky'] | |
71 | end |
|
67 | end | |
72 | if request.post? && @message.update_attributes(params[:message]) |
|
68 | if request.post? && @message.update_attributes(params[:message]) | |
73 | params[:attachments].each { |file| |
|
69 | attach_files(@message, params[:attachments]) | |
74 | Attachment.create(:container => @message, :file => file, :author => User.current) if file.size > 0 |
|
|||
75 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
76 | flash[:notice] = l(:notice_successful_update) |
|
70 | flash[:notice] = l(:notice_successful_update) | |
77 | redirect_to :action => 'show', :id => @topic |
|
71 | redirect_to :action => 'show', :id => @topic | |
78 | end |
|
72 | end | |
79 | end |
|
73 | end | |
80 |
|
74 | |||
81 | # Delete a messages |
|
75 | # Delete a messages | |
82 | def destroy |
|
76 | def destroy | |
83 | @message.destroy |
|
77 | @message.destroy | |
84 | redirect_to @message.parent.nil? ? |
|
78 | redirect_to @message.parent.nil? ? | |
85 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : |
|
79 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : | |
86 | { :action => 'show', :id => @message.parent } |
|
80 | { :action => 'show', :id => @message.parent } | |
87 | end |
|
81 | end | |
88 |
|
82 | |||
89 | private |
|
83 | private | |
90 | def find_message |
|
84 | def find_message | |
91 | find_board |
|
85 | find_board | |
92 | @message = @board.messages.find(params[:id], :include => :parent) |
|
86 | @message = @board.messages.find(params[:id], :include => :parent) | |
93 | @topic = @message.root |
|
87 | @topic = @message.root | |
94 | rescue ActiveRecord::RecordNotFound |
|
88 | rescue ActiveRecord::RecordNotFound | |
95 | render_404 |
|
89 | render_404 | |
96 | end |
|
90 | end | |
97 |
|
91 | |||
98 | def find_board |
|
92 | def find_board | |
99 | @board = Board.find(params[:board_id], :include => :project) |
|
93 | @board = Board.find(params[:board_id], :include => :project) | |
100 | @project = @board.project |
|
94 | @project = @board.project | |
101 | rescue ActiveRecord::RecordNotFound |
|
95 | rescue ActiveRecord::RecordNotFound | |
102 | render_404 |
|
96 | render_404 | |
103 | end |
|
97 | end | |
104 | end |
|
98 | end |
@@ -1,560 +1,548 | |||||
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 ProjectsController < ApplicationController |
|
18 | class ProjectsController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :find_project, :except => [ :index, :list, :add ] |
|
20 | before_filter :find_project, :except => [ :index, :list, :add ] | |
21 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
21 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] | |
22 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
22 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] | |
23 | accept_key_auth :activity, :calendar |
|
23 | accept_key_auth :activity, :calendar | |
24 |
|
24 | |||
25 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] |
|
25 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] | |
26 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] |
|
26 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] | |
27 | cache_sweeper :version_sweeper, :only => [ :add_version ] |
|
27 | cache_sweeper :version_sweeper, :only => [ :add_version ] | |
28 |
|
28 | |||
29 | helper :sort |
|
29 | helper :sort | |
30 | include SortHelper |
|
30 | include SortHelper | |
31 | helper :custom_fields |
|
31 | helper :custom_fields | |
32 | include CustomFieldsHelper |
|
32 | include CustomFieldsHelper | |
33 | helper :ifpdf |
|
33 | helper :ifpdf | |
34 | include IfpdfHelper |
|
34 | include IfpdfHelper | |
35 | helper :issues |
|
35 | helper :issues | |
36 | helper IssuesHelper |
|
36 | helper IssuesHelper | |
37 | helper :queries |
|
37 | helper :queries | |
38 | include QueriesHelper |
|
38 | include QueriesHelper | |
39 | helper :repositories |
|
39 | helper :repositories | |
40 | include RepositoriesHelper |
|
40 | include RepositoriesHelper | |
41 | include ProjectsHelper |
|
41 | include ProjectsHelper | |
42 |
|
42 | |||
43 | def index |
|
43 | def index | |
44 | list |
|
44 | list | |
45 | render :action => 'list' unless request.xhr? |
|
45 | render :action => 'list' unless request.xhr? | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | # Lists visible projects |
|
48 | # Lists visible projects | |
49 | def list |
|
49 | def list | |
50 | projects = Project.find :all, |
|
50 | projects = Project.find :all, | |
51 | :conditions => Project.visible_by(User.current), |
|
51 | :conditions => Project.visible_by(User.current), | |
52 | :include => :parent |
|
52 | :include => :parent | |
53 | @project_tree = projects.group_by {|p| p.parent || p} |
|
53 | @project_tree = projects.group_by {|p| p.parent || p} | |
54 | @project_tree.each_key {|p| @project_tree[p] -= [p]} |
|
54 | @project_tree.each_key {|p| @project_tree[p] -= [p]} | |
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, :order => "#{CustomField.table_name}.position") |
|
59 | @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
60 | @trackers = Tracker.all |
|
60 | @trackers = Tracker.all | |
61 | @root_projects = Project.find(:all, |
|
61 | @root_projects = Project.find(:all, | |
62 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
62 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | |
63 | :order => 'name') |
|
63 | :order => 'name') | |
64 | @project = Project.new(params[:project]) |
|
64 | @project = Project.new(params[:project]) | |
65 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
65 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules | |
66 | if request.get? |
|
66 | if request.get? | |
67 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
67 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
68 | @project.trackers = Tracker.all |
|
68 | @project.trackers = Tracker.all | |
69 | else |
|
69 | else | |
70 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
70 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
71 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } |
|
71 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } | |
72 | @project.custom_values = @custom_values |
|
72 | @project.custom_values = @custom_values | |
73 | if @project.save |
|
73 | if @project.save | |
74 | @project.enabled_module_names = params[:enabled_modules] |
|
74 | @project.enabled_module_names = params[:enabled_modules] | |
75 | flash[:notice] = l(:notice_successful_create) |
|
75 | flash[:notice] = l(:notice_successful_create) | |
76 | redirect_to :controller => 'admin', :action => 'projects' |
|
76 | redirect_to :controller => 'admin', :action => 'projects' | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | # Show @project |
|
81 | # Show @project | |
82 | def show |
|
82 | def show | |
83 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") |
|
83 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") | |
84 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
84 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} | |
85 | @subprojects = @project.active_children |
|
85 | @subprojects = @project.active_children | |
86 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
86 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
87 | @trackers = @project.trackers |
|
87 | @trackers = @project.trackers | |
88 | @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]) |
|
88 | @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]) | |
89 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
89 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
90 | @total_hours = @project.time_entries.sum(:hours) |
|
90 | @total_hours = @project.time_entries.sum(:hours) | |
91 | @key = User.current.rss_key |
|
91 | @key = User.current.rss_key | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def settings |
|
94 | def settings | |
95 | @root_projects = Project.find(:all, |
|
95 | @root_projects = Project.find(:all, | |
96 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], |
|
96 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], | |
97 | :order => 'name') |
|
97 | :order => 'name') | |
98 | @custom_fields = IssueCustomField.find(:all) |
|
98 | @custom_fields = IssueCustomField.find(:all) | |
99 | @issue_category ||= IssueCategory.new |
|
99 | @issue_category ||= IssueCategory.new | |
100 | @member ||= @project.members.new |
|
100 | @member ||= @project.members.new | |
101 | @trackers = Tracker.all |
|
101 | @trackers = Tracker.all | |
102 | @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
102 | @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
103 | @repository ||= @project.repository |
|
103 | @repository ||= @project.repository | |
104 | @wiki ||= @project.wiki |
|
104 | @wiki ||= @project.wiki | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | # Edit @project |
|
107 | # Edit @project | |
108 | def edit |
|
108 | def edit | |
109 | if request.post? |
|
109 | if request.post? | |
110 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
110 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
111 | if params[:custom_fields] |
|
111 | if params[:custom_fields] | |
112 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
112 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
113 | @project.custom_values = @custom_values |
|
113 | @project.custom_values = @custom_values | |
114 | end |
|
114 | end | |
115 | @project.attributes = params[:project] |
|
115 | @project.attributes = params[:project] | |
116 | if @project.save |
|
116 | if @project.save | |
117 | flash[:notice] = l(:notice_successful_update) |
|
117 | flash[:notice] = l(:notice_successful_update) | |
118 | redirect_to :action => 'settings', :id => @project |
|
118 | redirect_to :action => 'settings', :id => @project | |
119 | else |
|
119 | else | |
120 | settings |
|
120 | settings | |
121 | render :action => 'settings' |
|
121 | render :action => 'settings' | |
122 | end |
|
122 | end | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def modules |
|
126 | def modules | |
127 | @project.enabled_module_names = params[:enabled_modules] |
|
127 | @project.enabled_module_names = params[:enabled_modules] | |
128 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
128 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def archive |
|
131 | def archive | |
132 | @project.archive if request.post? && @project.active? |
|
132 | @project.archive if request.post? && @project.active? | |
133 | redirect_to :controller => 'admin', :action => 'projects' |
|
133 | redirect_to :controller => 'admin', :action => 'projects' | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def unarchive |
|
136 | def unarchive | |
137 | @project.unarchive if request.post? && !@project.active? |
|
137 | @project.unarchive if request.post? && !@project.active? | |
138 | redirect_to :controller => 'admin', :action => 'projects' |
|
138 | redirect_to :controller => 'admin', :action => 'projects' | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | # Delete @project |
|
141 | # Delete @project | |
142 | def destroy |
|
142 | def destroy | |
143 | @project_to_destroy = @project |
|
143 | @project_to_destroy = @project | |
144 | if request.post? and params[:confirm] |
|
144 | if request.post? and params[:confirm] | |
145 | @project_to_destroy.destroy |
|
145 | @project_to_destroy.destroy | |
146 | redirect_to :controller => 'admin', :action => 'projects' |
|
146 | redirect_to :controller => 'admin', :action => 'projects' | |
147 | end |
|
147 | end | |
148 | # hide project in layout |
|
148 | # hide project in layout | |
149 | @project = nil |
|
149 | @project = nil | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | # Add a new issue category to @project |
|
152 | # Add a new issue category to @project | |
153 | def add_issue_category |
|
153 | def add_issue_category | |
154 | @category = @project.issue_categories.build(params[:category]) |
|
154 | @category = @project.issue_categories.build(params[:category]) | |
155 | if request.post? and @category.save |
|
155 | if request.post? and @category.save | |
156 | respond_to do |format| |
|
156 | respond_to do |format| | |
157 | format.html do |
|
157 | format.html do | |
158 | flash[:notice] = l(:notice_successful_create) |
|
158 | flash[:notice] = l(:notice_successful_create) | |
159 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
159 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
160 | end |
|
160 | end | |
161 | format.js do |
|
161 | format.js do | |
162 | # IE doesn't support the replace_html rjs method for select box options |
|
162 | # IE doesn't support the replace_html rjs method for select box options | |
163 | render(:update) {|page| page.replace "issue_category_id", |
|
163 | render(:update) {|page| page.replace "issue_category_id", | |
164 | content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') |
|
164 | content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') | |
165 | } |
|
165 | } | |
166 | end |
|
166 | end | |
167 | end |
|
167 | end | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | # Add a new version to @project |
|
171 | # Add a new version to @project | |
172 | def add_version |
|
172 | def add_version | |
173 | @version = @project.versions.build(params[:version]) |
|
173 | @version = @project.versions.build(params[:version]) | |
174 | if request.post? and @version.save |
|
174 | if request.post? and @version.save | |
175 | flash[:notice] = l(:notice_successful_create) |
|
175 | flash[:notice] = l(:notice_successful_create) | |
176 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
176 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
177 | end |
|
177 | end | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | # Add a new document to @project |
|
180 | # Add a new document to @project | |
181 | def add_document |
|
181 | def add_document | |
182 | @document = @project.documents.build(params[:document]) |
|
182 | @document = @project.documents.build(params[:document]) | |
183 | if request.post? and @document.save |
|
183 | if request.post? and @document.save | |
184 | # Save the attachments |
|
184 | attach_files(@document, params[:attachments]) | |
185 | params[:attachments].each { |a| |
|
|||
186 | Attachment.create(:container => @document, :file => a, :author => User.current) unless a.size == 0 |
|
|||
187 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
188 | flash[:notice] = l(:notice_successful_create) |
|
185 | flash[:notice] = l(:notice_successful_create) | |
189 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') |
|
186 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') | |
190 | redirect_to :action => 'list_documents', :id => @project |
|
187 | redirect_to :action => 'list_documents', :id => @project | |
191 | end |
|
188 | end | |
192 | end |
|
189 | end | |
193 |
|
190 | |||
194 | # Show documents list of @project |
|
191 | # Show documents list of @project | |
195 | def list_documents |
|
192 | def list_documents | |
196 | @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' |
|
193 | @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' | |
197 | documents = @project.documents.find :all, :include => [:attachments, :category] |
|
194 | documents = @project.documents.find :all, :include => [:attachments, :category] | |
198 | case @sort_by |
|
195 | case @sort_by | |
199 | when 'date' |
|
196 | when 'date' | |
200 | @grouped = documents.group_by {|d| d.created_on.to_date } |
|
197 | @grouped = documents.group_by {|d| d.created_on.to_date } | |
201 | when 'title' |
|
198 | when 'title' | |
202 | @grouped = documents.group_by {|d| d.title.first.upcase} |
|
199 | @grouped = documents.group_by {|d| d.title.first.upcase} | |
203 | when 'author' |
|
200 | when 'author' | |
204 | @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} |
|
201 | @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} | |
205 | else |
|
202 | else | |
206 | @grouped = documents.group_by(&:category) |
|
203 | @grouped = documents.group_by(&:category) | |
207 | end |
|
204 | end | |
208 | render :layout => false if request.xhr? |
|
205 | render :layout => false if request.xhr? | |
209 | end |
|
206 | end | |
210 |
|
207 | |||
211 | # Add a new issue to @project |
|
208 | # Add a new issue to @project | |
212 | # The new issue will be created from an existing one if copy_from parameter is given |
|
209 | # The new issue will be created from an existing one if copy_from parameter is given | |
213 | def add_issue |
|
210 | def add_issue | |
214 | @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue]) |
|
211 | @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue]) | |
215 | @issue.project = @project |
|
212 | @issue.project = @project | |
216 | @issue.author = User.current |
|
213 | @issue.author = User.current | |
217 | @issue.tracker ||= @project.trackers.find(params[:tracker_id]) |
|
214 | @issue.tracker ||= @project.trackers.find(params[:tracker_id]) | |
218 |
|
215 | |||
219 | default_status = IssueStatus.default |
|
216 | default_status = IssueStatus.default | |
220 | unless default_status |
|
217 | unless default_status | |
221 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' |
|
218 | flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' | |
222 | render :nothing => true, :layout => true |
|
219 | render :nothing => true, :layout => true | |
223 | return |
|
220 | return | |
224 | end |
|
221 | end | |
225 | @issue.status = default_status |
|
222 | @issue.status = default_status | |
226 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)) |
|
223 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)) | |
227 |
|
224 | |||
228 | if request.get? |
|
225 | if request.get? | |
229 | @issue.start_date ||= Date.today |
|
226 | @issue.start_date ||= Date.today | |
230 | @custom_values = @issue.custom_values.empty? ? |
|
227 | @custom_values = @issue.custom_values.empty? ? | |
231 | @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } : |
|
228 | @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } : | |
232 | @issue.custom_values |
|
229 | @issue.custom_values | |
233 | else |
|
230 | else | |
234 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
231 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
235 | # Check that the user is allowed to apply the requested status |
|
232 | # Check that the user is allowed to apply the requested status | |
236 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
233 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
237 | @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]) } |
|
234 | @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]) } | |
238 | @issue.custom_values = @custom_values |
|
235 | @issue.custom_values = @custom_values | |
239 | if @issue.save |
|
236 | if @issue.save | |
240 | if params[:attachments] && params[:attachments].is_a?(Array) |
|
237 | attach_files(@issue, params[:attachments]) | |
241 | # Save attachments |
|
|||
242 | params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0} |
|
|||
243 | end |
|
|||
244 | flash[:notice] = l(:notice_successful_create) |
|
238 | flash[:notice] = l(:notice_successful_create) | |
245 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') |
|
239 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
246 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
240 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
247 | return |
|
241 | return | |
248 | end |
|
242 | end | |
249 | end |
|
243 | end | |
250 | @priorities = Enumeration::get_values('IPRI') |
|
244 | @priorities = Enumeration::get_values('IPRI') | |
251 | end |
|
245 | end | |
252 |
|
246 | |||
253 | # Bulk edit issues |
|
247 | # Bulk edit issues | |
254 | def bulk_edit_issues |
|
248 | def bulk_edit_issues | |
255 | if request.post? |
|
249 | if request.post? | |
256 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) |
|
250 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) | |
257 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) |
|
251 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) | |
258 | assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id]) |
|
252 | assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id]) | |
259 | category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id]) |
|
253 | category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id]) | |
260 | fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id]) |
|
254 | fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id]) | |
261 | issues = @project.issues.find_all_by_id(params[:issue_ids]) |
|
255 | issues = @project.issues.find_all_by_id(params[:issue_ids]) | |
262 | unsaved_issue_ids = [] |
|
256 | unsaved_issue_ids = [] | |
263 | issues.each do |issue| |
|
257 | issues.each do |issue| | |
264 | journal = issue.init_journal(User.current, params[:notes]) |
|
258 | journal = issue.init_journal(User.current, params[:notes]) | |
265 | issue.priority = priority if priority |
|
259 | issue.priority = priority if priority | |
266 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' |
|
260 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' | |
267 | issue.category = category if category |
|
261 | issue.category = category if category | |
268 | issue.fixed_version = fixed_version if fixed_version |
|
262 | issue.fixed_version = fixed_version if fixed_version | |
269 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
263 | issue.start_date = params[:start_date] unless params[:start_date].blank? | |
270 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
264 | issue.due_date = params[:due_date] unless params[:due_date].blank? | |
271 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
265 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? | |
272 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
266 | # Don't save any change to the issue if the user is not authorized to apply the requested status | |
273 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save |
|
267 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save | |
274 | # Send notification for each issue (if changed) |
|
268 | # Send notification for each issue (if changed) | |
275 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') |
|
269 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') | |
276 | else |
|
270 | else | |
277 | # Keep unsaved issue ids to display them in flash error |
|
271 | # Keep unsaved issue ids to display them in flash error | |
278 | unsaved_issue_ids << issue.id |
|
272 | unsaved_issue_ids << issue.id | |
279 | end |
|
273 | end | |
280 | end |
|
274 | end | |
281 | if unsaved_issue_ids.empty? |
|
275 | if unsaved_issue_ids.empty? | |
282 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
276 | flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
283 | else |
|
277 | else | |
284 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
278 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) | |
285 | end |
|
279 | end | |
286 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
280 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
287 | return |
|
281 | return | |
288 | end |
|
282 | end | |
289 | if current_role && User.current.allowed_to?(:change_issue_status, @project) |
|
283 | if current_role && User.current.allowed_to?(:change_issue_status, @project) | |
290 | # Find potential statuses the user could be allowed to switch issues to |
|
284 | # Find potential statuses the user could be allowed to switch issues to | |
291 | @available_statuses = Workflow.find(:all, :include => :new_status, |
|
285 | @available_statuses = Workflow.find(:all, :include => :new_status, | |
292 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq |
|
286 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq | |
293 | end |
|
287 | end | |
294 | render :update do |page| |
|
288 | render :update do |page| | |
295 | page.hide 'query_form' |
|
289 | page.hide 'query_form' | |
296 | page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form' |
|
290 | page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form' | |
297 | end |
|
291 | end | |
298 | end |
|
292 | end | |
299 |
|
293 | |||
300 | def move_issues |
|
294 | def move_issues | |
301 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
295 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
302 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues |
|
296 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues | |
303 |
|
297 | |||
304 | @projects = [] |
|
298 | @projects = [] | |
305 | # find projects to which the user is allowed to move the issue |
|
299 | # find projects to which the user is allowed to move the issue | |
306 | if User.current.admin? |
|
300 | if User.current.admin? | |
307 | # admin is allowed to move issues to any active (visible) project |
|
301 | # admin is allowed to move issues to any active (visible) project | |
308 | @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') |
|
302 | @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') | |
309 | else |
|
303 | else | |
310 | User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)} |
|
304 | User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)} | |
311 | end |
|
305 | end | |
312 | @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
306 | @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
313 | @target_project ||= @project |
|
307 | @target_project ||= @project | |
314 | @trackers = @target_project.trackers |
|
308 | @trackers = @target_project.trackers | |
315 | if request.post? |
|
309 | if request.post? | |
316 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
310 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
317 | unsaved_issue_ids = [] |
|
311 | unsaved_issue_ids = [] | |
318 | @issues.each do |issue| |
|
312 | @issues.each do |issue| | |
319 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) |
|
313 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) | |
320 | end |
|
314 | end | |
321 | if unsaved_issue_ids.empty? |
|
315 | if unsaved_issue_ids.empty? | |
322 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
316 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
323 | else |
|
317 | else | |
324 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
318 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) | |
325 | end |
|
319 | end | |
326 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
320 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
327 | return |
|
321 | return | |
328 | end |
|
322 | end | |
329 | render :layout => false if request.xhr? |
|
323 | render :layout => false if request.xhr? | |
330 | end |
|
324 | end | |
331 |
|
325 | |||
332 | # Add a news to @project |
|
326 | # Add a news to @project | |
333 | def add_news |
|
327 | def add_news | |
334 | @news = News.new(:project => @project, :author => User.current) |
|
328 | @news = News.new(:project => @project, :author => User.current) | |
335 | if request.post? |
|
329 | if request.post? | |
336 | @news.attributes = params[:news] |
|
330 | @news.attributes = params[:news] | |
337 | if @news.save |
|
331 | if @news.save | |
338 | flash[:notice] = l(:notice_successful_create) |
|
332 | flash[:notice] = l(:notice_successful_create) | |
339 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
333 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') | |
340 | redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
334 | redirect_to :controller => 'news', :action => 'index', :project_id => @project | |
341 | end |
|
335 | end | |
342 | end |
|
336 | end | |
343 | end |
|
337 | end | |
344 |
|
338 | |||
345 | def add_file |
|
339 | def add_file | |
346 | if request.post? |
|
340 | if request.post? | |
347 | @version = @project.versions.find_by_id(params[:version_id]) |
|
341 | @version = @project.versions.find_by_id(params[:version_id]) | |
348 | # Save the attachments |
|
342 | attachments = attach_files(@issue, params[:attachments]) | |
349 | @attachments = [] |
|
343 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') | |
350 | params[:attachments].each { |file| |
|
|||
351 | next unless file.size > 0 |
|
|||
352 | a = Attachment.create(:container => @version, :file => file, :author => User.current) |
|
|||
353 | @attachments << a unless a.new_record? |
|
|||
354 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
355 | Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added') |
|
|||
356 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
344 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
357 | end |
|
345 | end | |
358 | @versions = @project.versions.sort |
|
346 | @versions = @project.versions.sort | |
359 | end |
|
347 | end | |
360 |
|
348 | |||
361 | def list_files |
|
349 | def list_files | |
362 | @versions = @project.versions.sort |
|
350 | @versions = @project.versions.sort | |
363 | end |
|
351 | end | |
364 |
|
352 | |||
365 | # Show changelog for @project |
|
353 | # Show changelog for @project | |
366 | def changelog |
|
354 | def changelog | |
367 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
355 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
368 | retrieve_selected_tracker_ids(@trackers) |
|
356 | retrieve_selected_tracker_ids(@trackers) | |
369 | @versions = @project.versions.sort |
|
357 | @versions = @project.versions.sort | |
370 | end |
|
358 | end | |
371 |
|
359 | |||
372 | def roadmap |
|
360 | def roadmap | |
373 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) |
|
361 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) | |
374 | retrieve_selected_tracker_ids(@trackers) |
|
362 | retrieve_selected_tracker_ids(@trackers) | |
375 | @versions = @project.versions.sort |
|
363 | @versions = @project.versions.sort | |
376 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
364 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] | |
377 | end |
|
365 | end | |
378 |
|
366 | |||
379 | def activity |
|
367 | def activity | |
380 | if params[:year] and params[:year].to_i > 1900 |
|
368 | if params[:year] and params[:year].to_i > 1900 | |
381 | @year = params[:year].to_i |
|
369 | @year = params[:year].to_i | |
382 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
370 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
383 | @month = params[:month].to_i |
|
371 | @month = params[:month].to_i | |
384 | end |
|
372 | end | |
385 | end |
|
373 | end | |
386 | @year ||= Date.today.year |
|
374 | @year ||= Date.today.year | |
387 | @month ||= Date.today.month |
|
375 | @month ||= Date.today.month | |
388 |
|
376 | |||
389 | case params[:format] |
|
377 | case params[:format] | |
390 | when 'atom' |
|
378 | when 'atom' | |
391 | # 30 last days |
|
379 | # 30 last days | |
392 | @date_from = Date.today - 30 |
|
380 | @date_from = Date.today - 30 | |
393 | @date_to = Date.today + 1 |
|
381 | @date_to = Date.today + 1 | |
394 | else |
|
382 | else | |
395 | # current month |
|
383 | # current month | |
396 | @date_from = Date.civil(@year, @month, 1) |
|
384 | @date_from = Date.civil(@year, @month, 1) | |
397 | @date_to = @date_from >> 1 |
|
385 | @date_to = @date_from >> 1 | |
398 | end |
|
386 | end | |
399 |
|
387 | |||
400 | @event_types = %w(issues news files documents changesets wiki_pages messages) |
|
388 | @event_types = %w(issues news files documents changesets wiki_pages messages) | |
401 | @event_types.delete('wiki_pages') unless @project.wiki |
|
389 | @event_types.delete('wiki_pages') unless @project.wiki | |
402 | @event_types.delete('changesets') unless @project.repository |
|
390 | @event_types.delete('changesets') unless @project.repository | |
403 | @event_types.delete('messages') unless @project.boards.any? |
|
391 | @event_types.delete('messages') unless @project.boards.any? | |
404 | # only show what the user is allowed to view |
|
392 | # only show what the user is allowed to view | |
405 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} |
|
393 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} | |
406 |
|
394 | |||
407 | @scope = @event_types.select {|t| params["show_#{t}"]} |
|
395 | @scope = @event_types.select {|t| params["show_#{t}"]} | |
408 | # default events if none is specified in parameters |
|
396 | # default events if none is specified in parameters | |
409 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? |
|
397 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? | |
410 |
|
398 | |||
411 | @events = [] |
|
399 | @events = [] | |
412 |
|
400 | |||
413 | if @scope.include?('issues') |
|
401 | if @scope.include?('issues') | |
414 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) |
|
402 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) | |
415 | @events += @project.issues_status_changes(@date_from, @date_to) |
|
403 | @events += @project.issues_status_changes(@date_from, @date_to) | |
416 | end |
|
404 | end | |
417 |
|
405 | |||
418 | if @scope.include?('news') |
|
406 | if @scope.include?('news') | |
419 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) |
|
407 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) | |
420 | end |
|
408 | end | |
421 |
|
409 | |||
422 | if @scope.include?('files') |
|
410 | if @scope.include?('files') | |
423 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
411 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
424 | end |
|
412 | end | |
425 |
|
413 | |||
426 | if @scope.include?('documents') |
|
414 | if @scope.include?('documents') | |
427 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) |
|
415 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) | |
428 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
416 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
429 | end |
|
417 | end | |
430 |
|
418 | |||
431 | if @scope.include?('wiki_pages') |
|
419 | if @scope.include?('wiki_pages') | |
432 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
420 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
433 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
421 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + | |
434 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
422 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + | |
435 | "#{WikiContent.versioned_table_name}.id" |
|
423 | "#{WikiContent.versioned_table_name}.id" | |
436 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
424 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
437 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
425 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
438 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
426 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
439 | @project.id, @date_from, @date_to] |
|
427 | @project.id, @date_from, @date_to] | |
440 |
|
428 | |||
441 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) |
|
429 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) | |
442 | end |
|
430 | end | |
443 |
|
431 | |||
444 | if @scope.include?('changesets') |
|
432 | if @scope.include?('changesets') | |
445 | @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) |
|
433 | @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) | |
446 | end |
|
434 | end | |
447 |
|
435 | |||
448 | if @scope.include?('messages') |
|
436 | if @scope.include?('messages') | |
449 | @events += Message.find(:all, |
|
437 | @events += Message.find(:all, | |
450 | :include => [:board, :author], |
|
438 | :include => [:board, :author], | |
451 | :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) |
|
439 | :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) | |
452 | end |
|
440 | end | |
453 |
|
441 | |||
454 | @events_by_day = @events.group_by(&:event_date) |
|
442 | @events_by_day = @events.group_by(&:event_date) | |
455 |
|
443 | |||
456 | respond_to do |format| |
|
444 | respond_to do |format| | |
457 | format.html { render :layout => false if request.xhr? } |
|
445 | format.html { render :layout => false if request.xhr? } | |
458 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } |
|
446 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } | |
459 | end |
|
447 | end | |
460 | end |
|
448 | end | |
461 |
|
449 | |||
462 | def calendar |
|
450 | def calendar | |
463 | @trackers = Tracker.find(:all, :order => 'position') |
|
451 | @trackers = Tracker.find(:all, :order => 'position') | |
464 | retrieve_selected_tracker_ids(@trackers) |
|
452 | retrieve_selected_tracker_ids(@trackers) | |
465 |
|
453 | |||
466 | if params[:year] and params[:year].to_i > 1900 |
|
454 | if params[:year] and params[:year].to_i > 1900 | |
467 | @year = params[:year].to_i |
|
455 | @year = params[:year].to_i | |
468 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
456 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
469 | @month = params[:month].to_i |
|
457 | @month = params[:month].to_i | |
470 | end |
|
458 | end | |
471 | end |
|
459 | end | |
472 | @year ||= Date.today.year |
|
460 | @year ||= Date.today.year | |
473 | @month ||= Date.today.month |
|
461 | @month ||= Date.today.month | |
474 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
462 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
475 |
|
463 | |||
476 | events = [] |
|
464 | events = [] | |
477 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
465 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
478 | events += Issue.find(:all, |
|
466 | events += Issue.find(:all, | |
479 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
467 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
480 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
468 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] | |
481 | ) unless @selected_tracker_ids.empty? |
|
469 | ) unless @selected_tracker_ids.empty? | |
482 | end |
|
470 | end | |
483 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
471 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
484 | @calendar.events = events |
|
472 | @calendar.events = events | |
485 |
|
473 | |||
486 | render :layout => false if request.xhr? |
|
474 | render :layout => false if request.xhr? | |
487 | end |
|
475 | end | |
488 |
|
476 | |||
489 | def gantt |
|
477 | def gantt | |
490 | @trackers = Tracker.find(:all, :order => 'position') |
|
478 | @trackers = Tracker.find(:all, :order => 'position') | |
491 | retrieve_selected_tracker_ids(@trackers) |
|
479 | retrieve_selected_tracker_ids(@trackers) | |
492 |
|
480 | |||
493 | if params[:year] and params[:year].to_i >0 |
|
481 | if params[:year] and params[:year].to_i >0 | |
494 | @year_from = params[:year].to_i |
|
482 | @year_from = params[:year].to_i | |
495 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
483 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
496 | @month_from = params[:month].to_i |
|
484 | @month_from = params[:month].to_i | |
497 | else |
|
485 | else | |
498 | @month_from = 1 |
|
486 | @month_from = 1 | |
499 | end |
|
487 | end | |
500 | else |
|
488 | else | |
501 | @month_from ||= Date.today.month |
|
489 | @month_from ||= Date.today.month | |
502 | @year_from ||= Date.today.year |
|
490 | @year_from ||= Date.today.year | |
503 | end |
|
491 | end | |
504 |
|
492 | |||
505 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
493 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i | |
506 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
494 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 | |
507 | months = (params[:months] || User.current.pref[:gantt_months]).to_i |
|
495 | months = (params[:months] || User.current.pref[:gantt_months]).to_i | |
508 | @months = (months > 0 && months < 25) ? months : 6 |
|
496 | @months = (months > 0 && months < 25) ? months : 6 | |
509 |
|
497 | |||
510 | # Save gantt paramters as user preference (zoom and months count) |
|
498 | # Save gantt paramters as user preference (zoom and months count) | |
511 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) |
|
499 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) | |
512 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
500 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months | |
513 | User.current.preference.save |
|
501 | User.current.preference.save | |
514 | end |
|
502 | end | |
515 |
|
503 | |||
516 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
504 | @date_from = Date.civil(@year_from, @month_from, 1) | |
517 | @date_to = (@date_from >> @months) - 1 |
|
505 | @date_to = (@date_from >> @months) - 1 | |
518 |
|
506 | |||
519 | @events = [] |
|
507 | @events = [] | |
520 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
508 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
521 | @events += Issue.find(:all, |
|
509 | @events += Issue.find(:all, | |
522 | :order => "start_date, due_date", |
|
510 | :order => "start_date, due_date", | |
523 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
511 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
524 | :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] |
|
512 | :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] | |
525 | ) unless @selected_tracker_ids.empty? |
|
513 | ) unless @selected_tracker_ids.empty? | |
526 | end |
|
514 | end | |
527 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
515 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
528 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
516 | @events.sort! {|x,y| x.start_date <=> y.start_date } | |
529 |
|
517 | |||
530 | if params[:format]=='pdf' |
|
518 | if params[:format]=='pdf' | |
531 | @options_for_rfpdf ||= {} |
|
519 | @options_for_rfpdf ||= {} | |
532 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
520 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" | |
533 | render :template => "projects/gantt.rfpdf", :layout => false |
|
521 | render :template => "projects/gantt.rfpdf", :layout => false | |
534 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
522 | elsif params[:format]=='png' && respond_to?('gantt_image') | |
535 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
523 | image = gantt_image(@events, @date_from, @months, @zoom) | |
536 | image.format = 'PNG' |
|
524 | image.format = 'PNG' | |
537 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
525 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") | |
538 | else |
|
526 | else | |
539 | render :template => "projects/gantt.rhtml" |
|
527 | render :template => "projects/gantt.rhtml" | |
540 | end |
|
528 | end | |
541 | end |
|
529 | end | |
542 |
|
530 | |||
543 | private |
|
531 | private | |
544 | # Find project of id params[:id] |
|
532 | # Find project of id params[:id] | |
545 | # if not found, redirect to project list |
|
533 | # if not found, redirect to project list | |
546 | # Used as a before_filter |
|
534 | # Used as a before_filter | |
547 | def find_project |
|
535 | def find_project | |
548 | @project = Project.find(params[:id]) |
|
536 | @project = Project.find(params[:id]) | |
549 | rescue ActiveRecord::RecordNotFound |
|
537 | rescue ActiveRecord::RecordNotFound | |
550 | render_404 |
|
538 | render_404 | |
551 | end |
|
539 | end | |
552 |
|
540 | |||
553 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
541 | def retrieve_selected_tracker_ids(selectable_trackers) | |
554 | if ids = params[:tracker_ids] |
|
542 | if ids = params[:tracker_ids] | |
555 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
543 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
556 | else |
|
544 | else | |
557 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
545 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
558 | end |
|
546 | end | |
559 | end |
|
547 | end | |
560 | end |
|
548 | end |
@@ -1,180 +1,176 | |||||
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 'diff' |
|
18 | require 'diff' | |
19 |
|
19 | |||
20 | class WikiController < ApplicationController |
|
20 | class WikiController < ApplicationController | |
21 | layout 'base' |
|
21 | layout 'base' | |
22 | before_filter :find_wiki, :authorize |
|
22 | before_filter :find_wiki, :authorize | |
23 |
|
23 | |||
24 | verify :method => :post, :only => [:destroy, :destroy_attachment], :redirect_to => { :action => :index } |
|
24 | verify :method => :post, :only => [:destroy, :destroy_attachment], :redirect_to => { :action => :index } | |
25 |
|
25 | |||
26 | helper :attachments |
|
26 | helper :attachments | |
27 | include AttachmentsHelper |
|
27 | include AttachmentsHelper | |
28 |
|
28 | |||
29 | # display a page (in editing mode if it doesn't exist) |
|
29 | # display a page (in editing mode if it doesn't exist) | |
30 | def index |
|
30 | def index | |
31 | page_title = params[:page] |
|
31 | page_title = params[:page] | |
32 | @page = @wiki.find_or_new_page(page_title) |
|
32 | @page = @wiki.find_or_new_page(page_title) | |
33 | if @page.new_record? |
|
33 | if @page.new_record? | |
34 | if User.current.allowed_to?(:edit_wiki_pages, @project) |
|
34 | if User.current.allowed_to?(:edit_wiki_pages, @project) | |
35 | edit |
|
35 | edit | |
36 | render :action => 'edit' |
|
36 | render :action => 'edit' | |
37 | else |
|
37 | else | |
38 | render_404 |
|
38 | render_404 | |
39 | end |
|
39 | end | |
40 | return |
|
40 | return | |
41 | end |
|
41 | end | |
42 | @content = @page.content_for_version(params[:version]) |
|
42 | @content = @page.content_for_version(params[:version]) | |
43 | if params[:export] == 'html' |
|
43 | if params[:export] == 'html' | |
44 | export = render_to_string :action => 'export', :layout => false |
|
44 | export = render_to_string :action => 'export', :layout => false | |
45 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") |
|
45 | send_data(export, :type => 'text/html', :filename => "#{@page.title}.html") | |
46 | return |
|
46 | return | |
47 | elsif params[:export] == 'txt' |
|
47 | elsif params[:export] == 'txt' | |
48 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") |
|
48 | send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt") | |
49 | return |
|
49 | return | |
50 | end |
|
50 | end | |
51 | render :action => 'show' |
|
51 | render :action => 'show' | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | # edit an existing page or a new one |
|
54 | # edit an existing page or a new one | |
55 | def edit |
|
55 | def edit | |
56 | @page = @wiki.find_or_new_page(params[:page]) |
|
56 | @page = @wiki.find_or_new_page(params[:page]) | |
57 | @page.content = WikiContent.new(:page => @page) if @page.new_record? |
|
57 | @page.content = WikiContent.new(:page => @page) if @page.new_record? | |
58 |
|
58 | |||
59 | @content = @page.content_for_version(params[:version]) |
|
59 | @content = @page.content_for_version(params[:version]) | |
60 | @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? |
|
60 | @content.text = "h1. #{@page.pretty_title}" if @content.text.blank? | |
61 | # don't keep previous comment |
|
61 | # don't keep previous comment | |
62 | @content.comments = nil |
|
62 | @content.comments = nil | |
63 | if request.post? |
|
63 | if request.post? | |
64 | if !@page.new_record? && @content.text == params[:content][:text] |
|
64 | if !@page.new_record? && @content.text == params[:content][:text] | |
65 | # don't save if text wasn't changed |
|
65 | # don't save if text wasn't changed | |
66 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
66 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
67 | return |
|
67 | return | |
68 | end |
|
68 | end | |
69 | #@content.text = params[:content][:text] |
|
69 | #@content.text = params[:content][:text] | |
70 | #@content.comments = params[:content][:comments] |
|
70 | #@content.comments = params[:content][:comments] | |
71 | @content.attributes = params[:content] |
|
71 | @content.attributes = params[:content] | |
72 | @content.author = User.current |
|
72 | @content.author = User.current | |
73 | # if page is new @page.save will also save content, but not if page isn't a new record |
|
73 | # if page is new @page.save will also save content, but not if page isn't a new record | |
74 | if (@page.new_record? ? @page.save : @content.save) |
|
74 | if (@page.new_record? ? @page.save : @content.save) | |
75 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
75 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end | |
78 | rescue ActiveRecord::StaleObjectError |
|
78 | rescue ActiveRecord::StaleObjectError | |
79 | # Optimistic locking exception |
|
79 | # Optimistic locking exception | |
80 | flash[:error] = l(:notice_locking_conflict) |
|
80 | flash[:error] = l(:notice_locking_conflict) | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | # rename a page |
|
83 | # rename a page | |
84 | def rename |
|
84 | def rename | |
85 | @page = @wiki.find_page(params[:page]) |
|
85 | @page = @wiki.find_page(params[:page]) | |
86 | @page.redirect_existing_links = true |
|
86 | @page.redirect_existing_links = true | |
87 | # used to display the *original* title if some AR validation errors occur |
|
87 | # used to display the *original* title if some AR validation errors occur | |
88 | @original_title = @page.pretty_title |
|
88 | @original_title = @page.pretty_title | |
89 | if request.post? && @page.update_attributes(params[:wiki_page]) |
|
89 | if request.post? && @page.update_attributes(params[:wiki_page]) | |
90 | flash[:notice] = l(:notice_successful_update) |
|
90 | flash[:notice] = l(:notice_successful_update) | |
91 | redirect_to :action => 'index', :id => @project, :page => @page.title |
|
91 | redirect_to :action => 'index', :id => @project, :page => @page.title | |
92 | end |
|
92 | end | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | # show page history |
|
95 | # show page history | |
96 | def history |
|
96 | def history | |
97 | @page = @wiki.find_page(params[:page]) |
|
97 | @page = @wiki.find_page(params[:page]) | |
98 |
|
98 | |||
99 | @version_count = @page.content.versions.count |
|
99 | @version_count = @page.content.versions.count | |
100 | @version_pages = Paginator.new self, @version_count, 25, params['p'] |
|
100 | @version_pages = Paginator.new self, @version_count, 25, params['p'] | |
101 | # don't load text |
|
101 | # don't load text | |
102 | @versions = @page.content.versions.find :all, |
|
102 | @versions = @page.content.versions.find :all, | |
103 | :select => "id, author_id, comments, updated_on, version", |
|
103 | :select => "id, author_id, comments, updated_on, version", | |
104 | :order => 'version DESC', |
|
104 | :order => 'version DESC', | |
105 | :limit => @version_pages.items_per_page + 1, |
|
105 | :limit => @version_pages.items_per_page + 1, | |
106 | :offset => @version_pages.current.offset |
|
106 | :offset => @version_pages.current.offset | |
107 |
|
107 | |||
108 | render :layout => false if request.xhr? |
|
108 | render :layout => false if request.xhr? | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def diff |
|
111 | def diff | |
112 | @page = @wiki.find_page(params[:page]) |
|
112 | @page = @wiki.find_page(params[:page]) | |
113 | @diff = @page.diff(params[:version], params[:version_from]) |
|
113 | @diff = @page.diff(params[:version], params[:version_from]) | |
114 | render_404 unless @diff |
|
114 | render_404 unless @diff | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | # remove a wiki page and its history |
|
117 | # remove a wiki page and its history | |
118 | def destroy |
|
118 | def destroy | |
119 | @page = @wiki.find_page(params[:page]) |
|
119 | @page = @wiki.find_page(params[:page]) | |
120 | @page.destroy if @page |
|
120 | @page.destroy if @page | |
121 | redirect_to :action => 'special', :id => @project, :page => 'Page_index' |
|
121 | redirect_to :action => 'special', :id => @project, :page => 'Page_index' | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | # display special pages |
|
124 | # display special pages | |
125 | def special |
|
125 | def special | |
126 | page_title = params[:page].downcase |
|
126 | page_title = params[:page].downcase | |
127 | case page_title |
|
127 | case page_title | |
128 | # show pages index, sorted by title |
|
128 | # show pages index, sorted by title | |
129 | when 'page_index', 'date_index' |
|
129 | when 'page_index', 'date_index' | |
130 | # eager load information about last updates, without loading text |
|
130 | # eager load information about last updates, without loading text | |
131 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", |
|
131 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
132 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", |
|
132 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", | |
133 | :order => 'title' |
|
133 | :order => 'title' | |
134 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} |
|
134 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |
135 | # export wiki to a single html file |
|
135 | # export wiki to a single html file | |
136 | when 'export' |
|
136 | when 'export' | |
137 | @pages = @wiki.pages.find :all, :order => 'title' |
|
137 | @pages = @wiki.pages.find :all, :order => 'title' | |
138 | export = render_to_string :action => 'export_multiple', :layout => false |
|
138 | export = render_to_string :action => 'export_multiple', :layout => false | |
139 | send_data(export, :type => 'text/html', :filename => "wiki.html") |
|
139 | send_data(export, :type => 'text/html', :filename => "wiki.html") | |
140 | return |
|
140 | return | |
141 | else |
|
141 | else | |
142 | # requested special page doesn't exist, redirect to default page |
|
142 | # requested special page doesn't exist, redirect to default page | |
143 | redirect_to :action => 'index', :id => @project, :page => nil and return |
|
143 | redirect_to :action => 'index', :id => @project, :page => nil and return | |
144 | end |
|
144 | end | |
145 | render :action => "special_#{page_title}" |
|
145 | render :action => "special_#{page_title}" | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def preview |
|
148 | def preview | |
149 | page = @wiki.find_page(params[:page]) |
|
149 | page = @wiki.find_page(params[:page]) | |
150 | @attachements = page.attachments if page |
|
150 | @attachements = page.attachments if page | |
151 | @text = params[:content][:text] |
|
151 | @text = params[:content][:text] | |
152 | render :partial => 'common/preview' |
|
152 | render :partial => 'common/preview' | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | def add_attachment |
|
155 | def add_attachment | |
156 | @page = @wiki.find_page(params[:page]) |
|
156 | @page = @wiki.find_page(params[:page]) | |
157 | # Save the attachments |
|
157 | attach_files(@page, params[:attachments]) | |
158 | params[:attachments].each { |file| |
|
|||
159 | next unless file.size > 0 |
|
|||
160 | a = Attachment.create(:container => @page, :file => file, :author => User.current) |
|
|||
161 | } if params[:attachments] and params[:attachments].is_a? Array |
|
|||
162 | redirect_to :action => 'index', :page => @page.title |
|
158 | redirect_to :action => 'index', :page => @page.title | |
163 | end |
|
159 | end | |
164 |
|
160 | |||
165 | def destroy_attachment |
|
161 | def destroy_attachment | |
166 | @page = @wiki.find_page(params[:page]) |
|
162 | @page = @wiki.find_page(params[:page]) | |
167 | @page.attachments.find(params[:attachment_id]).destroy |
|
163 | @page.attachments.find(params[:attachment_id]).destroy | |
168 | redirect_to :action => 'index', :page => @page.title |
|
164 | redirect_to :action => 'index', :page => @page.title | |
169 | end |
|
165 | end | |
170 |
|
166 | |||
171 | private |
|
167 | private | |
172 |
|
168 | |||
173 | def find_wiki |
|
169 | def find_wiki | |
174 | @project = Project.find(params[:id]) |
|
170 | @project = Project.find(params[:id]) | |
175 | @wiki = @project.wiki |
|
171 | @wiki = @project.wiki | |
176 | render_404 unless @wiki |
|
172 | render_404 unless @wiki | |
177 | rescue ActiveRecord::RecordNotFound |
|
173 | rescue ActiveRecord::RecordNotFound | |
178 | render_404 |
|
174 | render_404 | |
179 | end |
|
175 | end | |
180 | end |
|
176 | end |
General Comments 0
You need to be logged in to leave comments.
Login now