##// END OF EJS Templates
Adds a builder-like template system for rendering xml and json API responses....
Jean-Philippe Lang -
r4338:96ce0f017cfe
parent child
Show More
@@ -0,0 +1,28
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 module Redmine
19 module Views
20 class ApiTemplateHandler < ActionView::TemplateHandler
21 include ActionView::TemplateHandlers::Compilable
22
23 def compile(template)
24 "Redmine::Views::Builders.for(params[:format]) do |api|; #{template.source}; self.output_buffer = api.output; end"
25 end
26 end
27 end
28 end
@@ -0,0 +1,35
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 module Redmine
19 module Views
20 module Builders
21 def self.for(format, &block)
22 builder = case format
23 when 'xml', :xml; Builders::Xml.new
24 when 'json', :json; Builders::Json.new
25 else; raise "No builder for format #{format}"
26 end
27 if block
28 block.call(builder)
29 else
30 builder
31 end
32 end
33 end
34 end
35 end
@@ -0,0 +1,30
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'blankslate'
19
20 module Redmine
21 module Views
22 module Builders
23 class Json < Structure
24 def output
25 @struct.first.to_json
26 end
27 end
28 end
29 end
30 end
@@ -0,0 +1,68
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'blankslate'
19
20 module Redmine
21 module Views
22 module Builders
23 class Structure < BlankSlate
24 def initialize
25 @struct = [{}]
26 end
27
28 def array(tag, &block)
29 @struct << []
30 block.call(self)
31 ret = @struct.pop
32 @struct.last[tag] = ret
33 end
34
35 def method_missing(sym, *args, &block)
36 if args.any?
37 if args.first.is_a?(Hash)
38 if @struct.last.is_a?(Array)
39 @struct.last << args.first
40 end
41 else
42 if @struct.last.is_a?(Array)
43 @struct.last << (args.last || {}).merge(:value => args.first)
44 else
45 @struct.last[sym] = args.first
46 end
47 end
48 end
49
50 if block
51 @struct << {}
52 block.call(self)
53 ret = @struct.pop
54 if @struct.last.is_a?(Array)
55 @struct.last << ret
56 else
57 @struct.last[sym] = ret
58 end
59 end
60 end
61
62 def output
63 raise "Need to implement #{self.class.name}#output"
64 end
65 end
66 end
67 end
68 end
@@ -0,0 +1,45
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 module Redmine
19 module Views
20 module Builders
21 class Xml < ::Builder::XmlMarkup
22 def initialize
23 super
24 instruct!
25 end
26
27 def output
28 target!
29 end
30
31 def method_missing(sym, *args, &block)
32 if args.size == 1 && args.first.is_a?(Time)
33 __send__ sym, args.first.xmlschema, &block
34 else
35 super
36 end
37 end
38
39 def array(name, options={}, &block)
40 __send__ name, options.merge(:type => 'array'), &block
41 end
42 end
43 end
44 end
45 end
@@ -0,0 +1,54
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../../../../../test_helper'
19
20 class Redmine::Views::Builders::JsonTest < HelperTestCase
21
22 def test_hash
23 assert_json_output({'person' => {'name' => 'Ryan', 'age' => 32}}) do |b|
24 b.person do
25 b.name 'Ryan'
26 b.age 32
27 end
28 end
29 end
30
31 def test_array
32 assert_json_output({'books' => [{'title' => 'Book 1', 'author' => 'B. Smith'}, {'title' => 'Book 2', 'author' => 'G. Cooper'}]}) do |b|
33 b.array :books do |b|
34 b.book :title => 'Book 1', :author => 'B. Smith'
35 b.book :title => 'Book 2', :author => 'G. Cooper'
36 end
37 end
38 end
39
40 def test_array_with_content_tags
41 assert_json_output({'books' => [{'value' => 'Book 1', 'author' => 'B. Smith'}, {'value' => 'Book 2', 'author' => 'G. Cooper'}]}) do |b|
42 b.array :books do |b|
43 b.book 'Book 1', :author => 'B. Smith'
44 b.book 'Book 2', :author => 'G. Cooper'
45 end
46 end
47 end
48
49 def assert_json_output(expected, &block)
50 builder = Redmine::Views::Builders::Json.new
51 block.call(builder)
52 assert_equal(expected, ActiveSupport::JSON.decode(builder.output))
53 end
54 end
@@ -0,0 +1,54
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../../../../../test_helper'
19
20 class Redmine::Views::Builders::XmlTest < HelperTestCase
21
22 def test_hash
23 assert_xml_output('<person><name>Ryan</name><age>32</age></person>') do |b|
24 b.person do
25 b.name 'Ryan'
26 b.age 32
27 end
28 end
29 end
30
31 def test_array
32 assert_xml_output('<books type="array"><book author="B. Smith" title="Book 1"/><book author="G. Cooper" title="Book 2"/></books>') do |b|
33 b.array :books do |b|
34 b.book :title => 'Book 1', :author => 'B. Smith'
35 b.book :title => 'Book 2', :author => 'G. Cooper'
36 end
37 end
38 end
39
40 def test_array_with_content_tags
41 assert_xml_output('<books type="array"><book author="B. Smith">Book 1</book><book author="G. Cooper">Book 2</book></books>') do |b|
42 b.array :books do |b|
43 b.book 'Book 1', :author => 'B. Smith'
44 b.book 'Book 2', :author => 'G. Cooper'
45 end
46 end
47 end
48
49 def assert_xml_output(expected, &block)
50 builder = Redmine::Views::Builders::Xml.new
51 block.call(builder)
52 assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)
53 end
54 end
@@ -1,417 +1,417
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'uri'
18 require 'uri'
19 require 'cgi'
19 require 'cgi'
20
20
21 class ApplicationController < ActionController::Base
21 class ApplicationController < ActionController::Base
22 include Redmine::I18n
22 include Redmine::I18n
23
23
24 layout 'base'
24 layout 'base'
25 exempt_from_layout 'builder'
25 exempt_from_layout 'builder', 'apit'
26
26
27 # Remove broken cookie after upgrade from 0.8.x (#4292)
27 # Remove broken cookie after upgrade from 0.8.x (#4292)
28 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
28 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
29 # TODO: remove it when Rails is fixed
29 # TODO: remove it when Rails is fixed
30 before_filter :delete_broken_cookies
30 before_filter :delete_broken_cookies
31 def delete_broken_cookies
31 def delete_broken_cookies
32 if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
32 if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
33 cookies.delete '_redmine_session'
33 cookies.delete '_redmine_session'
34 redirect_to home_path
34 redirect_to home_path
35 return false
35 return false
36 end
36 end
37 end
37 end
38
38
39 before_filter :user_setup, :check_if_login_required, :set_localization
39 before_filter :user_setup, :check_if_login_required, :set_localization
40 filter_parameter_logging :password
40 filter_parameter_logging :password
41 protect_from_forgery
41 protect_from_forgery
42
42
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
43 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
44
44
45 include Redmine::Search::Controller
45 include Redmine::Search::Controller
46 include Redmine::MenuManager::MenuController
46 include Redmine::MenuManager::MenuController
47 helper Redmine::MenuManager::MenuHelper
47 helper Redmine::MenuManager::MenuHelper
48
48
49 Redmine::Scm::Base.all.each do |scm|
49 Redmine::Scm::Base.all.each do |scm|
50 require_dependency "repository/#{scm.underscore}"
50 require_dependency "repository/#{scm.underscore}"
51 end
51 end
52
52
53 def user_setup
53 def user_setup
54 # Check the settings cache for each request
54 # Check the settings cache for each request
55 Setting.check_cache
55 Setting.check_cache
56 # Find the current user
56 # Find the current user
57 User.current = find_current_user
57 User.current = find_current_user
58 end
58 end
59
59
60 # Returns the current user or nil if no user is logged in
60 # Returns the current user or nil if no user is logged in
61 # and starts a session if needed
61 # and starts a session if needed
62 def find_current_user
62 def find_current_user
63 if session[:user_id]
63 if session[:user_id]
64 # existing session
64 # existing session
65 (User.active.find(session[:user_id]) rescue nil)
65 (User.active.find(session[:user_id]) rescue nil)
66 elsif cookies[:autologin] && Setting.autologin?
66 elsif cookies[:autologin] && Setting.autologin?
67 # auto-login feature starts a new session
67 # auto-login feature starts a new session
68 user = User.try_to_autologin(cookies[:autologin])
68 user = User.try_to_autologin(cookies[:autologin])
69 session[:user_id] = user.id if user
69 session[:user_id] = user.id if user
70 user
70 user
71 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
71 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
72 # RSS key authentication does not start a session
72 # RSS key authentication does not start a session
73 User.find_by_rss_key(params[:key])
73 User.find_by_rss_key(params[:key])
74 elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
74 elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format])
75 if params[:key].present? && accept_key_auth_actions.include?(params[:action])
75 if params[:key].present? && accept_key_auth_actions.include?(params[:action])
76 # Use API key
76 # Use API key
77 User.find_by_api_key(params[:key])
77 User.find_by_api_key(params[:key])
78 else
78 else
79 # HTTP Basic, either username/password or API key/random
79 # HTTP Basic, either username/password or API key/random
80 authenticate_with_http_basic do |username, password|
80 authenticate_with_http_basic do |username, password|
81 User.try_to_login(username, password) || User.find_by_api_key(username)
81 User.try_to_login(username, password) || User.find_by_api_key(username)
82 end
82 end
83 end
83 end
84 end
84 end
85 end
85 end
86
86
87 # Sets the logged in user
87 # Sets the logged in user
88 def logged_user=(user)
88 def logged_user=(user)
89 reset_session
89 reset_session
90 if user && user.is_a?(User)
90 if user && user.is_a?(User)
91 User.current = user
91 User.current = user
92 session[:user_id] = user.id
92 session[:user_id] = user.id
93 else
93 else
94 User.current = User.anonymous
94 User.current = User.anonymous
95 end
95 end
96 end
96 end
97
97
98 # check if login is globally required to access the application
98 # check if login is globally required to access the application
99 def check_if_login_required
99 def check_if_login_required
100 # no check needed if user is already logged in
100 # no check needed if user is already logged in
101 return true if User.current.logged?
101 return true if User.current.logged?
102 require_login if Setting.login_required?
102 require_login if Setting.login_required?
103 end
103 end
104
104
105 def set_localization
105 def set_localization
106 lang = nil
106 lang = nil
107 if User.current.logged?
107 if User.current.logged?
108 lang = find_language(User.current.language)
108 lang = find_language(User.current.language)
109 end
109 end
110 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
110 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
111 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
111 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
112 if !accept_lang.blank?
112 if !accept_lang.blank?
113 accept_lang = accept_lang.downcase
113 accept_lang = accept_lang.downcase
114 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
114 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
115 end
115 end
116 end
116 end
117 lang ||= Setting.default_language
117 lang ||= Setting.default_language
118 set_language_if_valid(lang)
118 set_language_if_valid(lang)
119 end
119 end
120
120
121 def require_login
121 def require_login
122 if !User.current.logged?
122 if !User.current.logged?
123 # Extract only the basic url parameters on non-GET requests
123 # Extract only the basic url parameters on non-GET requests
124 if request.get?
124 if request.get?
125 url = url_for(params)
125 url = url_for(params)
126 else
126 else
127 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
127 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
128 end
128 end
129 respond_to do |format|
129 respond_to do |format|
130 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
130 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
131 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
131 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
132 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
132 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
133 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
133 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
134 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
134 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
135 end
135 end
136 return false
136 return false
137 end
137 end
138 true
138 true
139 end
139 end
140
140
141 def require_admin
141 def require_admin
142 return unless require_login
142 return unless require_login
143 if !User.current.admin?
143 if !User.current.admin?
144 render_403
144 render_403
145 return false
145 return false
146 end
146 end
147 true
147 true
148 end
148 end
149
149
150 def deny_access
150 def deny_access
151 User.current.logged? ? render_403 : require_login
151 User.current.logged? ? render_403 : require_login
152 end
152 end
153
153
154 # Authorize the user for the requested action
154 # Authorize the user for the requested action
155 def authorize(ctrl = params[:controller], action = params[:action], global = false)
155 def authorize(ctrl = params[:controller], action = params[:action], global = false)
156 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
156 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
157 if allowed
157 if allowed
158 true
158 true
159 else
159 else
160 if @project && @project.archived?
160 if @project && @project.archived?
161 render_403 :message => :notice_not_authorized_archived_project
161 render_403 :message => :notice_not_authorized_archived_project
162 else
162 else
163 deny_access
163 deny_access
164 end
164 end
165 end
165 end
166 end
166 end
167
167
168 # Authorize the user for the requested action outside a project
168 # Authorize the user for the requested action outside a project
169 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
169 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
170 authorize(ctrl, action, global)
170 authorize(ctrl, action, global)
171 end
171 end
172
172
173 # Find project of id params[:id]
173 # Find project of id params[:id]
174 def find_project
174 def find_project
175 @project = Project.find(params[:id])
175 @project = Project.find(params[:id])
176 rescue ActiveRecord::RecordNotFound
176 rescue ActiveRecord::RecordNotFound
177 render_404
177 render_404
178 end
178 end
179
179
180 # Find project of id params[:project_id]
180 # Find project of id params[:project_id]
181 def find_project_by_project_id
181 def find_project_by_project_id
182 @project = Project.find(params[:project_id])
182 @project = Project.find(params[:project_id])
183 rescue ActiveRecord::RecordNotFound
183 rescue ActiveRecord::RecordNotFound
184 render_404
184 render_404
185 end
185 end
186
186
187 # Find a project based on params[:project_id]
187 # Find a project based on params[:project_id]
188 # TODO: some subclasses override this, see about merging their logic
188 # TODO: some subclasses override this, see about merging their logic
189 def find_optional_project
189 def find_optional_project
190 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
190 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
191 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
191 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
192 allowed ? true : deny_access
192 allowed ? true : deny_access
193 rescue ActiveRecord::RecordNotFound
193 rescue ActiveRecord::RecordNotFound
194 render_404
194 render_404
195 end
195 end
196
196
197 # Finds and sets @project based on @object.project
197 # Finds and sets @project based on @object.project
198 def find_project_from_association
198 def find_project_from_association
199 render_404 unless @object.present?
199 render_404 unless @object.present?
200
200
201 @project = @object.project
201 @project = @object.project
202 rescue ActiveRecord::RecordNotFound
202 rescue ActiveRecord::RecordNotFound
203 render_404
203 render_404
204 end
204 end
205
205
206 def find_model_object
206 def find_model_object
207 model = self.class.read_inheritable_attribute('model_object')
207 model = self.class.read_inheritable_attribute('model_object')
208 if model
208 if model
209 @object = model.find(params[:id])
209 @object = model.find(params[:id])
210 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
210 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
211 end
211 end
212 rescue ActiveRecord::RecordNotFound
212 rescue ActiveRecord::RecordNotFound
213 render_404
213 render_404
214 end
214 end
215
215
216 def self.model_object(model)
216 def self.model_object(model)
217 write_inheritable_attribute('model_object', model)
217 write_inheritable_attribute('model_object', model)
218 end
218 end
219
219
220 # Filter for bulk issue operations
220 # Filter for bulk issue operations
221 def find_issues
221 def find_issues
222 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
222 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
223 raise ActiveRecord::RecordNotFound if @issues.empty?
223 raise ActiveRecord::RecordNotFound if @issues.empty?
224 @projects = @issues.collect(&:project).compact.uniq
224 @projects = @issues.collect(&:project).compact.uniq
225 @project = @projects.first if @projects.size == 1
225 @project = @projects.first if @projects.size == 1
226 rescue ActiveRecord::RecordNotFound
226 rescue ActiveRecord::RecordNotFound
227 render_404
227 render_404
228 end
228 end
229
229
230 # Check if project is unique before bulk operations
230 # Check if project is unique before bulk operations
231 def check_project_uniqueness
231 def check_project_uniqueness
232 unless @project
232 unless @project
233 # TODO: let users bulk edit/move/destroy issues from different projects
233 # TODO: let users bulk edit/move/destroy issues from different projects
234 render_error 'Can not bulk edit/move/destroy issues from different projects'
234 render_error 'Can not bulk edit/move/destroy issues from different projects'
235 return false
235 return false
236 end
236 end
237 end
237 end
238
238
239 # make sure that the user is a member of the project (or admin) if project is private
239 # make sure that the user is a member of the project (or admin) if project is private
240 # used as a before_filter for actions that do not require any particular permission on the project
240 # used as a before_filter for actions that do not require any particular permission on the project
241 def check_project_privacy
241 def check_project_privacy
242 if @project && @project.active?
242 if @project && @project.active?
243 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
243 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
244 true
244 true
245 else
245 else
246 User.current.logged? ? render_403 : require_login
246 User.current.logged? ? render_403 : require_login
247 end
247 end
248 else
248 else
249 @project = nil
249 @project = nil
250 render_404
250 render_404
251 false
251 false
252 end
252 end
253 end
253 end
254
254
255 def back_url
255 def back_url
256 params[:back_url] || request.env['HTTP_REFERER']
256 params[:back_url] || request.env['HTTP_REFERER']
257 end
257 end
258
258
259 def redirect_back_or_default(default)
259 def redirect_back_or_default(default)
260 back_url = CGI.unescape(params[:back_url].to_s)
260 back_url = CGI.unescape(params[:back_url].to_s)
261 if !back_url.blank?
261 if !back_url.blank?
262 begin
262 begin
263 uri = URI.parse(back_url)
263 uri = URI.parse(back_url)
264 # do not redirect user to another host or to the login or register page
264 # do not redirect user to another host or to the login or register page
265 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
265 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
266 redirect_to(back_url)
266 redirect_to(back_url)
267 return
267 return
268 end
268 end
269 rescue URI::InvalidURIError
269 rescue URI::InvalidURIError
270 # redirect to default
270 # redirect to default
271 end
271 end
272 end
272 end
273 redirect_to default
273 redirect_to default
274 end
274 end
275
275
276 def render_403(options={})
276 def render_403(options={})
277 @project = nil
277 @project = nil
278 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
278 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
279 return false
279 return false
280 end
280 end
281
281
282 def render_404(options={})
282 def render_404(options={})
283 render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
283 render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
284 return false
284 return false
285 end
285 end
286
286
287 # Renders an error response
287 # Renders an error response
288 def render_error(arg)
288 def render_error(arg)
289 arg = {:message => arg} unless arg.is_a?(Hash)
289 arg = {:message => arg} unless arg.is_a?(Hash)
290
290
291 @message = arg[:message]
291 @message = arg[:message]
292 @message = l(@message) if @message.is_a?(Symbol)
292 @message = l(@message) if @message.is_a?(Symbol)
293 @status = arg[:status] || 500
293 @status = arg[:status] || 500
294
294
295 respond_to do |format|
295 respond_to do |format|
296 format.html {
296 format.html {
297 render :template => 'common/error', :layout => use_layout, :status => @status
297 render :template => 'common/error', :layout => use_layout, :status => @status
298 }
298 }
299 format.atom { head @status }
299 format.atom { head @status }
300 format.xml { head @status }
300 format.xml { head @status }
301 format.js { head @status }
301 format.js { head @status }
302 format.json { head @status }
302 format.json { head @status }
303 end
303 end
304 end
304 end
305
305
306 # Picks which layout to use based on the request
306 # Picks which layout to use based on the request
307 #
307 #
308 # @return [boolean, string] name of the layout to use or false for no layout
308 # @return [boolean, string] name of the layout to use or false for no layout
309 def use_layout
309 def use_layout
310 request.xhr? ? false : 'base'
310 request.xhr? ? false : 'base'
311 end
311 end
312
312
313 def invalid_authenticity_token
313 def invalid_authenticity_token
314 if api_request?
314 if api_request?
315 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
315 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
316 end
316 end
317 render_error "Invalid form authenticity token."
317 render_error "Invalid form authenticity token."
318 end
318 end
319
319
320 def render_feed(items, options={})
320 def render_feed(items, options={})
321 @items = items || []
321 @items = items || []
322 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
322 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
323 @items = @items.slice(0, Setting.feeds_limit.to_i)
323 @items = @items.slice(0, Setting.feeds_limit.to_i)
324 @title = options[:title] || Setting.app_title
324 @title = options[:title] || Setting.app_title
325 render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
325 render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
326 end
326 end
327
327
328 def self.accept_key_auth(*actions)
328 def self.accept_key_auth(*actions)
329 actions = actions.flatten.map(&:to_s)
329 actions = actions.flatten.map(&:to_s)
330 write_inheritable_attribute('accept_key_auth_actions', actions)
330 write_inheritable_attribute('accept_key_auth_actions', actions)
331 end
331 end
332
332
333 def accept_key_auth_actions
333 def accept_key_auth_actions
334 self.class.read_inheritable_attribute('accept_key_auth_actions') || []
334 self.class.read_inheritable_attribute('accept_key_auth_actions') || []
335 end
335 end
336
336
337 # Returns the number of objects that should be displayed
337 # Returns the number of objects that should be displayed
338 # on the paginated list
338 # on the paginated list
339 def per_page_option
339 def per_page_option
340 per_page = nil
340 per_page = nil
341 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
341 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
342 per_page = params[:per_page].to_s.to_i
342 per_page = params[:per_page].to_s.to_i
343 session[:per_page] = per_page
343 session[:per_page] = per_page
344 elsif session[:per_page]
344 elsif session[:per_page]
345 per_page = session[:per_page]
345 per_page = session[:per_page]
346 else
346 else
347 per_page = Setting.per_page_options_array.first || 25
347 per_page = Setting.per_page_options_array.first || 25
348 end
348 end
349 per_page
349 per_page
350 end
350 end
351
351
352 # qvalues http header parser
352 # qvalues http header parser
353 # code taken from webrick
353 # code taken from webrick
354 def parse_qvalues(value)
354 def parse_qvalues(value)
355 tmp = []
355 tmp = []
356 if value
356 if value
357 parts = value.split(/,\s*/)
357 parts = value.split(/,\s*/)
358 parts.each {|part|
358 parts.each {|part|
359 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
359 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
360 val = m[1]
360 val = m[1]
361 q = (m[2] or 1).to_f
361 q = (m[2] or 1).to_f
362 tmp.push([val, q])
362 tmp.push([val, q])
363 end
363 end
364 }
364 }
365 tmp = tmp.sort_by{|val, q| -q}
365 tmp = tmp.sort_by{|val, q| -q}
366 tmp.collect!{|val, q| val}
366 tmp.collect!{|val, q| val}
367 end
367 end
368 return tmp
368 return tmp
369 rescue
369 rescue
370 nil
370 nil
371 end
371 end
372
372
373 # Returns a string that can be used as filename value in Content-Disposition header
373 # Returns a string that can be used as filename value in Content-Disposition header
374 def filename_for_content_disposition(name)
374 def filename_for_content_disposition(name)
375 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
375 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
376 end
376 end
377
377
378 def api_request?
378 def api_request?
379 %w(xml json).include? params[:format]
379 %w(xml json).include? params[:format]
380 end
380 end
381
381
382 # Renders a warning flash if obj has unsaved attachments
382 # Renders a warning flash if obj has unsaved attachments
383 def render_attachment_warning_if_needed(obj)
383 def render_attachment_warning_if_needed(obj)
384 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
384 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
385 end
385 end
386
386
387 # Sets the `flash` notice or error based the number of issues that did not save
387 # Sets the `flash` notice or error based the number of issues that did not save
388 #
388 #
389 # @param [Array, Issue] issues all of the saved and unsaved Issues
389 # @param [Array, Issue] issues all of the saved and unsaved Issues
390 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
390 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
391 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
391 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
392 if unsaved_issue_ids.empty?
392 if unsaved_issue_ids.empty?
393 flash[:notice] = l(:notice_successful_update) unless issues.empty?
393 flash[:notice] = l(:notice_successful_update) unless issues.empty?
394 else
394 else
395 flash[:error] = l(:notice_failed_to_save_issues,
395 flash[:error] = l(:notice_failed_to_save_issues,
396 :count => unsaved_issue_ids.size,
396 :count => unsaved_issue_ids.size,
397 :total => issues.size,
397 :total => issues.size,
398 :ids => '#' + unsaved_issue_ids.join(', #'))
398 :ids => '#' + unsaved_issue_ids.join(', #'))
399 end
399 end
400 end
400 end
401
401
402 # Rescues an invalid query statement. Just in case...
402 # Rescues an invalid query statement. Just in case...
403 def query_statement_invalid(exception)
403 def query_statement_invalid(exception)
404 logger.error "Query::StatementInvalid: #{exception.message}" if logger
404 logger.error "Query::StatementInvalid: #{exception.message}" if logger
405 session.delete(:query)
405 session.delete(:query)
406 sort_clear if respond_to?(:sort_clear)
406 sort_clear if respond_to?(:sort_clear)
407 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
407 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
408 end
408 end
409
409
410 # Converts the errors on an ActiveRecord object into a common JSON format
410 # Converts the errors on an ActiveRecord object into a common JSON format
411 def object_errors_to_json(object)
411 def object_errors_to_json(object)
412 object.errors.collect do |attribute, error|
412 object.errors.collect do |attribute, error|
413 { attribute => error }
413 { attribute => error }
414 end.to_json
414 end.to_json
415 end
415 end
416
416
417 end
417 end
@@ -1,231 +1,233
1 require 'redmine/access_control'
1 require 'redmine/access_control'
2 require 'redmine/menu_manager'
2 require 'redmine/menu_manager'
3 require 'redmine/activity'
3 require 'redmine/activity'
4 require 'redmine/search'
4 require 'redmine/search'
5 require 'redmine/custom_field_format'
5 require 'redmine/custom_field_format'
6 require 'redmine/mime_type'
6 require 'redmine/mime_type'
7 require 'redmine/core_ext'
7 require 'redmine/core_ext'
8 require 'redmine/themes'
8 require 'redmine/themes'
9 require 'redmine/hook'
9 require 'redmine/hook'
10 require 'redmine/plugin'
10 require 'redmine/plugin'
11 require 'redmine/notifiable'
11 require 'redmine/notifiable'
12 require 'redmine/wiki_formatting'
12 require 'redmine/wiki_formatting'
13 require 'redmine/scm/base'
13 require 'redmine/scm/base'
14
14
15 begin
15 begin
16 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
16 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
17 rescue LoadError
17 rescue LoadError
18 # RMagick is not available
18 # RMagick is not available
19 end
19 end
20
20
21 if RUBY_VERSION < '1.9'
21 if RUBY_VERSION < '1.9'
22 require 'faster_csv'
22 require 'faster_csv'
23 else
23 else
24 require 'csv'
24 require 'csv'
25 FCSV = CSV
25 FCSV = CSV
26 end
26 end
27
27
28 Redmine::Scm::Base.add "Subversion"
28 Redmine::Scm::Base.add "Subversion"
29 Redmine::Scm::Base.add "Darcs"
29 Redmine::Scm::Base.add "Darcs"
30 Redmine::Scm::Base.add "Mercurial"
30 Redmine::Scm::Base.add "Mercurial"
31 Redmine::Scm::Base.add "Cvs"
31 Redmine::Scm::Base.add "Cvs"
32 Redmine::Scm::Base.add "Bazaar"
32 Redmine::Scm::Base.add "Bazaar"
33 Redmine::Scm::Base.add "Git"
33 Redmine::Scm::Base.add "Git"
34 Redmine::Scm::Base.add "Filesystem"
34 Redmine::Scm::Base.add "Filesystem"
35
35
36 Redmine::CustomFieldFormat.map do |fields|
36 Redmine::CustomFieldFormat.map do |fields|
37 fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1)
37 fields.register Redmine::CustomFieldFormat.new('string', :label => :label_string, :order => 1)
38 fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2)
38 fields.register Redmine::CustomFieldFormat.new('text', :label => :label_text, :order => 2)
39 fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3)
39 fields.register Redmine::CustomFieldFormat.new('int', :label => :label_integer, :order => 3)
40 fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4)
40 fields.register Redmine::CustomFieldFormat.new('float', :label => :label_float, :order => 4)
41 fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
41 fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
42 fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
42 fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
43 fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
43 fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
44 end
44 end
45
45
46 # Permissions
46 # Permissions
47 Redmine::AccessControl.map do |map|
47 Redmine::AccessControl.map do |map|
48 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true
48 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true
49 map.permission :search_project, {:search => :index}, :public => true
49 map.permission :search_project, {:search => :index}, :public => true
50 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
50 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
51 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
51 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
52 map.permission :select_project_modules, {:projects => :modules}, :require => :member
52 map.permission :select_project_modules, {:projects => :modules}, :require => :member
53 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member
53 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member
54 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
54 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
55 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
55 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
56
56
57 map.project_module :issue_tracking do |map|
57 map.project_module :issue_tracking do |map|
58 # Issue categories
58 # Issue categories
59 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
59 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
60 # Issues
60 # Issues
61 map.permission :view_issues, {:issues => [:index, :show],
61 map.permission :view_issues, {:issues => [:index, :show],
62 :auto_complete => [:issues],
62 :auto_complete => [:issues],
63 :context_menus => [:issues],
63 :context_menus => [:issues],
64 :versions => [:index, :show, :status_by],
64 :versions => [:index, :show, :status_by],
65 :journals => :index,
65 :journals => :index,
66 :queries => :index,
66 :queries => :index,
67 :reports => [:issue_report, :issue_report_details]}
67 :reports => [:issue_report, :issue_report_details]}
68 map.permission :add_issues, {:issues => [:new, :create, :update_form]}
68 map.permission :add_issues, {:issues => [:new, :create, :update_form]}
69 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]}
69 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new]}
70 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
70 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
71 map.permission :manage_subtasks, {}
71 map.permission :manage_subtasks, {}
72 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
72 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
73 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
73 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
74 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
74 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
75 map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
75 map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
76 map.permission :delete_issues, {:issues => :destroy}, :require => :member
76 map.permission :delete_issues, {:issues => :destroy}, :require => :member
77 # Queries
77 # Queries
78 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
78 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
79 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
79 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
80 # Watchers
80 # Watchers
81 map.permission :view_issue_watchers, {}
81 map.permission :view_issue_watchers, {}
82 map.permission :add_issue_watchers, {:watchers => :new}
82 map.permission :add_issue_watchers, {:watchers => :new}
83 map.permission :delete_issue_watchers, {:watchers => :destroy}
83 map.permission :delete_issue_watchers, {:watchers => :destroy}
84 end
84 end
85
85
86 map.project_module :time_tracking do |map|
86 map.project_module :time_tracking do |map|
87 map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin
87 map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin
88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member
89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member
90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
92 end
92 end
93
93
94 map.project_module :news do |map|
94 map.project_module :news do |map|
95 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
95 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
96 map.permission :view_news, {:news => [:index, :show]}, :public => true
96 map.permission :view_news, {:news => [:index, :show]}, :public => true
97 map.permission :comment_news, {:comments => :create}
97 map.permission :comment_news, {:comments => :create}
98 end
98 end
99
99
100 map.project_module :documents do |map|
100 map.project_module :documents do |map|
101 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
101 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment]}, :require => :loggedin
102 map.permission :view_documents, :documents => [:index, :show, :download]
102 map.permission :view_documents, :documents => [:index, :show, :download]
103 end
103 end
104
104
105 map.project_module :files do |map|
105 map.project_module :files do |map|
106 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
106 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
107 map.permission :view_files, :files => :index, :versions => :download
107 map.permission :view_files, :files => :index, :versions => :download
108 end
108 end
109
109
110 map.project_module :wiki do |map|
110 map.project_module :wiki do |map|
111 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
111 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
112 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
112 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
113 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
113 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
114 map.permission :view_wiki_pages, :wiki => [:index, :show, :special, :date_index]
114 map.permission :view_wiki_pages, :wiki => [:index, :show, :special, :date_index]
115 map.permission :export_wiki_pages, :wiki => [:export]
115 map.permission :export_wiki_pages, :wiki => [:export]
116 map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
116 map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
117 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
117 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
118 map.permission :delete_wiki_pages_attachments, {}
118 map.permission :delete_wiki_pages_attachments, {}
119 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
119 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
120 end
120 end
121
121
122 map.project_module :repository do |map|
122 map.project_module :repository do |map|
123 map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member
123 map.permission :manage_repository, {:repositories => [:edit, :committers, :destroy]}, :require => :member
124 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
124 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
125 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
125 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
126 map.permission :commit_access, {}
126 map.permission :commit_access, {}
127 end
127 end
128
128
129 map.project_module :boards do |map|
129 map.project_module :boards do |map|
130 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
130 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
131 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
131 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
132 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
132 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
133 map.permission :edit_messages, {:messages => :edit}, :require => :member
133 map.permission :edit_messages, {:messages => :edit}, :require => :member
134 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
134 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
135 map.permission :delete_messages, {:messages => :destroy}, :require => :member
135 map.permission :delete_messages, {:messages => :destroy}, :require => :member
136 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
136 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
137 end
137 end
138
138
139 map.project_module :calendar do |map|
139 map.project_module :calendar do |map|
140 map.permission :view_calendar, :calendars => [:show, :update]
140 map.permission :view_calendar, :calendars => [:show, :update]
141 end
141 end
142
142
143 map.project_module :gantt do |map|
143 map.project_module :gantt do |map|
144 map.permission :view_gantt, :gantts => [:show, :update]
144 map.permission :view_gantt, :gantts => [:show, :update]
145 end
145 end
146 end
146 end
147
147
148 Redmine::MenuManager.map :top_menu do |menu|
148 Redmine::MenuManager.map :top_menu do |menu|
149 menu.push :home, :home_path
149 menu.push :home, :home_path
150 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
150 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
151 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
151 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
152 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
152 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
153 menu.push :help, Redmine::Info.help_url, :last => true
153 menu.push :help, Redmine::Info.help_url, :last => true
154 end
154 end
155
155
156 Redmine::MenuManager.map :account_menu do |menu|
156 Redmine::MenuManager.map :account_menu do |menu|
157 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
157 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
158 menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
158 menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
159 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
159 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
160 menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
160 menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
161 end
161 end
162
162
163 Redmine::MenuManager.map :application_menu do |menu|
163 Redmine::MenuManager.map :application_menu do |menu|
164 # Empty
164 # Empty
165 end
165 end
166
166
167 Redmine::MenuManager.map :admin_menu do |menu|
167 Redmine::MenuManager.map :admin_menu do |menu|
168 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
168 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
169 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
169 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
170 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
170 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
171 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
171 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
172 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
172 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
173 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
173 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
174 :html => {:class => 'issue_statuses'}
174 :html => {:class => 'issue_statuses'}
175 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
175 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
176 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
176 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
177 :html => {:class => 'custom_fields'}
177 :html => {:class => 'custom_fields'}
178 menu.push :enumerations, {:controller => 'enumerations'}
178 menu.push :enumerations, {:controller => 'enumerations'}
179 menu.push :settings, {:controller => 'settings'}
179 menu.push :settings, {:controller => 'settings'}
180 menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'},
180 menu.push :ldap_authentication, {:controller => 'ldap_auth_sources', :action => 'index'},
181 :html => {:class => 'server_authentication'}
181 :html => {:class => 'server_authentication'}
182 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
182 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
183 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
183 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
184 end
184 end
185
185
186 Redmine::MenuManager.map :project_menu do |menu|
186 Redmine::MenuManager.map :project_menu do |menu|
187 menu.push :overview, { :controller => 'projects', :action => 'show' }
187 menu.push :overview, { :controller => 'projects', :action => 'show' }
188 menu.push :activity, { :controller => 'activities', :action => 'index' }
188 menu.push :activity, { :controller => 'activities', :action => 'index' }
189 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
189 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
190 :if => Proc.new { |p| p.shared_versions.any? }
190 :if => Proc.new { |p| p.shared_versions.any? }
191 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
191 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
192 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
192 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
193 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
193 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
194 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
194 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
195 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
195 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
196 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
196 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
197 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
197 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
198 menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
198 menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
199 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
199 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
200 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
200 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
201 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
201 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
202 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
202 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
203 menu.push :repository, { :controller => 'repositories', :action => 'show' },
203 menu.push :repository, { :controller => 'repositories', :action => 'show' },
204 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
204 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
205 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
205 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
206 end
206 end
207
207
208 Redmine::Activity.map do |activity|
208 Redmine::Activity.map do |activity|
209 activity.register :issues, :class_name => %w(Issue Journal)
209 activity.register :issues, :class_name => %w(Issue Journal)
210 activity.register :changesets
210 activity.register :changesets
211 activity.register :news
211 activity.register :news
212 activity.register :documents, :class_name => %w(Document Attachment)
212 activity.register :documents, :class_name => %w(Document Attachment)
213 activity.register :files, :class_name => 'Attachment'
213 activity.register :files, :class_name => 'Attachment'
214 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
214 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
215 activity.register :messages, :default => false
215 activity.register :messages, :default => false
216 activity.register :time_entries, :default => false
216 activity.register :time_entries, :default => false
217 end
217 end
218
218
219 Redmine::Search.map do |search|
219 Redmine::Search.map do |search|
220 search.register :issues
220 search.register :issues
221 search.register :news
221 search.register :news
222 search.register :documents
222 search.register :documents
223 search.register :changesets
223 search.register :changesets
224 search.register :wiki_pages
224 search.register :wiki_pages
225 search.register :messages
225 search.register :messages
226 search.register :projects
226 search.register :projects
227 end
227 end
228
228
229 Redmine::WikiFormatting.map do |format|
229 Redmine::WikiFormatting.map do |format|
230 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
230 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
231 end
231 end
232
233 ActionView::Template.register_template_handler :apit, Redmine::Views::ApiTemplateHandler
General Comments 0
You need to be logged in to leave comments. Login now