##// END OF EJS Templates
Moves @layout 'base'@ to ApplicationController....
Jean-Philippe Lang -
r1726:2fdf4426cd8f
parent child
Show More
@@ -1,191 +1,190
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 AccountController < ApplicationController
19 layout 'base'
20 19 helper :custom_fields
21 20 include CustomFieldsHelper
22 21
23 22 # prevents login action to be filtered by check_if_login_required application scope filter
24 23 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
25 24
26 25 # Show user's account
27 26 def show
28 27 @user = User.find_active(params[:id])
29 28 @custom_values = @user.custom_values.find(:all, :include => :custom_field)
30 29
31 30 # show only public projects and private projects that the logged in user is also a member of
32 31 @memberships = @user.memberships.select do |membership|
33 32 membership.project.is_public? || (User.current.member_of?(membership.project))
34 33 end
35 34 rescue ActiveRecord::RecordNotFound
36 35 render_404
37 36 end
38 37
39 38 # Login request and validation
40 39 def login
41 40 if request.get?
42 41 # Logout user
43 42 self.logged_user = nil
44 43 else
45 44 # Authenticate user
46 45 user = User.try_to_login(params[:username], params[:password])
47 46 if user.nil?
48 47 # Invalid credentials
49 48 flash.now[:error] = l(:notice_account_invalid_creditentials)
50 49 elsif user.new_record?
51 50 # Onthefly creation failed, display the registration form to fill/fix attributes
52 51 @user = user
53 52 session[:auth_source_registration] = {:login => user.login, :auth_source_id => user.auth_source_id }
54 53 render :action => 'register'
55 54 else
56 55 # Valid user
57 56 self.logged_user = user
58 57 # generate a key and set cookie if autologin
59 58 if params[:autologin] && Setting.autologin?
60 59 token = Token.create(:user => user, :action => 'autologin')
61 60 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
62 61 end
63 62 redirect_back_or_default :controller => 'my', :action => 'page'
64 63 end
65 64 end
66 65 end
67 66
68 67 # Log out current user and redirect to welcome page
69 68 def logout
70 69 cookies.delete :autologin
71 70 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
72 71 self.logged_user = nil
73 72 redirect_to home_url
74 73 end
75 74
76 75 # Enable user to choose a new password
77 76 def lost_password
78 77 redirect_to(home_url) && return unless Setting.lost_password?
79 78 if params[:token]
80 79 @token = Token.find_by_action_and_value("recovery", params[:token])
81 80 redirect_to(home_url) && return unless @token and !@token.expired?
82 81 @user = @token.user
83 82 if request.post?
84 83 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
85 84 if @user.save
86 85 @token.destroy
87 86 flash[:notice] = l(:notice_account_password_updated)
88 87 redirect_to :action => 'login'
89 88 return
90 89 end
91 90 end
92 91 render :template => "account/password_recovery"
93 92 return
94 93 else
95 94 if request.post?
96 95 user = User.find_by_mail(params[:mail])
97 96 # user not found in db
98 97 flash.now[:error] = l(:notice_account_unknown_email) and return unless user
99 98 # user uses an external authentification
100 99 flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
101 100 # create a new token for password recovery
102 101 token = Token.new(:user => user, :action => "recovery")
103 102 if token.save
104 103 Mailer.deliver_lost_password(token)
105 104 flash[:notice] = l(:notice_account_lost_email_sent)
106 105 redirect_to :action => 'login'
107 106 return
108 107 end
109 108 end
110 109 end
111 110 end
112 111
113 112 # User self-registration
114 113 def register
115 114 redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
116 115 if request.get?
117 116 session[:auth_source_registration] = nil
118 117 @user = User.new(:language => Setting.default_language)
119 118 else
120 119 @user = User.new(params[:user])
121 120 @user.admin = false
122 121 @user.status = User::STATUS_REGISTERED
123 122 if session[:auth_source_registration]
124 123 @user.status = User::STATUS_ACTIVE
125 124 @user.login = session[:auth_source_registration][:login]
126 125 @user.auth_source_id = session[:auth_source_registration][:auth_source_id]
127 126 if @user.save
128 127 session[:auth_source_registration] = nil
129 128 self.logged_user = @user
130 129 flash[:notice] = l(:notice_account_activated)
131 130 redirect_to :controller => 'my', :action => 'account'
132 131 end
133 132 else
134 133 @user.login = params[:user][:login]
135 134 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
136 135 case Setting.self_registration
137 136 when '1'
138 137 # Email activation
139 138 token = Token.new(:user => @user, :action => "register")
140 139 if @user.save and token.save
141 140 Mailer.deliver_register(token)
142 141 flash[:notice] = l(:notice_account_register_done)
143 142 redirect_to :action => 'login'
144 143 end
145 144 when '3'
146 145 # Automatic activation
147 146 @user.status = User::STATUS_ACTIVE
148 147 if @user.save
149 148 self.logged_user = @user
150 149 flash[:notice] = l(:notice_account_activated)
151 150 redirect_to :controller => 'my', :action => 'account'
152 151 end
153 152 else
154 153 # Manual activation by the administrator
155 154 if @user.save
156 155 # Sends an email to the administrators
157 156 Mailer.deliver_account_activation_request(@user)
158 157 flash[:notice] = l(:notice_account_pending)
159 158 redirect_to :action => 'login'
160 159 end
161 160 end
162 161 end
163 162 end
164 163 end
165 164
166 165 # Token based account activation
167 166 def activate
168 167 redirect_to(home_url) && return unless Setting.self_registration? && params[:token]
169 168 token = Token.find_by_action_and_value('register', params[:token])
170 169 redirect_to(home_url) && return unless token and !token.expired?
171 170 user = token.user
172 171 redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED
173 172 user.status = User::STATUS_ACTIVE
174 173 if user.save
175 174 token.destroy
176 175 flash[:notice] = l(:notice_account_activated)
177 176 end
178 177 redirect_to :action => 'login'
179 178 end
180 179
181 180 private
182 181 def logged_user=(user)
183 182 if user && user.is_a?(User)
184 183 User.current = user
185 184 session[:user_id] = user.id
186 185 else
187 186 User.current = User.anonymous
188 187 session[:user_id] = nil
189 188 end
190 189 end
191 190 end
@@ -1,86 +1,85
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 AdminController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 helper :sort
23 22 include SortHelper
24 23
25 24 def index
26 25 @no_configuration_data = Redmine::DefaultData::Loader::no_data?
27 26 end
28 27
29 28 def projects
30 29 sort_init 'name', 'asc'
31 30 sort_update
32 31
33 32 @status = params[:status] ? params[:status].to_i : 0
34 33 conditions = nil
35 34 conditions = ["status=?", @status] unless @status == 0
36 35
37 36 @project_count = Project.count(:conditions => conditions)
38 37 @project_pages = Paginator.new self, @project_count,
39 38 per_page_option,
40 39 params['page']
41 40 @projects = Project.find :all, :order => sort_clause,
42 41 :conditions => conditions,
43 42 :limit => @project_pages.items_per_page,
44 43 :offset => @project_pages.current.offset
45 44
46 45 render :action => "projects", :layout => false if request.xhr?
47 46 end
48 47
49 48 # Loads the default configuration
50 49 # (roles, trackers, statuses, workflow, enumerations)
51 50 def default_configuration
52 51 if request.post?
53 52 begin
54 53 Redmine::DefaultData::Loader::load(params[:lang])
55 54 flash[:notice] = l(:notice_default_data_loaded)
56 55 rescue Exception => e
57 56 flash[:error] = l(:error_can_t_load_default_data, e.message)
58 57 end
59 58 end
60 59 redirect_to :action => 'index'
61 60 end
62 61
63 62 def test_email
64 63 raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
65 64 # Force ActionMailer to raise delivery errors so we can catch it
66 65 ActionMailer::Base.raise_delivery_errors = true
67 66 begin
68 67 @test = Mailer.deliver_test(User.current)
69 68 flash[:notice] = l(:notice_email_sent, User.current.mail)
70 69 rescue Exception => e
71 70 flash[:error] = l(:notice_email_error, e.message)
72 71 end
73 72 ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
74 73 redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications'
75 74 end
76 75
77 76 def info
78 77 @db_adapter_name = ActiveRecord::Base.connection.adapter_name
79 78 @flags = {
80 79 :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?,
81 80 :file_repository_writable => File.writable?(Attachment.storage_path),
82 81 :rmagick_available => Object.const_defined?(:Magick)
83 82 }
84 83 @plugins = Redmine::Plugin.registered_plugins
85 84 end
86 85 end
@@ -1,219 +1,221
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 'uri'
19 19
20 20 class ApplicationController < ActionController::Base
21 layout 'base'
22
21 23 before_filter :user_setup, :check_if_login_required, :set_localization
22 24 filter_parameter_logging :password
23 25
24 26 include Redmine::MenuManager::MenuController
25 27 helper Redmine::MenuManager::MenuHelper
26 28
27 29 REDMINE_SUPPORTED_SCM.each do |scm|
28 30 require_dependency "repository/#{scm.underscore}"
29 31 end
30 32
31 33 def current_role
32 34 @current_role ||= User.current.role_for_project(@project)
33 35 end
34 36
35 37 def user_setup
36 38 # Check the settings cache for each request
37 39 Setting.check_cache
38 40 # Find the current user
39 41 User.current = find_current_user
40 42 end
41 43
42 44 # Returns the current user or nil if no user is logged in
43 45 def find_current_user
44 46 if session[:user_id]
45 47 # existing session
46 48 (User.find_active(session[:user_id]) rescue nil)
47 49 elsif cookies[:autologin] && Setting.autologin?
48 50 # auto-login feature
49 51 User.find_by_autologin_key(cookies[:autologin])
50 52 elsif params[:key] && accept_key_auth_actions.include?(params[:action])
51 53 # RSS key authentication
52 54 User.find_by_rss_key(params[:key])
53 55 end
54 56 end
55 57
56 58 # check if login is globally required to access the application
57 59 def check_if_login_required
58 60 # no check needed if user is already logged in
59 61 return true if User.current.logged?
60 62 require_login if Setting.login_required?
61 63 end
62 64
63 65 def set_localization
64 66 User.current.language = nil unless User.current.logged?
65 67 lang = begin
66 68 if !User.current.language.blank? && GLoc.valid_language?(User.current.language)
67 69 User.current.language
68 70 elsif request.env['HTTP_ACCEPT_LANGUAGE']
69 71 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase
70 72 if !accept_lang.blank? && (GLoc.valid_language?(accept_lang) || GLoc.valid_language?(accept_lang = accept_lang.split('-').first))
71 73 User.current.language = accept_lang
72 74 end
73 75 end
74 76 rescue
75 77 nil
76 78 end || Setting.default_language
77 79 set_language_if_valid(lang)
78 80 end
79 81
80 82 def require_login
81 83 if !User.current.logged?
82 84 redirect_to :controller => "account", :action => "login", :back_url => request.request_uri
83 85 return false
84 86 end
85 87 true
86 88 end
87 89
88 90 def require_admin
89 91 return unless require_login
90 92 if !User.current.admin?
91 93 render_403
92 94 return false
93 95 end
94 96 true
95 97 end
96 98
97 99 # Authorize the user for the requested action
98 100 def authorize(ctrl = params[:controller], action = params[:action])
99 101 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
100 102 allowed ? true : (User.current.logged? ? render_403 : require_login)
101 103 end
102 104
103 105 # make sure that the user is a member of the project (or admin) if project is private
104 106 # used as a before_filter for actions that do not require any particular permission on the project
105 107 def check_project_privacy
106 108 if @project && @project.active?
107 109 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
108 110 true
109 111 else
110 112 User.current.logged? ? render_403 : require_login
111 113 end
112 114 else
113 115 @project = nil
114 116 render_404
115 117 false
116 118 end
117 119 end
118 120
119 121 def redirect_back_or_default(default)
120 122 back_url = params[:back_url]
121 123 if !back_url.blank?
122 124 uri = URI.parse(back_url)
123 125 # do not redirect user to another host
124 126 if uri.relative? || (uri.host == request.host)
125 127 redirect_to(back_url) and return
126 128 end
127 129 end
128 130 redirect_to default
129 131 end
130 132
131 133 def render_403
132 134 @project = nil
133 135 render :template => "common/403", :layout => !request.xhr?, :status => 403
134 136 return false
135 137 end
136 138
137 139 def render_404
138 140 render :template => "common/404", :layout => !request.xhr?, :status => 404
139 141 return false
140 142 end
141 143
142 144 def render_error(msg)
143 145 flash.now[:error] = msg
144 146 render :nothing => true, :layout => !request.xhr?, :status => 500
145 147 end
146 148
147 149 def render_feed(items, options={})
148 150 @items = items || []
149 151 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
150 152 @items = @items.slice(0, Setting.feeds_limit.to_i)
151 153 @title = options[:title] || Setting.app_title
152 154 render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
153 155 end
154 156
155 157 def self.accept_key_auth(*actions)
156 158 actions = actions.flatten.map(&:to_s)
157 159 write_inheritable_attribute('accept_key_auth_actions', actions)
158 160 end
159 161
160 162 def accept_key_auth_actions
161 163 self.class.read_inheritable_attribute('accept_key_auth_actions') || []
162 164 end
163 165
164 166 # TODO: move to model
165 167 def attach_files(obj, attachments)
166 168 attached = []
167 169 if attachments && attachments.is_a?(Hash)
168 170 attachments.each_value do |attachment|
169 171 file = attachment['file']
170 172 next unless file && file.size > 0
171 173 a = Attachment.create(:container => obj,
172 174 :file => file,
173 175 :description => attachment['description'].to_s.strip,
174 176 :author => User.current)
175 177 attached << a unless a.new_record?
176 178 end
177 179 end
178 180 attached
179 181 end
180 182
181 183 # Returns the number of objects that should be displayed
182 184 # on the paginated list
183 185 def per_page_option
184 186 per_page = nil
185 187 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
186 188 per_page = params[:per_page].to_s.to_i
187 189 session[:per_page] = per_page
188 190 elsif session[:per_page]
189 191 per_page = session[:per_page]
190 192 else
191 193 per_page = Setting.per_page_options_array.first || 25
192 194 end
193 195 per_page
194 196 end
195 197
196 198 # qvalues http header parser
197 199 # code taken from webrick
198 200 def parse_qvalues(value)
199 201 tmp = []
200 202 if value
201 203 parts = value.split(/,\s*/)
202 204 parts.each {|part|
203 205 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
204 206 val = m[1]
205 207 q = (m[2] or 1).to_f
206 208 tmp.push([val, q])
207 209 end
208 210 }
209 211 tmp = tmp.sort_by{|val, q| -q}
210 212 tmp.collect!{|val, q| val}
211 213 end
212 214 return tmp
213 215 end
214 216
215 217 # Returns a string that can be used as filename value in Content-Disposition header
216 218 def filename_for_content_disposition(name)
217 219 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
218 220 end
219 221 end
@@ -1,56 +1,55
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 AttachmentsController < ApplicationController
19 layout 'base'
20 19 before_filter :find_project
21 20
22 21 def show
23 22 if @attachment.is_diff?
24 23 @diff = File.new(@attachment.diskfile, "rb").read
25 24 render :action => 'diff'
26 25 elsif @attachment.is_text?
27 26 @content = File.new(@attachment.diskfile, "rb").read
28 27 render :action => 'file'
29 28 elsif
30 29 download
31 30 end
32 31 end
33 32
34 33 def download
35 34 @attachment.increment_download if @attachment.container.is_a?(Version)
36 35
37 36 # images are sent inline
38 37 send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
39 38 :type => @attachment.content_type,
40 39 :disposition => (@attachment.image? ? 'inline' : 'attachment')
41 40 end
42 41
43 42 private
44 43 def find_project
45 44 @attachment = Attachment.find(params[:id])
46 45 # Show 404 if the filename in the url is wrong
47 46 raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
48 47
49 48 @project = @attachment.project
50 49 permission = @attachment.container.is_a?(Version) ? :view_files : "view_#{@attachment.container.class.name.underscore.pluralize}".to_sym
51 50 allowed = User.current.allowed_to?(permission, @project)
52 51 allowed ? true : (User.current.logged? ? render_403 : require_login)
53 52 rescue ActiveRecord::RecordNotFound
54 53 render_404
55 54 end
56 55 end
@@ -1,83 +1,82
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 AuthSourcesController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 def index
23 22 list
24 23 render :action => 'list' unless request.xhr?
25 24 end
26 25
27 26 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28 27 verify :method => :post, :only => [ :destroy, :create, :update ],
29 28 :redirect_to => { :action => :list }
30 29
31 30 def list
32 31 @auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
33 32 render :action => "list", :layout => false if request.xhr?
34 33 end
35 34
36 35 def new
37 36 @auth_source = AuthSourceLdap.new
38 37 end
39 38
40 39 def create
41 40 @auth_source = AuthSourceLdap.new(params[:auth_source])
42 41 if @auth_source.save
43 42 flash[:notice] = l(:notice_successful_create)
44 43 redirect_to :action => 'list'
45 44 else
46 45 render :action => 'new'
47 46 end
48 47 end
49 48
50 49 def edit
51 50 @auth_source = AuthSource.find(params[:id])
52 51 end
53 52
54 53 def update
55 54 @auth_source = AuthSource.find(params[:id])
56 55 if @auth_source.update_attributes(params[:auth_source])
57 56 flash[:notice] = l(:notice_successful_update)
58 57 redirect_to :action => 'list'
59 58 else
60 59 render :action => 'edit'
61 60 end
62 61 end
63 62
64 63 def test_connection
65 64 @auth_method = AuthSource.find(params[:id])
66 65 begin
67 66 @auth_method.test_connection
68 67 flash[:notice] = l(:notice_successful_connection)
69 68 rescue => text
70 69 flash[:error] = "Unable to connect (#{text})"
71 70 end
72 71 redirect_to :action => 'list'
73 72 end
74 73
75 74 def destroy
76 75 @auth_source = AuthSource.find(params[:id])
77 76 unless @auth_source.users.find(:first)
78 77 @auth_source.destroy
79 78 flash[:notice] = l(:notice_successful_delete)
80 79 end
81 80 redirect_to :action => 'list'
82 81 end
83 82 end
@@ -1,86 +1,85
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 BoardsController < ApplicationController
19 layout 'base'
20 19 before_filter :find_project, :authorize
21 20
22 21 helper :messages
23 22 include MessagesHelper
24 23 helper :sort
25 24 include SortHelper
26 25 helper :watchers
27 26 include WatchersHelper
28 27
29 28 def index
30 29 @boards = @project.boards
31 30 # show the board if there is only one
32 31 if @boards.size == 1
33 32 @board = @boards.first
34 33 show
35 34 end
36 35 end
37 36
38 37 def show
39 38 sort_init "#{Message.table_name}.updated_on", "desc"
40 39 sort_update
41 40
42 41 @topic_count = @board.topics.count
43 42 @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
44 43 @topics = @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
45 44 :include => [:author, {:last_reply => :author}],
46 45 :limit => @topic_pages.items_per_page,
47 46 :offset => @topic_pages.current.offset
48 47 render :action => 'show', :layout => !request.xhr?
49 48 end
50 49
51 50 verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
52 51
53 52 def new
54 53 @board = Board.new(params[:board])
55 54 @board.project = @project
56 55 if request.post? && @board.save
57 56 flash[:notice] = l(:notice_successful_create)
58 57 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
59 58 end
60 59 end
61 60
62 61 def edit
63 62 if request.post? && @board.update_attributes(params[:board])
64 63 case params[:position]
65 64 when 'highest'; @board.move_to_top
66 65 when 'higher'; @board.move_higher
67 66 when 'lower'; @board.move_lower
68 67 when 'lowest'; @board.move_to_bottom
69 68 end if params[:position]
70 69 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
71 70 end
72 71 end
73 72
74 73 def destroy
75 74 @board.destroy
76 75 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
77 76 end
78 77
79 78 private
80 79 def find_project
81 80 @project = Project.find(params[:project_id])
82 81 @board = @project.boards.find(params[:id]) if params[:id]
83 82 rescue ActiveRecord::RecordNotFound
84 83 render_404
85 84 end
86 85 end
@@ -1,89 +1,88
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 CustomFieldsController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 def index
23 22 list
24 23 render :action => 'list' unless request.xhr?
25 24 end
26 25
27 26 def list
28 27 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
29 28 @tab = params[:tab] || 'IssueCustomField'
30 29 render :action => "list", :layout => false if request.xhr?
31 30 end
32 31
33 32 def new
34 33 case params[:type]
35 34 when "IssueCustomField"
36 35 @custom_field = IssueCustomField.new(params[:custom_field])
37 36 @custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
38 37 when "UserCustomField"
39 38 @custom_field = UserCustomField.new(params[:custom_field])
40 39 when "ProjectCustomField"
41 40 @custom_field = ProjectCustomField.new(params[:custom_field])
42 41 when "TimeEntryCustomField"
43 42 @custom_field = TimeEntryCustomField.new(params[:custom_field])
44 43 else
45 44 redirect_to :action => 'list'
46 45 return
47 46 end
48 47 if request.post? and @custom_field.save
49 48 flash[:notice] = l(:notice_successful_create)
50 49 redirect_to :action => 'list', :tab => @custom_field.class.name
51 50 end
52 51 @trackers = Tracker.find(:all, :order => 'position')
53 52 end
54 53
55 54 def edit
56 55 @custom_field = CustomField.find(params[:id])
57 56 if request.post? and @custom_field.update_attributes(params[:custom_field])
58 57 if @custom_field.is_a? IssueCustomField
59 58 @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
60 59 end
61 60 flash[:notice] = l(:notice_successful_update)
62 61 redirect_to :action => 'list', :tab => @custom_field.class.name
63 62 end
64 63 @trackers = Tracker.find(:all, :order => 'position')
65 64 end
66 65
67 66 def move
68 67 @custom_field = CustomField.find(params[:id])
69 68 case params[:position]
70 69 when 'highest'
71 70 @custom_field.move_to_top
72 71 when 'higher'
73 72 @custom_field.move_higher
74 73 when 'lower'
75 74 @custom_field.move_lower
76 75 when 'lowest'
77 76 @custom_field.move_to_bottom
78 77 end if params[:position]
79 78 redirect_to :action => 'list', :tab => @custom_field.class.name
80 79 end
81 80
82 81 def destroy
83 82 @custom_field = CustomField.find(params[:id]).destroy
84 83 redirect_to :action => 'list', :tab => @custom_field.class.name
85 84 rescue
86 85 flash[:error] = "Unable to delete custom field"
87 86 redirect_to :action => 'list'
88 87 end
89 88 end
@@ -1,93 +1,92
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 layout 'base'
20 19 before_filter :find_project, :only => [:index, :new]
21 20 before_filter :find_document, :except => [:index, :new]
22 21 before_filter :authorize
23 22
24 23 helper :attachments
25 24
26 25 def index
27 26 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
28 27 documents = @project.documents.find :all, :include => [:attachments, :category]
29 28 case @sort_by
30 29 when 'date'
31 30 @grouped = documents.group_by {|d| d.created_on.to_date }
32 31 when 'title'
33 32 @grouped = documents.group_by {|d| d.title.first.upcase}
34 33 when 'author'
35 34 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
36 35 else
37 36 @grouped = documents.group_by(&:category)
38 37 end
39 38 render :layout => false if request.xhr?
40 39 end
41 40
42 41 def show
43 42 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
44 43 end
45 44
46 45 def new
47 46 @document = @project.documents.build(params[:document])
48 47 if request.post? and @document.save
49 48 attach_files(@document, params[:attachments])
50 49 flash[:notice] = l(:notice_successful_create)
51 50 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
52 51 redirect_to :action => 'index', :project_id => @project
53 52 end
54 53 end
55 54
56 55 def edit
57 56 @categories = Enumeration::get_values('DCAT')
58 57 if request.post? and @document.update_attributes(params[:document])
59 58 flash[:notice] = l(:notice_successful_update)
60 59 redirect_to :action => 'show', :id => @document
61 60 end
62 61 end
63 62
64 63 def destroy
65 64 @document.destroy
66 65 redirect_to :controller => 'documents', :action => 'index', :project_id => @project
67 66 end
68 67
69 68 def add_attachment
70 69 attachments = attach_files(@document, params[:attachments])
71 70 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
72 71 redirect_to :action => 'show', :id => @document
73 72 end
74 73
75 74 def destroy_attachment
76 75 @document.attachments.find(params[:attachment_id]).destroy
77 76 redirect_to :action => 'show', :id => @document
78 77 end
79 78
80 79 private
81 80 def find_project
82 81 @project = Project.find(params[:project_id])
83 82 rescue ActiveRecord::RecordNotFound
84 83 render_404
85 84 end
86 85
87 86 def find_document
88 87 @document = Document.find(params[:id])
89 88 @project = @document.project
90 89 rescue ActiveRecord::RecordNotFound
91 90 render_404
92 91 end
93 92 end
@@ -1,94 +1,93
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 EnumerationsController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 def index
23 22 list
24 23 render :action => 'list'
25 24 end
26 25
27 26 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28 27 verify :method => :post, :only => [ :destroy, :create, :update ],
29 28 :redirect_to => { :action => :list }
30 29
31 30 def list
32 31 end
33 32
34 33 def new
35 34 @enumeration = Enumeration.new(:opt => params[:opt])
36 35 end
37 36
38 37 def create
39 38 @enumeration = Enumeration.new(params[:enumeration])
40 39 if @enumeration.save
41 40 flash[:notice] = l(:notice_successful_create)
42 41 redirect_to :action => 'list', :opt => @enumeration.opt
43 42 else
44 43 render :action => 'new'
45 44 end
46 45 end
47 46
48 47 def edit
49 48 @enumeration = Enumeration.find(params[:id])
50 49 end
51 50
52 51 def update
53 52 @enumeration = Enumeration.find(params[:id])
54 53 if @enumeration.update_attributes(params[:enumeration])
55 54 flash[:notice] = l(:notice_successful_update)
56 55 redirect_to :action => 'list', :opt => @enumeration.opt
57 56 else
58 57 render :action => 'edit'
59 58 end
60 59 end
61 60
62 61 def move
63 62 @enumeration = Enumeration.find(params[:id])
64 63 case params[:position]
65 64 when 'highest'
66 65 @enumeration.move_to_top
67 66 when 'higher'
68 67 @enumeration.move_higher
69 68 when 'lower'
70 69 @enumeration.move_lower
71 70 when 'lowest'
72 71 @enumeration.move_to_bottom
73 72 end if params[:position]
74 73 redirect_to :action => 'index'
75 74 end
76 75
77 76 def destroy
78 77 @enumeration = Enumeration.find(params[:id])
79 78 if !@enumeration.in_use?
80 79 # No associated objects
81 80 @enumeration.destroy
82 81 redirect_to :action => 'index'
83 82 elsif params[:reassign_to_id]
84 83 if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
85 84 @enumeration.destroy(reassign_to)
86 85 redirect_to :action => 'index'
87 86 end
88 87 end
89 88 @enumerations = Enumeration.get_values(@enumeration.opt) - [@enumeration]
90 89 #rescue
91 90 # flash[:error] = 'Unable to delete enumeration'
92 91 # redirect_to :action => 'index'
93 92 end
94 93 end
@@ -1,53 +1,52
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 IssueCategoriesController < ApplicationController
19 layout 'base'
20 19 menu_item :settings
21 20 before_filter :find_project, :authorize
22 21
23 22 verify :method => :post, :only => :destroy
24 23
25 24 def edit
26 25 if request.post? and @category.update_attributes(params[:category])
27 26 flash[:notice] = l(:notice_successful_update)
28 27 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
29 28 end
30 29 end
31 30
32 31 def destroy
33 32 @issue_count = @category.issues.size
34 33 if @issue_count == 0
35 34 # No issue assigned to this category
36 35 @category.destroy
37 36 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
38 37 elsif params[:todo]
39 38 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
40 39 @category.destroy(reassign_to)
41 40 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
42 41 end
43 42 @categories = @project.issue_categories - [@category]
44 43 end
45 44
46 45 private
47 46 def find_project
48 47 @category = IssueCategory.find(params[:id])
49 48 @project = @category.project
50 49 rescue ActiveRecord::RecordNotFound
51 50 render_404
52 51 end
53 52 end
@@ -1,59 +1,58
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 IssueRelationsController < ApplicationController
19 layout 'base'
20 19 before_filter :find_project, :authorize
21 20
22 21 def new
23 22 @relation = IssueRelation.new(params[:relation])
24 23 @relation.issue_from = @issue
25 24 @relation.save if request.post?
26 25 respond_to do |format|
27 26 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
28 27 format.js do
29 28 render :update do |page|
30 29 page.replace_html "relations", :partial => 'issues/relations'
31 30 if @relation.errors.empty?
32 31 page << "$('relation_delay').value = ''"
33 32 page << "$('relation_issue_to_id').value = ''"
34 33 end
35 34 end
36 35 end
37 36 end
38 37 end
39 38
40 39 def destroy
41 40 relation = IssueRelation.find(params[:id])
42 41 if request.post? && @issue.relations.include?(relation)
43 42 relation.destroy
44 43 @issue.reload
45 44 end
46 45 respond_to do |format|
47 46 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
48 47 format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} }
49 48 end
50 49 end
51 50
52 51 private
53 52 def find_project
54 53 @issue = Issue.find(params[:issue_id])
55 54 @project = @issue.project
56 55 rescue ActiveRecord::RecordNotFound
57 56 render_404
58 57 end
59 58 end
@@ -1,85 +1,84
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 IssueStatusesController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 verify :method => :post, :only => [ :destroy, :create, :update, :move ],
23 22 :redirect_to => { :action => :list }
24 23
25 24 def index
26 25 list
27 26 render :action => 'list' unless request.xhr?
28 27 end
29 28
30 29 def list
31 30 @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
32 31 render :action => "list", :layout => false if request.xhr?
33 32 end
34 33
35 34 def new
36 35 @issue_status = IssueStatus.new
37 36 end
38 37
39 38 def create
40 39 @issue_status = IssueStatus.new(params[:issue_status])
41 40 if @issue_status.save
42 41 flash[:notice] = l(:notice_successful_create)
43 42 redirect_to :action => 'list'
44 43 else
45 44 render :action => 'new'
46 45 end
47 46 end
48 47
49 48 def edit
50 49 @issue_status = IssueStatus.find(params[:id])
51 50 end
52 51
53 52 def update
54 53 @issue_status = IssueStatus.find(params[:id])
55 54 if @issue_status.update_attributes(params[:issue_status])
56 55 flash[:notice] = l(:notice_successful_update)
57 56 redirect_to :action => 'list'
58 57 else
59 58 render :action => 'edit'
60 59 end
61 60 end
62 61
63 62 def move
64 63 @issue_status = IssueStatus.find(params[:id])
65 64 case params[:position]
66 65 when 'highest'
67 66 @issue_status.move_to_top
68 67 when 'higher'
69 68 @issue_status.move_higher
70 69 when 'lower'
71 70 @issue_status.move_lower
72 71 when 'lowest'
73 72 @issue_status.move_to_bottom
74 73 end if params[:position]
75 74 redirect_to :action => 'list'
76 75 end
77 76
78 77 def destroy
79 78 IssueStatus.find(params[:id]).destroy
80 79 redirect_to :action => 'list'
81 80 rescue
82 81 flash[:error] = "Unable to delete issue status"
83 82 redirect_to :action => 'list'
84 83 end
85 84 end
@@ -1,430 +1,429
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 layout 'base'
20 19 menu_item :new_issue, :only => :new
21 20
22 21 before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment]
23 22 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 23 before_filter :find_project, :only => [:new, :update_form, :preview]
25 24 before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
26 25 before_filter :find_optional_project, :only => [:index, :changes]
27 26 accept_key_auth :index, :changes
28 27
29 28 helper :journals
30 29 helper :projects
31 30 include ProjectsHelper
32 31 helper :custom_fields
33 32 include CustomFieldsHelper
34 33 helper :ifpdf
35 34 include IfpdfHelper
36 35 helper :issue_relations
37 36 include IssueRelationsHelper
38 37 helper :watchers
39 38 include WatchersHelper
40 39 helper :attachments
41 40 include AttachmentsHelper
42 41 helper :queries
43 42 helper :sort
44 43 include SortHelper
45 44 include IssuesHelper
46 45 helper :timelog
47 46
48 47 def index
49 48 sort_init "#{Issue.table_name}.id", "desc"
50 49 sort_update
51 50 retrieve_query
52 51 if @query.valid?
53 52 limit = per_page_option
54 53 respond_to do |format|
55 54 format.html { }
56 55 format.atom { }
57 56 format.csv { limit = Setting.issues_export_limit.to_i }
58 57 format.pdf { limit = Setting.issues_export_limit.to_i }
59 58 end
60 59 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
61 60 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
62 61 @issues = Issue.find :all, :order => sort_clause,
63 62 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
64 63 :conditions => @query.statement,
65 64 :limit => limit,
66 65 :offset => @issue_pages.current.offset
67 66 respond_to do |format|
68 67 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
69 68 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
70 69 format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
71 70 format.pdf { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
72 71 end
73 72 else
74 73 # Send html if the query is not valid
75 74 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
76 75 end
77 76 rescue ActiveRecord::RecordNotFound
78 77 render_404
79 78 end
80 79
81 80 def changes
82 81 sort_init "#{Issue.table_name}.id", "desc"
83 82 sort_update
84 83 retrieve_query
85 84 if @query.valid?
86 85 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
87 86 :conditions => @query.statement,
88 87 :limit => 25,
89 88 :order => "#{Journal.table_name}.created_on DESC"
90 89 end
91 90 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
92 91 render :layout => false, :content_type => 'application/atom+xml'
93 92 rescue ActiveRecord::RecordNotFound
94 93 render_404
95 94 end
96 95
97 96 def show
98 97 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
99 98 @journals.each_with_index {|j,i| j.indice = i+1}
100 99 @journals.reverse! if User.current.wants_comments_in_reverse_order?
101 100 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
102 101 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
103 102 @priorities = Enumeration::get_values('IPRI')
104 103 @time_entry = TimeEntry.new
105 104 respond_to do |format|
106 105 format.html { render :template => 'issues/show.rhtml' }
107 106 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
108 107 format.pdf { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
109 108 end
110 109 end
111 110
112 111 # Add a new issue
113 112 # The new issue will be created from an existing one if copy_from parameter is given
114 113 def new
115 114 @issue = Issue.new
116 115 @issue.copy_from(params[:copy_from]) if params[:copy_from]
117 116 @issue.project = @project
118 117 # Tracker must be set before custom field values
119 118 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
120 119 if @issue.tracker.nil?
121 120 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
122 121 render :nothing => true, :layout => true
123 122 return
124 123 end
125 124 @issue.attributes = params[:issue]
126 125 @issue.author = User.current
127 126
128 127 default_status = IssueStatus.default
129 128 unless default_status
130 129 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
131 130 render :nothing => true, :layout => true
132 131 return
133 132 end
134 133 @issue.status = default_status
135 134 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
136 135
137 136 if request.get? || request.xhr?
138 137 @issue.start_date ||= Date.today
139 138 else
140 139 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
141 140 # Check that the user is allowed to apply the requested status
142 141 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
143 142 if @issue.save
144 143 attach_files(@issue, params[:attachments])
145 144 flash[:notice] = l(:notice_successful_create)
146 145 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
147 146 redirect_to :controller => 'issues', :action => 'show', :id => @issue
148 147 return
149 148 end
150 149 end
151 150 @priorities = Enumeration::get_values('IPRI')
152 151 render :layout => !request.xhr?
153 152 end
154 153
155 154 # Attributes that can be updated on workflow transition (without :edit permission)
156 155 # TODO: make it configurable (at least per role)
157 156 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
158 157
159 158 def edit
160 159 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
161 160 @priorities = Enumeration::get_values('IPRI')
162 161 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
163 162 @time_entry = TimeEntry.new
164 163
165 164 @notes = params[:notes]
166 165 journal = @issue.init_journal(User.current, @notes)
167 166 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
168 167 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
169 168 attrs = params[:issue].dup
170 169 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
171 170 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
172 171 @issue.attributes = attrs
173 172 end
174 173
175 174 if request.post?
176 175 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
177 176 @time_entry.attributes = params[:time_entry]
178 177 attachments = attach_files(@issue, params[:attachments])
179 178 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
180 179 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save
181 180 # Log spend time
182 181 if current_role.allowed_to?(:log_time)
183 182 @time_entry.save
184 183 end
185 184 if !journal.new_record?
186 185 # Only send notification if something was actually changed
187 186 flash[:notice] = l(:notice_successful_update)
188 187 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
189 188 end
190 189 redirect_to(params[:back_to] || {:action => 'show', :id => @issue})
191 190 end
192 191 end
193 192 rescue ActiveRecord::StaleObjectError
194 193 # Optimistic locking exception
195 194 flash.now[:error] = l(:notice_locking_conflict)
196 195 end
197 196
198 197 def reply
199 198 journal = Journal.find(params[:journal_id]) if params[:journal_id]
200 199 if journal
201 200 user = journal.user
202 201 text = journal.notes
203 202 else
204 203 user = @issue.author
205 204 text = @issue.description
206 205 end
207 206 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
208 207 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
209 208 render(:update) { |page|
210 209 page.<< "$('notes').value = \"#{content}\";"
211 210 page.show 'update'
212 211 page << "Form.Element.focus('notes');"
213 212 page << "Element.scrollTo('update');"
214 213 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
215 214 }
216 215 end
217 216
218 217 # Bulk edit a set of issues
219 218 def bulk_edit
220 219 if request.post?
221 220 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
222 221 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
223 222 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
224 223 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
225 224 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
226 225
227 226 unsaved_issue_ids = []
228 227 @issues.each do |issue|
229 228 journal = issue.init_journal(User.current, params[:notes])
230 229 issue.priority = priority if priority
231 230 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
232 231 issue.category = category if category || params[:category_id] == 'none'
233 232 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
234 233 issue.start_date = params[:start_date] unless params[:start_date].blank?
235 234 issue.due_date = params[:due_date] unless params[:due_date].blank?
236 235 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
237 236 # Don't save any change to the issue if the user is not authorized to apply the requested status
238 237 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
239 238 # Send notification for each issue (if changed)
240 239 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
241 240 else
242 241 # Keep unsaved issue ids to display them in flash error
243 242 unsaved_issue_ids << issue.id
244 243 end
245 244 end
246 245 if unsaved_issue_ids.empty?
247 246 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
248 247 else
249 248 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
250 249 end
251 250 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
252 251 return
253 252 end
254 253 # Find potential statuses the user could be allowed to switch issues to
255 254 @available_statuses = Workflow.find(:all, :include => :new_status,
256 255 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
257 256 end
258 257
259 258 def move
260 259 @allowed_projects = []
261 260 # find projects to which the user is allowed to move the issue
262 261 if User.current.admin?
263 262 # admin is allowed to move issues to any active (visible) project
264 263 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
265 264 else
266 265 User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:move_issues)}
267 266 end
268 267 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
269 268 @target_project ||= @project
270 269 @trackers = @target_project.trackers
271 270 if request.post?
272 271 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
273 272 unsaved_issue_ids = []
274 273 @issues.each do |issue|
275 274 issue.init_journal(User.current)
276 275 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
277 276 end
278 277 if unsaved_issue_ids.empty?
279 278 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
280 279 else
281 280 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
282 281 end
283 282 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
284 283 return
285 284 end
286 285 render :layout => false if request.xhr?
287 286 end
288 287
289 288 def destroy
290 289 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
291 290 if @hours > 0
292 291 case params[:todo]
293 292 when 'destroy'
294 293 # nothing to do
295 294 when 'nullify'
296 295 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
297 296 when 'reassign'
298 297 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
299 298 if reassign_to.nil?
300 299 flash.now[:error] = l(:error_issue_not_found_in_project)
301 300 return
302 301 else
303 302 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
304 303 end
305 304 else
306 305 # display the destroy form
307 306 return
308 307 end
309 308 end
310 309 @issues.each(&:destroy)
311 310 redirect_to :action => 'index', :project_id => @project
312 311 end
313 312
314 313 def destroy_attachment
315 314 a = @issue.attachments.find(params[:attachment_id])
316 315 a.destroy
317 316 journal = @issue.init_journal(User.current)
318 317 journal.details << JournalDetail.new(:property => 'attachment',
319 318 :prop_key => a.id,
320 319 :old_value => a.filename)
321 320 journal.save
322 321 redirect_to :action => 'show', :id => @issue
323 322 end
324 323
325 324 def context_menu
326 325 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
327 326 if (@issues.size == 1)
328 327 @issue = @issues.first
329 328 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
330 329 @assignables = @issue.assignable_users
331 330 @assignables << @issue.assigned_to if @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
332 331 end
333 332 projects = @issues.collect(&:project).compact.uniq
334 333 @project = projects.first if projects.size == 1
335 334
336 335 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
337 336 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
338 337 :update => (@issue && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && !@allowed_statuses.empty?))),
339 338 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
340 339 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
341 340 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
342 341 }
343 342
344 343 @priorities = Enumeration.get_values('IPRI').reverse
345 344 @statuses = IssueStatus.find(:all, :order => 'position')
346 345 @back = request.env['HTTP_REFERER']
347 346
348 347 render :layout => false
349 348 end
350 349
351 350 def update_form
352 351 @issue = Issue.new(params[:issue])
353 352 render :action => :new, :layout => false
354 353 end
355 354
356 355 def preview
357 356 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
358 357 @attachements = @issue.attachments if @issue
359 358 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
360 359 render :partial => 'common/preview'
361 360 end
362 361
363 362 private
364 363 def find_issue
365 364 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
366 365 @project = @issue.project
367 366 rescue ActiveRecord::RecordNotFound
368 367 render_404
369 368 end
370 369
371 370 # Filter for bulk operations
372 371 def find_issues
373 372 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
374 373 raise ActiveRecord::RecordNotFound if @issues.empty?
375 374 projects = @issues.collect(&:project).compact.uniq
376 375 if projects.size == 1
377 376 @project = projects.first
378 377 else
379 378 # TODO: let users bulk edit/move/destroy issues from different projects
380 379 render_error 'Can not bulk edit/move/destroy issues from different projects' and return false
381 380 end
382 381 rescue ActiveRecord::RecordNotFound
383 382 render_404
384 383 end
385 384
386 385 def find_project
387 386 @project = Project.find(params[:project_id])
388 387 rescue ActiveRecord::RecordNotFound
389 388 render_404
390 389 end
391 390
392 391 def find_optional_project
393 392 return true unless params[:project_id]
394 393 @project = Project.find(params[:project_id])
395 394 authorize
396 395 rescue ActiveRecord::RecordNotFound
397 396 render_404
398 397 end
399 398
400 399 # Retrieve query from session or build a new query
401 400 def retrieve_query
402 401 if !params[:query_id].blank?
403 402 cond = "project_id IS NULL"
404 403 cond << " OR project_id = #{@project.id}" if @project
405 404 @query = Query.find(params[:query_id], :conditions => cond)
406 405 @query.project = @project
407 406 session[:query] = {:id => @query.id, :project_id => @query.project_id}
408 407 else
409 408 if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
410 409 # Give it a name, required to be valid
411 410 @query = Query.new(:name => "_")
412 411 @query.project = @project
413 412 if params[:fields] and params[:fields].is_a? Array
414 413 params[:fields].each do |field|
415 414 @query.add_filter(field, params[:operators][field], params[:values][field])
416 415 end
417 416 else
418 417 @query.available_filters.keys.each do |field|
419 418 @query.add_short_filter(field, params[field]) if params[field]
420 419 end
421 420 end
422 421 session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
423 422 else
424 423 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
425 424 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
426 425 @query.project = @project
427 426 end
428 427 end
429 428 end
430 429 end
@@ -1,41 +1,40
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 JournalsController < ApplicationController
19 layout 'base'
20 19 before_filter :find_journal
21 20
22 21 def edit
23 22 if request.post?
24 23 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
25 24 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
26 25 respond_to do |format|
27 26 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
28 27 format.js { render :action => 'update' }
29 28 end
30 29 end
31 30 end
32 31
33 32 private
34 33 def find_journal
35 34 @journal = Journal.find(params[:id])
36 35 render_403 and return false unless @journal.editable_by?(User.current)
37 36 @project = @journal.journalized.project
38 37 rescue ActiveRecord::RecordNotFound
39 38 render_404
40 39 end
41 40 end
@@ -1,62 +1,61
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 MembersController < ApplicationController
19 layout 'base'
20 19 before_filter :find_member, :except => :new
21 20 before_filter :find_project, :only => :new
22 21 before_filter :authorize
23 22
24 23 def new
25 24 @project.members << Member.new(params[:member]) if request.post?
26 25 respond_to do |format|
27 26 format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
28 27 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
29 28 end
30 29 end
31 30
32 31 def edit
33 32 if request.post? and @member.update_attributes(params[:member])
34 33 respond_to do |format|
35 34 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
36 35 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
37 36 end
38 37 end
39 38 end
40 39
41 40 def destroy
42 41 @member.destroy
43 42 respond_to do |format|
44 43 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
45 44 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
46 45 end
47 46 end
48 47
49 48 private
50 49 def find_project
51 50 @project = Project.find(params[:id])
52 51 rescue ActiveRecord::RecordNotFound
53 52 render_404
54 53 end
55 54
56 55 def find_member
57 56 @member = Member.find(params[:id])
58 57 @project = @member.project
59 58 rescue ActiveRecord::RecordNotFound
60 59 render_404
61 60 end
62 61 end
@@ -1,108 +1,107
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 layout 'base'
20 19 menu_item :boards
21 20 before_filter :find_board, :only => [:new, :preview]
22 21 before_filter :find_message, :except => [:new, :preview]
23 22 before_filter :authorize, :except => :preview
24 23
25 24 verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
26 25
27 26 helper :attachments
28 27 include AttachmentsHelper
29 28
30 29 # Show a topic and its replies
31 30 def show
32 31 @replies = @topic.children
33 32 @replies.reverse! if User.current.wants_comments_in_reverse_order?
34 33 @reply = Message.new(:subject => "RE: #{@message.subject}")
35 34 render :action => "show", :layout => false if request.xhr?
36 35 end
37 36
38 37 # Create a new topic
39 38 def new
40 39 @message = Message.new(params[:message])
41 40 @message.author = User.current
42 41 @message.board = @board
43 42 if params[:message] && User.current.allowed_to?(:edit_messages, @project)
44 43 @message.locked = params[:message]['locked']
45 44 @message.sticky = params[:message]['sticky']
46 45 end
47 46 if request.post? && @message.save
48 47 attach_files(@message, params[:attachments])
49 48 redirect_to :action => 'show', :id => @message
50 49 end
51 50 end
52 51
53 52 # Reply to a topic
54 53 def reply
55 54 @reply = Message.new(params[:reply])
56 55 @reply.author = User.current
57 56 @reply.board = @board
58 57 @topic.children << @reply
59 58 if !@reply.new_record?
60 59 attach_files(@reply, params[:attachments])
61 60 end
62 61 redirect_to :action => 'show', :id => @topic
63 62 end
64 63
65 64 # Edit a message
66 65 def edit
67 66 if params[:message] && User.current.allowed_to?(:edit_messages, @project)
68 67 @message.locked = params[:message]['locked']
69 68 @message.sticky = params[:message]['sticky']
70 69 end
71 70 if request.post? && @message.update_attributes(params[:message])
72 71 attach_files(@message, params[:attachments])
73 72 flash[:notice] = l(:notice_successful_update)
74 73 redirect_to :action => 'show', :id => @topic
75 74 end
76 75 end
77 76
78 77 # Delete a messages
79 78 def destroy
80 79 @message.destroy
81 80 redirect_to @message.parent.nil? ?
82 81 { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } :
83 82 { :action => 'show', :id => @message.parent }
84 83 end
85 84
86 85 def preview
87 86 message = @board.messages.find_by_id(params[:id])
88 87 @attachements = message.attachments if message
89 88 @text = (params[:message] || params[:reply])[:content]
90 89 render :partial => 'common/preview'
91 90 end
92 91
93 92 private
94 93 def find_message
95 94 find_board
96 95 @message = @board.messages.find(params[:id], :include => :parent)
97 96 @topic = @message.root
98 97 rescue ActiveRecord::RecordNotFound
99 98 render_404
100 99 end
101 100
102 101 def find_board
103 102 @board = Board.find(params[:board_id], :include => :project)
104 103 @project = @board.project
105 104 rescue ActiveRecord::RecordNotFound
106 105 render_404
107 106 end
108 107 end
@@ -1,161 +1,160
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 MyController < ApplicationController
19 helper :issues
20
21 layout 'base'
22 19 before_filter :require_login
23 20
21 helper :issues
22
24 23 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 24 'issuesreportedbyme' => :label_reported_issues,
26 25 'issueswatched' => :label_watched_issues,
27 26 'news' => :label_news_latest,
28 27 'calendar' => :label_calendar,
29 28 'documents' => :label_document_plural,
30 29 'timelog' => :label_spent_time
31 30 }.freeze
32 31
33 32 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
34 33 'right' => ['issuesreportedbyme']
35 34 }.freeze
36 35
37 36 verify :xhr => true,
38 37 :session => :page_layout,
39 38 :only => [:add_block, :remove_block, :order_blocks]
40 39
41 40 def index
42 41 page
43 42 render :action => 'page'
44 43 end
45 44
46 45 # Show user's page
47 46 def page
48 47 @user = User.current
49 48 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
50 49 end
51 50
52 51 # Edit user's account
53 52 def account
54 53 @user = User.current
55 54 @pref = @user.pref
56 55 if request.post?
57 56 @user.attributes = params[:user]
58 57 @user.mail_notification = (params[:notification_option] == 'all')
59 58 @user.pref.attributes = params[:pref]
60 59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
61 60 if @user.save
62 61 @user.pref.save
63 62 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
64 63 set_language_if_valid @user.language
65 64 flash[:notice] = l(:notice_account_updated)
66 65 redirect_to :action => 'account'
67 66 return
68 67 end
69 68 end
70 69 @notification_options = [[l(:label_user_mail_option_all), 'all'],
71 70 [l(:label_user_mail_option_none), 'none']]
72 71 # Only users that belong to more than 1 project can select projects for which they are notified
73 72 # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
74 73 @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
75 74 @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
76 75 end
77 76
78 77 # Manage user's password
79 78 def password
80 79 @user = User.current
81 80 flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
82 81 if request.post?
83 82 if @user.check_password?(params[:password])
84 83 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
85 84 if @user.save
86 85 flash[:notice] = l(:notice_account_password_updated)
87 86 redirect_to :action => 'account'
88 87 end
89 88 else
90 89 flash[:error] = l(:notice_account_wrong_password)
91 90 end
92 91 end
93 92 end
94 93
95 94 # Create a new feeds key
96 95 def reset_rss_key
97 96 if request.post? && User.current.rss_token
98 97 User.current.rss_token.destroy
99 98 flash[:notice] = l(:notice_feeds_access_key_reseted)
100 99 end
101 100 redirect_to :action => 'account'
102 101 end
103 102
104 103 # User's page layout configuration
105 104 def page_layout
106 105 @user = User.current
107 106 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
108 107 session[:page_layout] = @blocks
109 108 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
110 109 @block_options = []
111 110 BLOCKS.each {|k, v| @block_options << [l(v), k]}
112 111 end
113 112
114 113 # Add a block to user's page
115 114 # The block is added on top of the page
116 115 # params[:block] : id of the block to add
117 116 def add_block
118 117 block = params[:block]
119 118 render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
120 119 @user = User.current
121 120 # remove if already present in a group
122 121 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
123 122 # add it on top
124 123 session[:page_layout]['top'].unshift block
125 124 render :partial => "block", :locals => {:user => @user, :block_name => block}
126 125 end
127 126
128 127 # Remove a block to user's page
129 128 # params[:block] : id of the block to remove
130 129 def remove_block
131 130 block = params[:block]
132 131 # remove block in all groups
133 132 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
134 133 render :nothing => true
135 134 end
136 135
137 136 # Change blocks order on user's page
138 137 # params[:group] : group to order (top, left or right)
139 138 # params[:list-(top|left|right)] : array of block ids of the group
140 139 def order_blocks
141 140 group = params[:group]
142 141 group_items = params["list-#{group}"]
143 142 if group_items and group_items.is_a? Array
144 143 # remove group blocks if they are presents in other groups
145 144 %w(top left right).each {|f|
146 145 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
147 146 }
148 147 session[:page_layout][group] = group_items
149 148 end
150 149 render :nothing => true
151 150 end
152 151
153 152 # Save user's page layout
154 153 def page_layout_save
155 154 @user = User.current
156 155 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
157 156 @user.pref.save
158 157 session[:page_layout] = nil
159 158 redirect_to :action => 'page'
160 159 end
161 160 end
@@ -1,109 +1,108
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 NewsController < ApplicationController
19 layout 'base'
20 19 before_filter :find_news, :except => [:new, :index, :preview]
21 20 before_filter :find_project, :only => [:new, :preview]
22 21 before_filter :authorize, :except => [:index, :preview]
23 22 before_filter :find_optional_project, :only => :index
24 23 accept_key_auth :index
25 24
26 25 def index
27 26 @news_pages, @newss = paginate :news,
28 27 :per_page => 10,
29 28 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
30 29 :include => [:author, :project],
31 30 :order => "#{News.table_name}.created_on DESC"
32 31 respond_to do |format|
33 32 format.html { render :layout => false if request.xhr? }
34 33 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
35 34 end
36 35 end
37 36
38 37 def show
39 38 @comments = @news.comments
40 39 @comments.reverse! if User.current.wants_comments_in_reverse_order?
41 40 end
42 41
43 42 def new
44 43 @news = News.new(:project => @project, :author => User.current)
45 44 if request.post?
46 45 @news.attributes = params[:news]
47 46 if @news.save
48 47 flash[:notice] = l(:notice_successful_create)
49 48 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
50 49 redirect_to :controller => 'news', :action => 'index', :project_id => @project
51 50 end
52 51 end
53 52 end
54 53
55 54 def edit
56 55 if request.post? and @news.update_attributes(params[:news])
57 56 flash[:notice] = l(:notice_successful_update)
58 57 redirect_to :action => 'show', :id => @news
59 58 end
60 59 end
61 60
62 61 def add_comment
63 62 @comment = Comment.new(params[:comment])
64 63 @comment.author = User.current
65 64 if @news.comments << @comment
66 65 flash[:notice] = l(:label_comment_added)
67 66 redirect_to :action => 'show', :id => @news
68 67 else
69 68 render :action => 'show'
70 69 end
71 70 end
72 71
73 72 def destroy_comment
74 73 @news.comments.find(params[:comment_id]).destroy
75 74 redirect_to :action => 'show', :id => @news
76 75 end
77 76
78 77 def destroy
79 78 @news.destroy
80 79 redirect_to :action => 'index', :project_id => @project
81 80 end
82 81
83 82 def preview
84 83 @text = (params[:news] ? params[:news][:description] : nil)
85 84 render :partial => 'common/preview'
86 85 end
87 86
88 87 private
89 88 def find_news
90 89 @news = News.find(params[:id])
91 90 @project = @news.project
92 91 rescue ActiveRecord::RecordNotFound
93 92 render_404
94 93 end
95 94
96 95 def find_project
97 96 @project = Project.find(params[:project_id])
98 97 rescue ActiveRecord::RecordNotFound
99 98 render_404
100 99 end
101 100
102 101 def find_optional_project
103 102 return true unless params[:project_id]
104 103 @project = Project.find(params[:project_id])
105 104 authorize
106 105 rescue ActiveRecord::RecordNotFound
107 106 render_404
108 107 end
109 108 end
@@ -1,365 +1,364
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 layout 'base'
20 19 menu_item :overview
21 20 menu_item :activity, :only => :activity
22 21 menu_item :roadmap, :only => :roadmap
23 22 menu_item :files, :only => [:list_files, :add_file]
24 23 menu_item :settings, :only => :settings
25 24 menu_item :issues, :only => [:changelog]
26 25
27 26 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 27 before_filter :find_optional_project, :only => :activity
29 28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 30 accept_key_auth :activity, :calendar
32 31
33 32 helper :sort
34 33 include SortHelper
35 34 helper :custom_fields
36 35 include CustomFieldsHelper
37 36 helper :ifpdf
38 37 include IfpdfHelper
39 38 helper :issues
40 39 helper IssuesHelper
41 40 helper :queries
42 41 include QueriesHelper
43 42 helper :repositories
44 43 include RepositoriesHelper
45 44 include ProjectsHelper
46 45
47 46 # Lists visible projects
48 47 def index
49 48 projects = Project.find :all,
50 49 :conditions => Project.visible_by(User.current),
51 50 :include => :parent
52 51 respond_to do |format|
53 52 format.html {
54 53 @project_tree = projects.group_by {|p| p.parent || p}
55 54 @project_tree.keys.each {|p| @project_tree[p] -= [p]}
56 55 }
57 56 format.atom {
58 57 render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
59 58 :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 59 }
61 60 end
62 61 end
63 62
64 63 # Add a new project
65 64 def add
66 65 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 66 @trackers = Tracker.all
68 67 @root_projects = Project.find(:all,
69 68 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
70 69 :order => 'name')
71 70 @project = Project.new(params[:project])
72 71 if request.get?
73 72 @project.trackers = Tracker.all
74 73 @project.is_public = Setting.default_projects_public?
75 74 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
76 75 else
77 76 @project.enabled_module_names = params[:enabled_modules]
78 77 if @project.save
79 78 flash[:notice] = l(:notice_successful_create)
80 79 redirect_to :controller => 'admin', :action => 'projects'
81 80 end
82 81 end
83 82 end
84 83
85 84 # Show @project
86 85 def show
87 86 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 87 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
89 88 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
90 89 @trackers = @project.rolled_up_trackers
91 90
92 91 cond = @project.project_condition(Setting.display_subprojects_issues?)
93 92 Issue.visible_by(User.current) do
94 93 @open_issues_by_tracker = Issue.count(:group => :tracker,
95 94 :include => [:project, :status, :tracker],
96 95 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
97 96 @total_issues_by_tracker = Issue.count(:group => :tracker,
98 97 :include => [:project, :status, :tracker],
99 98 :conditions => cond)
100 99 end
101 100 TimeEntry.visible_by(User.current) do
102 101 @total_hours = TimeEntry.sum(:hours,
103 102 :include => :project,
104 103 :conditions => cond).to_f
105 104 end
106 105 @key = User.current.rss_key
107 106 end
108 107
109 108 def settings
110 109 @root_projects = Project.find(:all,
111 110 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
112 111 :order => 'name')
113 112 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
114 113 @issue_category ||= IssueCategory.new
115 114 @member ||= @project.members.new
116 115 @trackers = Tracker.all
117 116 @repository ||= @project.repository
118 117 @wiki ||= @project.wiki
119 118 end
120 119
121 120 # Edit @project
122 121 def edit
123 122 if request.post?
124 123 @project.attributes = params[:project]
125 124 if @project.save
126 125 flash[:notice] = l(:notice_successful_update)
127 126 redirect_to :action => 'settings', :id => @project
128 127 else
129 128 settings
130 129 render :action => 'settings'
131 130 end
132 131 end
133 132 end
134 133
135 134 def modules
136 135 @project.enabled_module_names = params[:enabled_modules]
137 136 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
138 137 end
139 138
140 139 def archive
141 140 @project.archive if request.post? && @project.active?
142 141 redirect_to :controller => 'admin', :action => 'projects'
143 142 end
144 143
145 144 def unarchive
146 145 @project.unarchive if request.post? && !@project.active?
147 146 redirect_to :controller => 'admin', :action => 'projects'
148 147 end
149 148
150 149 # Delete @project
151 150 def destroy
152 151 @project_to_destroy = @project
153 152 if request.post? and params[:confirm]
154 153 @project_to_destroy.destroy
155 154 redirect_to :controller => 'admin', :action => 'projects'
156 155 end
157 156 # hide project in layout
158 157 @project = nil
159 158 end
160 159
161 160 # Add a new issue category to @project
162 161 def add_issue_category
163 162 @category = @project.issue_categories.build(params[:category])
164 163 if request.post? and @category.save
165 164 respond_to do |format|
166 165 format.html do
167 166 flash[:notice] = l(:notice_successful_create)
168 167 redirect_to :action => 'settings', :tab => 'categories', :id => @project
169 168 end
170 169 format.js do
171 170 # IE doesn't support the replace_html rjs method for select box options
172 171 render(:update) {|page| page.replace "issue_category_id",
173 172 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]')
174 173 }
175 174 end
176 175 end
177 176 end
178 177 end
179 178
180 179 # Add a new version to @project
181 180 def add_version
182 181 @version = @project.versions.build(params[:version])
183 182 if request.post? and @version.save
184 183 flash[:notice] = l(:notice_successful_create)
185 184 redirect_to :action => 'settings', :tab => 'versions', :id => @project
186 185 end
187 186 end
188 187
189 188 def add_file
190 189 if request.post?
191 190 @version = @project.versions.find_by_id(params[:version_id])
192 191 attachments = attach_files(@version, params[:attachments])
193 192 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
194 193 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
195 194 end
196 195 @versions = @project.versions.sort
197 196 end
198 197
199 198 def list_files
200 199 sort_init "#{Attachment.table_name}.filename", "asc"
201 200 sort_update
202 201 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
203 202 render :layout => !request.xhr?
204 203 end
205 204
206 205 # Show changelog for @project
207 206 def changelog
208 207 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
209 208 retrieve_selected_tracker_ids(@trackers)
210 209 @versions = @project.versions.sort
211 210 end
212 211
213 212 def roadmap
214 213 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
215 214 retrieve_selected_tracker_ids(@trackers)
216 215 @versions = @project.versions.sort
217 216 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
218 217 end
219 218
220 219 def activity
221 220 @days = Setting.activity_days_default.to_i
222 221
223 222 if params[:from]
224 223 begin; @date_to = params[:from].to_date; rescue; end
225 224 end
226 225
227 226 @date_to ||= Date.today + 1
228 227 @date_from = @date_to - @days
229 228 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
230 229
231 230 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
232 231 @activity.scope_select {|t| !params["show_#{t}"].nil?}
233 232 @activity.default_scope! if @activity.scope.empty?
234 233
235 234 events = @activity.events(@date_from, @date_to)
236 235
237 236 respond_to do |format|
238 237 format.html {
239 238 @events_by_day = events.group_by(&:event_date)
240 239 render :layout => false if request.xhr?
241 240 }
242 241 format.atom {
243 242 title = (@activity.scope.size == 1) ? l("label_#{@activity.scope.first.singularize}_plural") : l(:label_activity)
244 243 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
245 244 }
246 245 end
247 246 end
248 247
249 248 def calendar
250 249 @trackers = @project.rolled_up_trackers
251 250 retrieve_selected_tracker_ids(@trackers)
252 251
253 252 if params[:year] and params[:year].to_i > 1900
254 253 @year = params[:year].to_i
255 254 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
256 255 @month = params[:month].to_i
257 256 end
258 257 end
259 258 @year ||= Date.today.year
260 259 @month ||= Date.today.month
261 260 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
262 261 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
263 262 events = []
264 263 @project.issues_with_subprojects(@with_subprojects) do
265 264 events += Issue.find(:all,
266 265 :include => [:tracker, :status, :assigned_to, :priority, :project],
267 266 :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]
268 267 ) unless @selected_tracker_ids.empty?
269 268 events += Version.find(:all, :include => :project,
270 269 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
271 270 end
272 271 @calendar.events = events
273 272
274 273 render :layout => false if request.xhr?
275 274 end
276 275
277 276 def gantt
278 277 @trackers = @project.rolled_up_trackers
279 278 retrieve_selected_tracker_ids(@trackers)
280 279
281 280 if params[:year] and params[:year].to_i >0
282 281 @year_from = params[:year].to_i
283 282 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
284 283 @month_from = params[:month].to_i
285 284 else
286 285 @month_from = 1
287 286 end
288 287 else
289 288 @month_from ||= Date.today.month
290 289 @year_from ||= Date.today.year
291 290 end
292 291
293 292 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
294 293 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
295 294 months = (params[:months] || User.current.pref[:gantt_months]).to_i
296 295 @months = (months > 0 && months < 25) ? months : 6
297 296
298 297 # Save gantt paramters as user preference (zoom and months count)
299 298 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
300 299 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
301 300 User.current.preference.save
302 301 end
303 302
304 303 @date_from = Date.civil(@year_from, @month_from, 1)
305 304 @date_to = (@date_from >> @months) - 1
306 305 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
307 306
308 307 @events = []
309 308 @project.issues_with_subprojects(@with_subprojects) do
310 309 # Issues that have start and due dates
311 310 @events += Issue.find(:all,
312 311 :order => "start_date, due_date",
313 312 :include => [:tracker, :status, :assigned_to, :priority, :project],
314 313 :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]
315 314 ) unless @selected_tracker_ids.empty?
316 315 # Issues that don't have a due date but that are assigned to a version with a date
317 316 @events += Issue.find(:all,
318 317 :order => "start_date, effective_date",
319 318 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
320 319 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_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]
321 320 ) unless @selected_tracker_ids.empty?
322 321 @events += Version.find(:all, :include => :project,
323 322 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
324 323 end
325 324 @events.sort! {|x,y| x.start_date <=> y.start_date }
326 325
327 326 if params[:format]=='pdf'
328 327 @options_for_rfpdf ||= {}
329 328 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
330 329 render :template => "projects/gantt.rfpdf", :layout => false
331 330 elsif params[:format]=='png' && respond_to?('gantt_image')
332 331 image = gantt_image(@events, @date_from, @months, @zoom)
333 332 image.format = 'PNG'
334 333 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
335 334 else
336 335 render :template => "projects/gantt.rhtml"
337 336 end
338 337 end
339 338
340 339 private
341 340 # Find project of id params[:id]
342 341 # if not found, redirect to project list
343 342 # Used as a before_filter
344 343 def find_project
345 344 @project = Project.find(params[:id])
346 345 rescue ActiveRecord::RecordNotFound
347 346 render_404
348 347 end
349 348
350 349 def find_optional_project
351 350 return true unless params[:id]
352 351 @project = Project.find(params[:id])
353 352 authorize
354 353 rescue ActiveRecord::RecordNotFound
355 354 render_404
356 355 end
357 356
358 357 def retrieve_selected_tracker_ids(selectable_trackers)
359 358 if ids = params[:tracker_ids]
360 359 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
361 360 else
362 361 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
363 362 end
364 363 end
365 364 end
@@ -1,81 +1,80
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 QueriesController < ApplicationController
19 layout 'base'
20 19 menu_item :issues
21 20 before_filter :find_query, :except => :new
22 21 before_filter :find_optional_project, :only => :new
23 22
24 23 def new
25 24 @query = Query.new(params[:query])
26 25 @query.project = params[:query_is_for_all] ? nil : @project
27 26 @query.user = User.current
28 27 @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
29 28 @query.column_names = nil if params[:default_columns]
30 29
31 30 params[:fields].each do |field|
32 31 @query.add_filter(field, params[:operators][field], params[:values][field])
33 32 end if params[:fields]
34 33
35 34 if request.post? && params[:confirm] && @query.save
36 35 flash[:notice] = l(:notice_successful_create)
37 36 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
38 37 return
39 38 end
40 39 render :layout => false if request.xhr?
41 40 end
42 41
43 42 def edit
44 43 if request.post?
45 44 @query.filters = {}
46 45 params[:fields].each do |field|
47 46 @query.add_filter(field, params[:operators][field], params[:values][field])
48 47 end if params[:fields]
49 48 @query.attributes = params[:query]
50 49 @query.project = nil if params[:query_is_for_all]
51 50 @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin?
52 51 @query.column_names = nil if params[:default_columns]
53 52
54 53 if @query.save
55 54 flash[:notice] = l(:notice_successful_update)
56 55 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
57 56 end
58 57 end
59 58 end
60 59
61 60 def destroy
62 61 @query.destroy if request.post?
63 62 redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1
64 63 end
65 64
66 65 private
67 66 def find_query
68 67 @query = Query.find(params[:id])
69 68 @project = @query.project
70 69 render_403 unless @query.editable_by?(User.current)
71 70 rescue ActiveRecord::RecordNotFound
72 71 render_404
73 72 end
74 73
75 74 def find_optional_project
76 75 @project = Project.find(params[:project_id]) if params[:project_id]
77 76 User.current.allowed_to?(:save_queries, @project, :global => true)
78 77 rescue ActiveRecord::RecordNotFound
79 78 render_404
80 79 end
81 80 end
@@ -1,237 +1,236
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 ReportsController < ApplicationController
19 layout 'base'
20 19 menu_item :issues
21 20 before_filter :find_project, :authorize
22 21
23 22 def issue_report
24 23 @statuses = IssueStatus.find(:all, :order => 'position')
25 24
26 25 case params[:detail]
27 26 when "tracker"
28 27 @field = "tracker_id"
29 28 @rows = @project.trackers
30 29 @data = issues_by_tracker
31 30 @report_title = l(:field_tracker)
32 31 render :template => "reports/issue_report_details"
33 32 when "version"
34 33 @field = "fixed_version_id"
35 34 @rows = @project.versions.sort
36 35 @data = issues_by_version
37 36 @report_title = l(:field_version)
38 37 render :template => "reports/issue_report_details"
39 38 when "priority"
40 39 @field = "priority_id"
41 40 @rows = Enumeration::get_values('IPRI')
42 41 @data = issues_by_priority
43 42 @report_title = l(:field_priority)
44 43 render :template => "reports/issue_report_details"
45 44 when "category"
46 45 @field = "category_id"
47 46 @rows = @project.issue_categories
48 47 @data = issues_by_category
49 48 @report_title = l(:field_category)
50 49 render :template => "reports/issue_report_details"
51 50 when "assigned_to"
52 51 @field = "assigned_to_id"
53 52 @rows = @project.members.collect { |m| m.user }
54 53 @data = issues_by_assigned_to
55 54 @report_title = l(:field_assigned_to)
56 55 render :template => "reports/issue_report_details"
57 56 when "author"
58 57 @field = "author_id"
59 58 @rows = @project.members.collect { |m| m.user }
60 59 @data = issues_by_author
61 60 @report_title = l(:field_author)
62 61 render :template => "reports/issue_report_details"
63 62 when "subproject"
64 63 @field = "project_id"
65 64 @rows = @project.active_children
66 65 @data = issues_by_subproject
67 66 @report_title = l(:field_subproject)
68 67 render :template => "reports/issue_report_details"
69 68 else
70 69 @trackers = @project.trackers
71 70 @versions = @project.versions.sort
72 71 @priorities = Enumeration::get_values('IPRI')
73 72 @categories = @project.issue_categories
74 73 @assignees = @project.members.collect { |m| m.user }
75 74 @authors = @project.members.collect { |m| m.user }
76 75 @subprojects = @project.active_children
77 76 issues_by_tracker
78 77 issues_by_version
79 78 issues_by_priority
80 79 issues_by_category
81 80 issues_by_assigned_to
82 81 issues_by_author
83 82 issues_by_subproject
84 83
85 84 render :template => "reports/issue_report"
86 85 end
87 86 end
88 87
89 88 def delays
90 89 @trackers = Tracker.find(:all)
91 90 if request.get?
92 91 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
93 92 else
94 93 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
95 94 end
96 95 @selected_tracker_ids ||= []
97 96 @raw =
98 97 ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
99 98 FROM issue_histories a, issue_histories b, issues i
100 99 WHERE a.status_id =5
101 100 AND a.issue_id = b.issue_id
102 101 AND a.issue_id = i.id
103 102 AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
104 103 AND b.id = (
105 104 SELECT min( c.id )
106 105 FROM issue_histories c
107 106 WHERE b.issue_id = c.issue_id )
108 107 GROUP BY delay") unless @selected_tracker_ids.empty?
109 108 @raw ||=[]
110 109
111 110 @x_from = 0
112 111 @x_to = 0
113 112 @y_from = 0
114 113 @y_to = 0
115 114 @sum_total = 0
116 115 @sum_delay = 0
117 116 @raw.each do |r|
118 117 @x_to = [r['delay'].to_i, @x_to].max
119 118 @y_to = [r['total'].to_i, @y_to].max
120 119 @sum_total = @sum_total + r['total'].to_i
121 120 @sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
122 121 end
123 122 end
124 123
125 124 private
126 125 # Find project of id params[:id]
127 126 def find_project
128 127 @project = Project.find(params[:id])
129 128 rescue ActiveRecord::RecordNotFound
130 129 render_404
131 130 end
132 131
133 132 def issues_by_tracker
134 133 @issues_by_tracker ||=
135 134 ActiveRecord::Base.connection.select_all("select s.id as status_id,
136 135 s.is_closed as closed,
137 136 t.id as tracker_id,
138 137 count(i.id) as total
139 138 from
140 139 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
141 140 where
142 141 i.status_id=s.id
143 142 and i.tracker_id=t.id
144 143 and i.project_id=#{@project.id}
145 144 group by s.id, s.is_closed, t.id")
146 145 end
147 146
148 147 def issues_by_version
149 148 @issues_by_version ||=
150 149 ActiveRecord::Base.connection.select_all("select s.id as status_id,
151 150 s.is_closed as closed,
152 151 v.id as fixed_version_id,
153 152 count(i.id) as total
154 153 from
155 154 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Version.table_name} v
156 155 where
157 156 i.status_id=s.id
158 157 and i.fixed_version_id=v.id
159 158 and i.project_id=#{@project.id}
160 159 group by s.id, s.is_closed, v.id")
161 160 end
162 161
163 162 def issues_by_priority
164 163 @issues_by_priority ||=
165 164 ActiveRecord::Base.connection.select_all("select s.id as status_id,
166 165 s.is_closed as closed,
167 166 p.id as priority_id,
168 167 count(i.id) as total
169 168 from
170 169 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
171 170 where
172 171 i.status_id=s.id
173 172 and i.priority_id=p.id
174 173 and i.project_id=#{@project.id}
175 174 group by s.id, s.is_closed, p.id")
176 175 end
177 176
178 177 def issues_by_category
179 178 @issues_by_category ||=
180 179 ActiveRecord::Base.connection.select_all("select s.id as status_id,
181 180 s.is_closed as closed,
182 181 c.id as category_id,
183 182 count(i.id) as total
184 183 from
185 184 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssueCategory.table_name} c
186 185 where
187 186 i.status_id=s.id
188 187 and i.category_id=c.id
189 188 and i.project_id=#{@project.id}
190 189 group by s.id, s.is_closed, c.id")
191 190 end
192 191
193 192 def issues_by_assigned_to
194 193 @issues_by_assigned_to ||=
195 194 ActiveRecord::Base.connection.select_all("select s.id as status_id,
196 195 s.is_closed as closed,
197 196 a.id as assigned_to_id,
198 197 count(i.id) as total
199 198 from
200 199 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
201 200 where
202 201 i.status_id=s.id
203 202 and i.assigned_to_id=a.id
204 203 and i.project_id=#{@project.id}
205 204 group by s.id, s.is_closed, a.id")
206 205 end
207 206
208 207 def issues_by_author
209 208 @issues_by_author ||=
210 209 ActiveRecord::Base.connection.select_all("select s.id as status_id,
211 210 s.is_closed as closed,
212 211 a.id as author_id,
213 212 count(i.id) as total
214 213 from
215 214 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
216 215 where
217 216 i.status_id=s.id
218 217 and i.author_id=a.id
219 218 and i.project_id=#{@project.id}
220 219 group by s.id, s.is_closed, a.id")
221 220 end
222 221
223 222 def issues_by_subproject
224 223 @issues_by_subproject ||=
225 224 ActiveRecord::Base.connection.select_all("select s.id as status_id,
226 225 s.is_closed as closed,
227 226 i.project_id as project_id,
228 227 count(i.id) as total
229 228 from
230 229 #{Issue.table_name} i, #{IssueStatus.table_name} s
231 230 where
232 231 i.status_id=s.id
233 232 and i.project_id IN (#{@project.active_children.collect{|p| p.id}.join(',')})
234 233 group by s.id, s.is_closed, i.project_id") if @project.active_children.any?
235 234 @issues_by_subproject ||= []
236 235 end
237 236 end
@@ -1,315 +1,314
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 'SVG/Graph/Bar'
19 19 require 'SVG/Graph/BarHorizontal'
20 20 require 'digest/sha1'
21 21
22 22 class ChangesetNotFound < Exception; end
23 23 class InvalidRevisionParam < Exception; end
24 24
25 25 class RepositoriesController < ApplicationController
26 layout 'base'
27 26 menu_item :repository
28 27 before_filter :find_repository, :except => :edit
29 28 before_filter :find_project, :only => :edit
30 29 before_filter :authorize
31 30 accept_key_auth :revisions
32 31
33 32 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
34 33
35 34 def edit
36 35 @repository = @project.repository
37 36 if !@repository
38 37 @repository = Repository.factory(params[:repository_scm])
39 38 @repository.project = @project if @repository
40 39 end
41 40 if request.post? && @repository
42 41 @repository.attributes = params[:repository]
43 42 @repository.save
44 43 end
45 44 render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
46 45 end
47 46
48 47 def destroy
49 48 @repository.destroy
50 49 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
51 50 end
52 51
53 52 def show
54 53 # check if new revisions have been committed in the repository
55 54 @repository.fetch_changesets if Setting.autofetch_changesets?
56 55 # root entries
57 56 @entries = @repository.entries('', @rev)
58 57 # latest changesets
59 58 @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
60 59 show_error_not_found unless @entries || @changesets.any?
61 60 end
62 61
63 62 def browse
64 63 @entries = @repository.entries(@path, @rev)
65 64 if request.xhr?
66 65 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
67 66 else
68 67 show_error_not_found and return unless @entries
69 68 @properties = @repository.properties(@path, @rev)
70 69 render :action => 'browse'
71 70 end
72 71 end
73 72
74 73 def changes
75 74 @entry = @repository.entry(@path, @rev)
76 75 show_error_not_found and return unless @entry
77 76 @changesets = @repository.changesets_for_path(@path)
78 77 @properties = @repository.properties(@path, @rev)
79 78 end
80 79
81 80 def revisions
82 81 @changeset_count = @repository.changesets.count
83 82 @changeset_pages = Paginator.new self, @changeset_count,
84 83 per_page_option,
85 84 params['page']
86 85 @changesets = @repository.changesets.find(:all,
87 86 :limit => @changeset_pages.items_per_page,
88 87 :offset => @changeset_pages.current.offset)
89 88
90 89 respond_to do |format|
91 90 format.html { render :layout => false if request.xhr? }
92 91 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
93 92 end
94 93 end
95 94
96 95 def entry
97 96 @entry = @repository.entry(@path, @rev)
98 97 show_error_not_found and return unless @entry
99 98
100 99 # If the entry is a dir, show the browser
101 100 browse and return if @entry.is_dir?
102 101
103 102 @content = @repository.cat(@path, @rev)
104 103 show_error_not_found and return unless @content
105 104 if 'raw' == params[:format] || @content.is_binary_data?
106 105 # Force the download if it's a binary file
107 106 send_data @content, :filename => @path.split('/').last
108 107 else
109 108 # Prevent empty lines when displaying a file with Windows style eol
110 109 @content.gsub!("\r\n", "\n")
111 110 end
112 111 end
113 112
114 113 def annotate
115 114 @annotate = @repository.scm.annotate(@path, @rev)
116 115 render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty?
117 116 end
118 117
119 118 def revision
120 119 @changeset = @repository.changesets.find_by_revision(@rev)
121 120 raise ChangesetNotFound unless @changeset
122 121 @changes_count = @changeset.changes.size
123 122 @changes_pages = Paginator.new self, @changes_count, 150, params['page']
124 123 @changes = @changeset.changes.find(:all,
125 124 :limit => @changes_pages.items_per_page,
126 125 :offset => @changes_pages.current.offset)
127 126
128 127 respond_to do |format|
129 128 format.html
130 129 format.js {render :layout => false}
131 130 end
132 131 rescue ChangesetNotFound
133 132 show_error_not_found
134 133 end
135 134
136 135 def diff
137 136 if params[:format] == 'diff'
138 137 @diff = @repository.diff(@path, @rev, @rev_to)
139 138 show_error_not_found and return unless @diff
140 139 filename = "changeset_r#{@rev}"
141 140 filename << "_r#{@rev_to}" if @rev_to
142 141 send_data @diff.join, :filename => "#{filename}.diff",
143 142 :type => 'text/x-patch',
144 143 :disposition => 'attachment'
145 144 else
146 145 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
147 146 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
148 147
149 148 # Save diff type as user preference
150 149 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
151 150 User.current.pref[:diff_type] = @diff_type
152 151 User.current.preference.save
153 152 end
154 153
155 154 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
156 155 unless read_fragment(@cache_key)
157 156 @diff = @repository.diff(@path, @rev, @rev_to)
158 157 show_error_not_found unless @diff
159 158 end
160 159 end
161 160 end
162 161
163 162 def stats
164 163 end
165 164
166 165 def graph
167 166 data = nil
168 167 case params[:graph]
169 168 when "commits_per_month"
170 169 data = graph_commits_per_month(@repository)
171 170 when "commits_per_author"
172 171 data = graph_commits_per_author(@repository)
173 172 end
174 173 if data
175 174 headers["Content-Type"] = "image/svg+xml"
176 175 send_data(data, :type => "image/svg+xml", :disposition => "inline")
177 176 else
178 177 render_404
179 178 end
180 179 end
181 180
182 181 private
183 182 def find_project
184 183 @project = Project.find(params[:id])
185 184 rescue ActiveRecord::RecordNotFound
186 185 render_404
187 186 end
188 187
189 188 REV_PARAM_RE = %r{^[a-f0-9]*$}
190 189
191 190 def find_repository
192 191 @project = Project.find(params[:id])
193 192 @repository = @project.repository
194 193 render_404 and return false unless @repository
195 194 @path = params[:path].join('/') unless params[:path].nil?
196 195 @path ||= ''
197 196 @rev = params[:rev]
198 197 @rev_to = params[:rev_to]
199 198 raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE)
200 199 rescue ActiveRecord::RecordNotFound
201 200 render_404
202 201 rescue InvalidRevisionParam
203 202 show_error_not_found
204 203 end
205 204
206 205 def show_error_not_found
207 206 render_error l(:error_scm_not_found)
208 207 end
209 208
210 209 # Handler for Redmine::Scm::Adapters::CommandFailed exception
211 210 def show_error_command_failed(exception)
212 211 render_error l(:error_scm_command_failed, exception.message)
213 212 end
214 213
215 214 def graph_commits_per_month(repository)
216 215 @date_to = Date.today
217 216 @date_from = @date_to << 11
218 217 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
219 218 commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
220 219 commits_by_month = [0] * 12
221 220 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
222 221
223 222 changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
224 223 changes_by_month = [0] * 12
225 224 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
226 225
227 226 fields = []
228 227 month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
229 228 12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
230 229
231 230 graph = SVG::Graph::Bar.new(
232 231 :height => 300,
233 232 :width => 800,
234 233 :fields => fields.reverse,
235 234 :stack => :side,
236 235 :scale_integers => true,
237 236 :step_x_labels => 2,
238 237 :show_data_values => false,
239 238 :graph_title => l(:label_commits_per_month),
240 239 :show_graph_title => true
241 240 )
242 241
243 242 graph.add_data(
244 243 :data => commits_by_month[0..11].reverse,
245 244 :title => l(:label_revision_plural)
246 245 )
247 246
248 247 graph.add_data(
249 248 :data => changes_by_month[0..11].reverse,
250 249 :title => l(:label_change_plural)
251 250 )
252 251
253 252 graph.burn
254 253 end
255 254
256 255 def graph_commits_per_author(repository)
257 256 commits_by_author = repository.changesets.count(:all, :group => :committer)
258 257 commits_by_author.sort! {|x, y| x.last <=> y.last}
259 258
260 259 changes_by_author = repository.changes.count(:all, :group => :committer)
261 260 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
262 261
263 262 fields = commits_by_author.collect {|r| r.first}
264 263 commits_data = commits_by_author.collect {|r| r.last}
265 264 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
266 265
267 266 fields = fields + [""]*(10 - fields.length) if fields.length<10
268 267 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
269 268 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
270 269
271 270 # Remove email adress in usernames
272 271 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
273 272
274 273 graph = SVG::Graph::BarHorizontal.new(
275 274 :height => 400,
276 275 :width => 800,
277 276 :fields => fields,
278 277 :stack => :side,
279 278 :scale_integers => true,
280 279 :show_data_values => false,
281 280 :rotate_y_labels => false,
282 281 :graph_title => l(:label_commits_per_author),
283 282 :show_graph_title => true
284 283 )
285 284
286 285 graph.add_data(
287 286 :data => commits_data,
288 287 :title => l(:label_revision_plural)
289 288 )
290 289
291 290 graph.add_data(
292 291 :data => changes_data,
293 292 :title => l(:label_change_plural)
294 293 )
295 294
296 295 graph.burn
297 296 end
298 297
299 298 end
300 299
301 300 class Date
302 301 def months_ago(date = Date.today)
303 302 (date.year - self.year)*12 + (date.month - self.month)
304 303 end
305 304
306 305 def weeks_ago(date = Date.today)
307 306 (date.year - self.year)*52 + (date.cweek - self.cweek)
308 307 end
309 308 end
310 309
311 310 class String
312 311 def with_leading_slash
313 312 starts_with?('/') ? self : "/#{self}"
314 313 end
315 314 end
@@ -1,116 +1,115
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 RolesController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 verify :method => :post, :only => [ :destroy, :move ],
23 22 :redirect_to => { :action => :list }
24 23
25 24 def index
26 25 list
27 26 render :action => 'list' unless request.xhr?
28 27 end
29 28
30 29 def list
31 30 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
32 31 render :action => "list", :layout => false if request.xhr?
33 32 end
34 33
35 34 def new
36 35 # Prefills the form with 'Non member' role permissions
37 36 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
38 37 if request.post? && @role.save
39 38 # workflow copy
40 39 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
41 40 @role.workflows.copy(copy_from)
42 41 end
43 42 flash[:notice] = l(:notice_successful_create)
44 43 redirect_to :action => 'list'
45 44 end
46 45 @permissions = @role.setable_permissions
47 46 @roles = Role.find :all, :order => 'builtin, position'
48 47 end
49 48
50 49 def edit
51 50 @role = Role.find(params[:id])
52 51 if request.post? and @role.update_attributes(params[:role])
53 52 flash[:notice] = l(:notice_successful_update)
54 53 redirect_to :action => 'list'
55 54 end
56 55 @permissions = @role.setable_permissions
57 56 end
58 57
59 58 def destroy
60 59 @role = Role.find(params[:id])
61 60 @role.destroy
62 61 redirect_to :action => 'list'
63 62 rescue
64 63 flash[:error] = 'This role is in use and can not be deleted.'
65 64 redirect_to :action => 'index'
66 65 end
67 66
68 67 def move
69 68 @role = Role.find(params[:id])
70 69 case params[:position]
71 70 when 'highest'
72 71 @role.move_to_top
73 72 when 'higher'
74 73 @role.move_higher
75 74 when 'lower'
76 75 @role.move_lower
77 76 when 'lowest'
78 77 @role.move_to_bottom
79 78 end if params[:position]
80 79 redirect_to :action => 'list'
81 80 end
82 81
83 82 def workflow
84 83 @role = Role.find_by_id(params[:role_id])
85 84 @tracker = Tracker.find_by_id(params[:tracker_id])
86 85
87 86 if request.post?
88 87 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
89 88 (params[:issue_status] || []).each { |old, news|
90 89 news.each { |new|
91 90 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
92 91 }
93 92 }
94 93 if @role.save
95 94 flash[:notice] = l(:notice_successful_update)
96 95 redirect_to :action => 'workflow', :role_id => @role, :tracker_id => @tracker
97 96 end
98 97 end
99 98 @roles = Role.find(:all, :order => 'builtin, position')
100 99 @trackers = Tracker.find(:all, :order => 'position')
101 100 @statuses = IssueStatus.find(:all, :order => 'position')
102 101 end
103 102
104 103 def report
105 104 @roles = Role.find(:all, :order => 'builtin, position')
106 105 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
107 106 if request.post?
108 107 @roles.each do |role|
109 108 role.permissions = params[:permissions][role.id.to_s]
110 109 role.save
111 110 end
112 111 flash[:notice] = l(:notice_successful_update)
113 112 redirect_to :action => 'list'
114 113 end
115 114 end
116 115 end
@@ -1,118 +1,116
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 SearchController < ApplicationController
19 layout 'base'
20
21 19 before_filter :find_optional_project
22 20
23 21 helper :messages
24 22 include MessagesHelper
25 23
26 24 def index
27 25 @question = params[:q] || ""
28 26 @question.strip!
29 27 @all_words = params[:all_words] || (params[:submit] ? false : true)
30 28 @titles_only = !params[:titles_only].nil?
31 29
32 30 projects_to_search =
33 31 case params[:scope]
34 32 when 'all'
35 33 nil
36 34 when 'my_projects'
37 35 User.current.memberships.collect(&:project)
38 36 when 'subprojects'
39 37 @project ? ([ @project ] + @project.active_children) : nil
40 38 else
41 39 @project
42 40 end
43 41
44 42 offset = nil
45 43 begin; offset = params[:offset].to_time if params[:offset]; rescue; end
46 44
47 45 # quick jump to an issue
48 46 if @question.match(/^#?(\d+)$/) && Issue.find_by_id($1, :include => :project, :conditions => Project.visible_by(User.current))
49 47 redirect_to :controller => "issues", :action => "show", :id => $1
50 48 return
51 49 end
52 50
53 51 @object_types = %w(issues news documents changesets wiki_pages messages projects)
54 52 if projects_to_search.is_a? Project
55 53 # don't search projects
56 54 @object_types.delete('projects')
57 55 # only show what the user is allowed to view
58 56 @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
59 57 end
60 58
61 59 @scope = @object_types.select {|t| params[t]}
62 60 @scope = @object_types if @scope.empty?
63 61
64 62 # extract tokens from the question
65 63 # eg. hello "bye bye" => ["hello", "bye bye"]
66 64 @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
67 65 # tokens must be at least 3 character long
68 66 @tokens = @tokens.uniq.select {|w| w.length > 2 }
69 67
70 68 if !@tokens.empty?
71 69 # no more than 5 tokens to search for
72 70 @tokens.slice! 5..-1 if @tokens.size > 5
73 71 # strings used in sql like statement
74 72 like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
75 73
76 74 @results = []
77 75 @results_by_type = Hash.new {|h,k| h[k] = 0}
78 76
79 77 limit = 10
80 78 @scope.each do |s|
81 79 r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
82 80 :all_words => @all_words,
83 81 :titles_only => @titles_only,
84 82 :limit => (limit+1),
85 83 :offset => offset,
86 84 :before => params[:previous].nil?)
87 85 @results += r
88 86 @results_by_type[s] += c
89 87 end
90 88 @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
91 89 if params[:previous].nil?
92 90 @pagination_previous_date = @results[0].event_datetime if offset && @results[0]
93 91 if @results.size > limit
94 92 @pagination_next_date = @results[limit-1].event_datetime
95 93 @results = @results[0, limit]
96 94 end
97 95 else
98 96 @pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
99 97 if @results.size > limit
100 98 @pagination_previous_date = @results[-(limit)].event_datetime
101 99 @results = @results[-(limit), limit]
102 100 end
103 101 end
104 102 else
105 103 @question = ""
106 104 end
107 105 render :layout => false if request.xhr?
108 106 end
109 107
110 108 private
111 109 def find_optional_project
112 110 return true unless params[:id]
113 111 @project = Project.find(params[:id])
114 112 check_project_privacy
115 113 rescue ActiveRecord::RecordNotFound
116 114 render_404
117 115 end
118 116 end
@@ -1,56 +1,55
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 SettingsController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 def index
23 22 edit
24 23 render :action => 'edit'
25 24 end
26 25
27 26 def edit
28 27 @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
29 28 if request.post? && params[:settings] && params[:settings].is_a?(Hash)
30 29 settings = (params[:settings] || {}).dup.symbolize_keys
31 30 settings.each do |name, value|
32 31 # remove blank values in array settings
33 32 value.delete_if {|v| v.blank? } if value.is_a?(Array)
34 33 Setting[name] = value
35 34 end
36 35 flash[:notice] = l(:notice_successful_update)
37 36 redirect_to :action => 'edit', :tab => params[:tab]
38 37 return
39 38 end
40 39 @options = {}
41 40 @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
42 41 @deliveries = ActionMailer::Base.perform_deliveries
43 42 end
44 43
45 44 def plugin
46 45 plugin_id = params[:id].to_sym
47 46 @plugin = Redmine::Plugin.registered_plugins[plugin_id]
48 47 if request.post?
49 48 Setting["plugin_#{plugin_id}"] = params[:settings]
50 49 flash[:notice] = l(:notice_successful_update)
51 50 redirect_to :action => 'plugin', :id => params[:id]
52 51 end
53 52 @partial = @plugin.settings[:partial]
54 53 @settings = Setting["plugin_#{plugin_id}"]
55 54 end
56 55 end
@@ -1,268 +1,267
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 TimelogController < ApplicationController
19 layout 'base'
20 19 menu_item :issues
21 20 before_filter :find_project, :authorize
22 21
23 22 verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
24 23
25 24 helper :sort
26 25 include SortHelper
27 26 helper :issues
28 27 include TimelogHelper
29 28 helper :custom_fields
30 29 include CustomFieldsHelper
31 30
32 31 def report
33 32 @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
34 33 :klass => Project,
35 34 :label => :label_project},
36 35 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
37 36 :klass => Version,
38 37 :label => :label_version},
39 38 'category' => {:sql => "#{Issue.table_name}.category_id",
40 39 :klass => IssueCategory,
41 40 :label => :field_category},
42 41 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
43 42 :klass => User,
44 43 :label => :label_member},
45 44 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
46 45 :klass => Tracker,
47 46 :label => :label_tracker},
48 47 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
49 48 :klass => Enumeration,
50 49 :label => :label_activity},
51 50 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
52 51 :klass => Issue,
53 52 :label => :label_issue}
54 53 }
55 54
56 55 # Add list and boolean custom fields as available criterias
57 56 @project.all_issue_custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
58 57 @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
59 58 :format => cf.field_format,
60 59 :label => cf.name}
61 60 end
62 61
63 62 # Add list and boolean time entry custom fields
64 63 TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
65 64 @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
66 65 :format => cf.field_format,
67 66 :label => cf.name}
68 67 end
69 68
70 69 @criterias = params[:criterias] || []
71 70 @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
72 71 @criterias.uniq!
73 72 @criterias = @criterias[0,3]
74 73
75 74 @columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
76 75
77 76 retrieve_date_range
78 77
79 78 unless @criterias.empty?
80 79 sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
81 80 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
82 81
83 82 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
84 83 sql << " FROM #{TimeEntry.table_name}"
85 84 sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
86 85 sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
87 86 sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
88 87 sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
89 88 sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
90 89 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
91 90
92 91 @hours = ActiveRecord::Base.connection.select_all(sql)
93 92
94 93 @hours.each do |row|
95 94 case @columns
96 95 when 'year'
97 96 row['year'] = row['tyear']
98 97 when 'month'
99 98 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
100 99 when 'week'
101 100 row['week'] = "#{row['tyear']}-#{row['tweek']}"
102 101 when 'day'
103 102 row['day'] = "#{row['spent_on']}"
104 103 end
105 104 end
106 105
107 106 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
108 107
109 108 @periods = []
110 109 # Date#at_beginning_of_ not supported in Rails 1.2.x
111 110 date_from = @from.to_time
112 111 # 100 columns max
113 112 while date_from <= @to.to_time && @periods.length < 100
114 113 case @columns
115 114 when 'year'
116 115 @periods << "#{date_from.year}"
117 116 date_from = (date_from + 1.year).at_beginning_of_year
118 117 when 'month'
119 118 @periods << "#{date_from.year}-#{date_from.month}"
120 119 date_from = (date_from + 1.month).at_beginning_of_month
121 120 when 'week'
122 121 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
123 122 date_from = (date_from + 7.day).at_beginning_of_week
124 123 when 'day'
125 124 @periods << "#{date_from.to_date}"
126 125 date_from = date_from + 1.day
127 126 end
128 127 end
129 128 end
130 129
131 130 respond_to do |format|
132 131 format.html { render :layout => !request.xhr? }
133 132 format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
134 133 end
135 134 end
136 135
137 136 def details
138 137 sort_init 'spent_on', 'desc'
139 138 sort_update
140 139
141 140 cond = ARCondition.new
142 141 cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
143 142 ["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
144 143
145 144 retrieve_date_range
146 145 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
147 146
148 147 TimeEntry.visible_by(User.current) do
149 148 respond_to do |format|
150 149 format.html {
151 150 # Paginate results
152 151 @entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
153 152 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
154 153 @entries = TimeEntry.find(:all,
155 154 :include => [:project, :activity, :user, {:issue => :tracker}],
156 155 :conditions => cond.conditions,
157 156 :order => sort_clause,
158 157 :limit => @entry_pages.items_per_page,
159 158 :offset => @entry_pages.current.offset)
160 159 @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
161 160
162 161 render :layout => !request.xhr?
163 162 }
164 163 format.atom {
165 164 entries = TimeEntry.find(:all,
166 165 :include => [:project, :activity, :user, {:issue => :tracker}],
167 166 :conditions => cond.conditions,
168 167 :order => "#{TimeEntry.table_name}.created_on DESC",
169 168 :limit => Setting.feeds_limit.to_i)
170 169 render_feed(entries, :title => l(:label_spent_time))
171 170 }
172 171 format.csv {
173 172 # Export all entries
174 173 @entries = TimeEntry.find(:all,
175 174 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
176 175 :conditions => cond.conditions,
177 176 :order => sort_clause)
178 177 send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
179 178 }
180 179 end
181 180 end
182 181 end
183 182
184 183 def edit
185 184 render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
186 185 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
187 186 @time_entry.attributes = params[:time_entry]
188 187 if request.post? and @time_entry.save
189 188 flash[:notice] = l(:notice_successful_update)
190 189 redirect_to(params[:back_url].blank? ? {:action => 'details', :project_id => @time_entry.project} : params[:back_url])
191 190 return
192 191 end
193 192 end
194 193
195 194 def destroy
196 195 render_404 and return unless @time_entry
197 196 render_403 and return unless @time_entry.editable_by?(User.current)
198 197 @time_entry.destroy
199 198 flash[:notice] = l(:notice_successful_delete)
200 199 redirect_to :back
201 200 rescue RedirectBackError
202 201 redirect_to :action => 'details', :project_id => @time_entry.project
203 202 end
204 203
205 204 private
206 205 def find_project
207 206 if params[:id]
208 207 @time_entry = TimeEntry.find(params[:id])
209 208 @project = @time_entry.project
210 209 elsif params[:issue_id]
211 210 @issue = Issue.find(params[:issue_id])
212 211 @project = @issue.project
213 212 elsif params[:project_id]
214 213 @project = Project.find(params[:project_id])
215 214 else
216 215 render_404
217 216 return false
218 217 end
219 218 rescue ActiveRecord::RecordNotFound
220 219 render_404
221 220 end
222 221
223 222 # Retrieves the date range based on predefined ranges or specific from/to param dates
224 223 def retrieve_date_range
225 224 @free_period = false
226 225 @from, @to = nil, nil
227 226
228 227 if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?)
229 228 case params[:period].to_s
230 229 when 'today'
231 230 @from = @to = Date.today
232 231 when 'yesterday'
233 232 @from = @to = Date.today - 1
234 233 when 'current_week'
235 234 @from = Date.today - (Date.today.cwday - 1)%7
236 235 @to = @from + 6
237 236 when 'last_week'
238 237 @from = Date.today - 7 - (Date.today.cwday - 1)%7
239 238 @to = @from + 6
240 239 when '7_days'
241 240 @from = Date.today - 7
242 241 @to = Date.today
243 242 when 'current_month'
244 243 @from = Date.civil(Date.today.year, Date.today.month, 1)
245 244 @to = (@from >> 1) - 1
246 245 when 'last_month'
247 246 @from = Date.civil(Date.today.year, Date.today.month, 1) << 1
248 247 @to = (@from >> 1) - 1
249 248 when '30_days'
250 249 @from = Date.today - 30
251 250 @to = Date.today
252 251 when 'current_year'
253 252 @from = Date.civil(Date.today.year, 1, 1)
254 253 @to = Date.civil(Date.today.year, 12, 31)
255 254 end
256 255 elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
257 256 begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
258 257 begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
259 258 @free_period = true
260 259 else
261 260 # default
262 261 end
263 262
264 263 @from, @to = @to, @from if @from && @to && @from > @to
265 264 @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
266 265 @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
267 266 end
268 267 end
@@ -1,80 +1,79
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 TrackersController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 def index
23 22 list
24 23 render :action => 'list' unless request.xhr?
25 24 end
26 25
27 26 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28 27 verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
29 28
30 29 def list
31 30 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
32 31 render :action => "list", :layout => false if request.xhr?
33 32 end
34 33
35 34 def new
36 35 @tracker = Tracker.new(params[:tracker])
37 36 if request.post? and @tracker.save
38 37 # workflow copy
39 38 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
40 39 @tracker.workflows.copy(copy_from)
41 40 end
42 41 flash[:notice] = l(:notice_successful_create)
43 42 redirect_to :action => 'list'
44 43 end
45 44 @trackers = Tracker.find :all, :order => 'position'
46 45 end
47 46
48 47 def edit
49 48 @tracker = Tracker.find(params[:id])
50 49 if request.post? and @tracker.update_attributes(params[:tracker])
51 50 flash[:notice] = l(:notice_successful_update)
52 51 redirect_to :action => 'list'
53 52 end
54 53 end
55 54
56 55 def move
57 56 @tracker = Tracker.find(params[:id])
58 57 case params[:position]
59 58 when 'highest'
60 59 @tracker.move_to_top
61 60 when 'higher'
62 61 @tracker.move_higher
63 62 when 'lower'
64 63 @tracker.move_lower
65 64 when 'lowest'
66 65 @tracker.move_to_bottom
67 66 end if params[:position]
68 67 redirect_to :action => 'list'
69 68 end
70 69
71 70 def destroy
72 71 @tracker = Tracker.find(params[:id])
73 72 unless @tracker.issues.empty?
74 73 flash[:error] = "This tracker contains issues and can\'t be deleted."
75 74 else
76 75 @tracker.destroy
77 76 end
78 77 redirect_to :action => 'list'
79 78 end
80 79 end
@@ -1,101 +1,100
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 UsersController < ApplicationController
19 layout 'base'
20 19 before_filter :require_admin
21 20
22 21 helper :sort
23 22 include SortHelper
24 23 helper :custom_fields
25 24 include CustomFieldsHelper
26 25
27 26 def index
28 27 list
29 28 render :action => 'list' unless request.xhr?
30 29 end
31 30
32 31 def list
33 32 sort_init 'login', 'asc'
34 33 sort_update
35 34
36 35 @status = params[:status] ? params[:status].to_i : 1
37 36 conditions = "status <> 0"
38 37 conditions = ["status=?", @status] unless @status == 0
39 38
40 39 @user_count = User.count(:conditions => conditions)
41 40 @user_pages = Paginator.new self, @user_count,
42 41 per_page_option,
43 42 params['page']
44 43 @users = User.find :all,:order => sort_clause,
45 44 :conditions => conditions,
46 45 :limit => @user_pages.items_per_page,
47 46 :offset => @user_pages.current.offset
48 47
49 48 render :action => "list", :layout => false if request.xhr?
50 49 end
51 50
52 51 def add
53 52 if request.get?
54 53 @user = User.new(:language => Setting.default_language)
55 54 else
56 55 @user = User.new(params[:user])
57 56 @user.admin = params[:user][:admin] || false
58 57 @user.login = params[:user][:login]
59 58 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
60 59 if @user.save
61 60 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
62 61 flash[:notice] = l(:notice_successful_create)
63 62 redirect_to :action => 'list'
64 63 end
65 64 end
66 65 @auth_sources = AuthSource.find(:all)
67 66 end
68 67
69 68 def edit
70 69 @user = User.find(params[:id])
71 70 if request.post?
72 71 @user.admin = params[:user][:admin] if params[:user][:admin]
73 72 @user.login = params[:user][:login] if params[:user][:login]
74 73 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
75 74 if @user.update_attributes(params[:user])
76 75 flash[:notice] = l(:notice_successful_update)
77 76 # Give a string to redirect_to otherwise it would use status param as the response code
78 77 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
79 78 end
80 79 end
81 80 @auth_sources = AuthSource.find(:all)
82 81 @roles = Role.find_all_givable
83 82 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
84 83 @membership ||= Member.new
85 84 @memberships = @user.memberships
86 85 end
87 86
88 87 def edit_membership
89 88 @user = User.find(params[:id])
90 89 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
91 90 @membership.attributes = params[:membership]
92 91 @membership.save if request.post?
93 92 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
94 93 end
95 94
96 95 def destroy_membership
97 96 @user = User.find(params[:id])
98 97 Member.find(params[:membership_id]).destroy if request.post?
99 98 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
100 99 end
101 100 end
@@ -1,61 +1,60
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 VersionsController < ApplicationController
19 layout 'base'
20 19 menu_item :roadmap
21 20 before_filter :find_project, :authorize
22 21
23 22 def show
24 23 end
25 24
26 25 def edit
27 26 if request.post? and @version.update_attributes(params[:version])
28 27 flash[:notice] = l(:notice_successful_update)
29 28 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
30 29 end
31 30 end
32 31
33 32 def destroy
34 33 @version.destroy
35 34 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
36 35 rescue
37 36 flash[:error] = "Unable to delete version"
38 37 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
39 38 end
40 39
41 40 def destroy_file
42 41 @version.attachments.find(params[:attachment_id]).destroy
43 42 flash[:notice] = l(:notice_successful_delete)
44 43 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
45 44 end
46 45
47 46 def status_by
48 47 respond_to do |format|
49 48 format.html { render :action => 'show' }
50 49 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
51 50 end
52 51 end
53 52
54 53 private
55 54 def find_project
56 55 @version = Version.find(params[:id])
57 56 @project = @version.project
58 57 rescue ActiveRecord::RecordNotFound
59 58 render_404
60 59 end
61 60 end
@@ -1,71 +1,70
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 WatchersController < ApplicationController
19 layout 'base'
20 19 before_filter :find_project
21 20 before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
22 21 before_filter :authorize, :only => :new
23 22
24 23 verify :method => :post,
25 24 :only => [ :watch, :unwatch ],
26 25 :render => { :nothing => true, :status => :method_not_allowed }
27 26
28 27 def watch
29 28 set_watcher(User.current, true)
30 29 end
31 30
32 31 def unwatch
33 32 set_watcher(User.current, false)
34 33 end
35 34
36 35 def new
37 36 @watcher = Watcher.new(params[:watcher])
38 37 @watcher.watchable = @watched
39 38 @watcher.save if request.post?
40 39 respond_to do |format|
41 40 format.html { redirect_to :back }
42 41 format.js do
43 42 render :update do |page|
44 43 page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
45 44 end
46 45 end
47 46 end
48 47 rescue ::ActionController::RedirectBackError
49 48 render :text => 'Watcher added.', :layout => true
50 49 end
51 50
52 51 private
53 52 def find_project
54 53 klass = Object.const_get(params[:object_type].camelcase)
55 54 return false unless klass.respond_to?('watched_by')
56 55 @watched = klass.find(params[:object_id])
57 56 @project = @watched.project
58 57 rescue
59 58 render_404
60 59 end
61 60
62 61 def set_watcher(user, watching)
63 62 @watched.set_watcher(user, watching)
64 63 respond_to do |format|
65 64 format.html { redirect_to :back }
66 65 format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
67 66 end
68 67 rescue ::ActionController::RedirectBackError
69 68 render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
70 69 end
71 70 end
@@ -1,25 +1,24
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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 WelcomeController < ApplicationController
19 layout 'base'
20 19
21 20 def index
22 21 @news = News.latest User.current
23 22 @projects = Project.latest User.current
24 23 end
25 24 end
@@ -1,204 +1,203
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 layout 'base'
22 21 before_filter :find_wiki, :authorize
23 22
24 23 verify :method => :post, :only => [:destroy, :destroy_attachment, :protect], :redirect_to => { :action => :index }
25 24
26 25 helper :attachments
27 26 include AttachmentsHelper
28 27
29 28 # display a page (in editing mode if it doesn't exist)
30 29 def index
31 30 page_title = params[:page]
32 31 @page = @wiki.find_or_new_page(page_title)
33 32 if @page.new_record?
34 33 if User.current.allowed_to?(:edit_wiki_pages, @project)
35 34 edit
36 35 render :action => 'edit'
37 36 else
38 37 render_404
39 38 end
40 39 return
41 40 end
42 41 @content = @page.content_for_version(params[:version])
43 42 if params[:export] == 'html'
44 43 export = render_to_string :action => 'export', :layout => false
45 44 send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
46 45 return
47 46 elsif params[:export] == 'txt'
48 47 send_data(@content.text, :type => 'text/plain', :filename => "#{@page.title}.txt")
49 48 return
50 49 end
51 50 @editable = editable?
52 51 render :action => 'show'
53 52 end
54 53
55 54 # edit an existing page or a new one
56 55 def edit
57 56 @page = @wiki.find_or_new_page(params[:page])
58 57 return render_403 unless editable?
59 58 @page.content = WikiContent.new(:page => @page) if @page.new_record?
60 59
61 60 @content = @page.content_for_version(params[:version])
62 61 @content.text = "h1. #{@page.pretty_title}" if @content.text.blank?
63 62 # don't keep previous comment
64 63 @content.comments = nil
65 64 if request.post?
66 65 if !@page.new_record? && @content.text == params[:content][:text]
67 66 # don't save if text wasn't changed
68 67 redirect_to :action => 'index', :id => @project, :page => @page.title
69 68 return
70 69 end
71 70 #@content.text = params[:content][:text]
72 71 #@content.comments = params[:content][:comments]
73 72 @content.attributes = params[:content]
74 73 @content.author = User.current
75 74 # if page is new @page.save will also save content, but not if page isn't a new record
76 75 if (@page.new_record? ? @page.save : @content.save)
77 76 redirect_to :action => 'index', :id => @project, :page => @page.title
78 77 end
79 78 end
80 79 rescue ActiveRecord::StaleObjectError
81 80 # Optimistic locking exception
82 81 flash[:error] = l(:notice_locking_conflict)
83 82 end
84 83
85 84 # rename a page
86 85 def rename
87 86 @page = @wiki.find_page(params[:page])
88 87 return render_403 unless editable?
89 88 @page.redirect_existing_links = true
90 89 # used to display the *original* title if some AR validation errors occur
91 90 @original_title = @page.pretty_title
92 91 if request.post? && @page.update_attributes(params[:wiki_page])
93 92 flash[:notice] = l(:notice_successful_update)
94 93 redirect_to :action => 'index', :id => @project, :page => @page.title
95 94 end
96 95 end
97 96
98 97 def protect
99 98 page = @wiki.find_page(params[:page])
100 99 page.update_attribute :protected, params[:protected]
101 100 redirect_to :action => 'index', :id => @project, :page => page.title
102 101 end
103 102
104 103 # show page history
105 104 def history
106 105 @page = @wiki.find_page(params[:page])
107 106
108 107 @version_count = @page.content.versions.count
109 108 @version_pages = Paginator.new self, @version_count, per_page_option, params['p']
110 109 # don't load text
111 110 @versions = @page.content.versions.find :all,
112 111 :select => "id, author_id, comments, updated_on, version",
113 112 :order => 'version DESC',
114 113 :limit => @version_pages.items_per_page + 1,
115 114 :offset => @version_pages.current.offset
116 115
117 116 render :layout => false if request.xhr?
118 117 end
119 118
120 119 def diff
121 120 @page = @wiki.find_page(params[:page])
122 121 @diff = @page.diff(params[:version], params[:version_from])
123 122 render_404 unless @diff
124 123 end
125 124
126 125 def annotate
127 126 @page = @wiki.find_page(params[:page])
128 127 @annotate = @page.annotate(params[:version])
129 128 end
130 129
131 130 # remove a wiki page and its history
132 131 def destroy
133 132 @page = @wiki.find_page(params[:page])
134 133 return render_403 unless editable?
135 134 @page.destroy if @page
136 135 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
137 136 end
138 137
139 138 # display special pages
140 139 def special
141 140 page_title = params[:page].downcase
142 141 case page_title
143 142 # show pages index, sorted by title
144 143 when 'page_index', 'date_index'
145 144 # eager load information about last updates, without loading text
146 145 @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
147 146 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
148 147 :order => 'title'
149 148 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
150 149 @pages_by_parent_id = @pages.group_by(&:parent_id)
151 150 # export wiki to a single html file
152 151 when 'export'
153 152 @pages = @wiki.pages.find :all, :order => 'title'
154 153 export = render_to_string :action => 'export_multiple', :layout => false
155 154 send_data(export, :type => 'text/html', :filename => "wiki.html")
156 155 return
157 156 else
158 157 # requested special page doesn't exist, redirect to default page
159 158 redirect_to :action => 'index', :id => @project, :page => nil and return
160 159 end
161 160 render :action => "special_#{page_title}"
162 161 end
163 162
164 163 def preview
165 164 page = @wiki.find_page(params[:page])
166 165 # page is nil when previewing a new page
167 166 return render_403 unless page.nil? || editable?(page)
168 167 if page
169 168 @attachements = page.attachments
170 169 @previewed = page.content
171 170 end
172 171 @text = params[:content][:text]
173 172 render :partial => 'common/preview'
174 173 end
175 174
176 175 def add_attachment
177 176 @page = @wiki.find_page(params[:page])
178 177 return render_403 unless editable?
179 178 attach_files(@page, params[:attachments])
180 179 redirect_to :action => 'index', :page => @page.title
181 180 end
182 181
183 182 def destroy_attachment
184 183 @page = @wiki.find_page(params[:page])
185 184 return render_403 unless editable?
186 185 @page.attachments.find(params[:attachment_id]).destroy
187 186 redirect_to :action => 'index', :page => @page.title
188 187 end
189 188
190 189 private
191 190
192 191 def find_wiki
193 192 @project = Project.find(params[:id])
194 193 @wiki = @project.wiki
195 194 render_404 unless @wiki
196 195 rescue ActiveRecord::RecordNotFound
197 196 render_404
198 197 end
199 198
200 199 # Returns true if the current user is allowed to edit the page, otherwise false
201 200 def editable?(page = @page)
202 201 page.editable_by?(User.current)
203 202 end
204 203 end
@@ -1,45 +1,44
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 WikisController < ApplicationController
19 layout 'base'
20 19 menu_item :settings
21 20 before_filter :find_project, :authorize
22 21
23 22 # Create or update a project's wiki
24 23 def edit
25 24 @wiki = @project.wiki || Wiki.new(:project => @project)
26 25 @wiki.attributes = params[:wiki]
27 26 @wiki.save if request.post?
28 27 render(:update) {|page| page.replace_html "tab-content-wiki", :partial => 'projects/settings/wiki'}
29 28 end
30 29
31 30 # Delete a project's wiki
32 31 def destroy
33 32 if request.post? && params[:confirm] && @project.wiki
34 33 @project.wiki.destroy
35 34 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'wiki'
36 35 end
37 36 end
38 37
39 38 private
40 39 def find_project
41 40 @project = Project.find(params[:id])
42 41 rescue ActiveRecord::RecordNotFound
43 42 render_404
44 43 end
45 44 end
General Comments 0
You need to be logged in to leave comments. Login now