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