##// END OF EJS Templates
Replaces the obsolete robots.txt with a cached action (#2491)....
Jean-Philippe Lang -
r2317:e1f96ca4db64
parent child
Show More
@@ -0,0 +1,9
1 User-agent: *
2 <% @projects.each do |p| -%>
3 Disallow: /projects/<%= p.to_param %>/repository
4 Disallow: /projects/<%= p.to_param %>/issues
5 Disallow: /projects/<%= p.to_param %>/activity
6 <% end -%>
7 Disallow: /issues/gantt
8 Disallow: /issues/calendar
9 Disallow: /activity
@@ -1,290 +1,296
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 menu_item :overview
19 menu_item :overview
20 menu_item :activity, :only => :activity
20 menu_item :activity, :only => :activity
21 menu_item :roadmap, :only => :roadmap
21 menu_item :roadmap, :only => :roadmap
22 menu_item :files, :only => [:list_files, :add_file]
22 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :settings, :only => :settings
23 menu_item :settings, :only => :settings
24 menu_item :issues, :only => [:changelog]
24 menu_item :issues, :only => [:changelog]
25
25
26 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
26 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
27 before_filter :find_optional_project, :only => :activity
27 before_filter :find_optional_project, :only => :activity
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
30 accept_key_auth :activity
30 accept_key_auth :activity
31
31
32 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
33 if controller.request.post?
34 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
35 end
36 end
37
32 helper :sort
38 helper :sort
33 include SortHelper
39 include SortHelper
34 helper :custom_fields
40 helper :custom_fields
35 include CustomFieldsHelper
41 include CustomFieldsHelper
36 helper :issues
42 helper :issues
37 helper IssuesHelper
43 helper IssuesHelper
38 helper :queries
44 helper :queries
39 include QueriesHelper
45 include QueriesHelper
40 helper :repositories
46 helper :repositories
41 include RepositoriesHelper
47 include RepositoriesHelper
42 include ProjectsHelper
48 include ProjectsHelper
43
49
44 # Lists visible projects
50 # Lists visible projects
45 def index
51 def index
46 respond_to do |format|
52 respond_to do |format|
47 format.html {
53 format.html {
48 @projects = Project.visible.find(:all, :order => 'lft')
54 @projects = Project.visible.find(:all, :order => 'lft')
49 }
55 }
50 format.atom {
56 format.atom {
51 projects = Project.visible.find(:all, :order => 'created_on DESC',
57 projects = Project.visible.find(:all, :order => 'created_on DESC',
52 :limit => Setting.feeds_limit.to_i)
58 :limit => Setting.feeds_limit.to_i)
53 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
59 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
54 }
60 }
55 end
61 end
56 end
62 end
57
63
58 # Add a new project
64 # Add a new project
59 def add
65 def add
60 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
61 @trackers = Tracker.all
67 @trackers = Tracker.all
62 @project = Project.new(params[:project])
68 @project = Project.new(params[:project])
63 if request.get?
69 if request.get?
64 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
70 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
65 @project.trackers = Tracker.all
71 @project.trackers = Tracker.all
66 @project.is_public = Setting.default_projects_public?
72 @project.is_public = Setting.default_projects_public?
67 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
73 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
68 else
74 else
69 @project.enabled_module_names = params[:enabled_modules]
75 @project.enabled_module_names = params[:enabled_modules]
70 if @project.save
76 if @project.save
71 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
77 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
72 flash[:notice] = l(:notice_successful_create)
78 flash[:notice] = l(:notice_successful_create)
73 redirect_to :controller => 'admin', :action => 'projects'
79 redirect_to :controller => 'admin', :action => 'projects'
74 end
80 end
75 end
81 end
76 end
82 end
77
83
78 # Show @project
84 # Show @project
79 def show
85 def show
80 if params[:jump]
86 if params[:jump]
81 # try to redirect to the requested menu item
87 # try to redirect to the requested menu item
82 redirect_to_project_menu_item(@project, params[:jump]) && return
88 redirect_to_project_menu_item(@project, params[:jump]) && return
83 end
89 end
84
90
85 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
91 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
86 @subprojects = @project.children.visible
92 @subprojects = @project.children.visible
87 @ancestors = @project.ancestors.visible
93 @ancestors = @project.ancestors.visible
88 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
94 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
89 @trackers = @project.rolled_up_trackers
95 @trackers = @project.rolled_up_trackers
90
96
91 cond = @project.project_condition(Setting.display_subprojects_issues?)
97 cond = @project.project_condition(Setting.display_subprojects_issues?)
92 Issue.visible_by(User.current) do
98 Issue.visible_by(User.current) do
93 @open_issues_by_tracker = Issue.count(:group => :tracker,
99 @open_issues_by_tracker = Issue.count(:group => :tracker,
94 :include => [:project, :status, :tracker],
100 :include => [:project, :status, :tracker],
95 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
101 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
96 @total_issues_by_tracker = Issue.count(:group => :tracker,
102 @total_issues_by_tracker = Issue.count(:group => :tracker,
97 :include => [:project, :status, :tracker],
103 :include => [:project, :status, :tracker],
98 :conditions => cond)
104 :conditions => cond)
99 end
105 end
100 TimeEntry.visible_by(User.current) do
106 TimeEntry.visible_by(User.current) do
101 @total_hours = TimeEntry.sum(:hours,
107 @total_hours = TimeEntry.sum(:hours,
102 :include => :project,
108 :include => :project,
103 :conditions => cond).to_f
109 :conditions => cond).to_f
104 end
110 end
105 @key = User.current.rss_key
111 @key = User.current.rss_key
106 end
112 end
107
113
108 def settings
114 def settings
109 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
115 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
110 @issue_category ||= IssueCategory.new
116 @issue_category ||= IssueCategory.new
111 @member ||= @project.members.new
117 @member ||= @project.members.new
112 @trackers = Tracker.all
118 @trackers = Tracker.all
113 @repository ||= @project.repository
119 @repository ||= @project.repository
114 @wiki ||= @project.wiki
120 @wiki ||= @project.wiki
115 end
121 end
116
122
117 # Edit @project
123 # Edit @project
118 def edit
124 def edit
119 if request.post?
125 if request.post?
120 @project.attributes = params[:project]
126 @project.attributes = params[:project]
121 if @project.save
127 if @project.save
122 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
128 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
123 flash[:notice] = l(:notice_successful_update)
129 flash[:notice] = l(:notice_successful_update)
124 redirect_to :action => 'settings', :id => @project
130 redirect_to :action => 'settings', :id => @project
125 else
131 else
126 settings
132 settings
127 render :action => 'settings'
133 render :action => 'settings'
128 end
134 end
129 end
135 end
130 end
136 end
131
137
132 def modules
138 def modules
133 @project.enabled_module_names = params[:enabled_modules]
139 @project.enabled_module_names = params[:enabled_modules]
134 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
140 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
135 end
141 end
136
142
137 def archive
143 def archive
138 @project.archive if request.post? && @project.active?
144 @project.archive if request.post? && @project.active?
139 redirect_to :controller => 'admin', :action => 'projects'
145 redirect_to :controller => 'admin', :action => 'projects'
140 end
146 end
141
147
142 def unarchive
148 def unarchive
143 @project.unarchive if request.post? && !@project.active?
149 @project.unarchive if request.post? && !@project.active?
144 redirect_to :controller => 'admin', :action => 'projects'
150 redirect_to :controller => 'admin', :action => 'projects'
145 end
151 end
146
152
147 # Delete @project
153 # Delete @project
148 def destroy
154 def destroy
149 @project_to_destroy = @project
155 @project_to_destroy = @project
150 if request.post? and params[:confirm]
156 if request.post? and params[:confirm]
151 @project_to_destroy.destroy
157 @project_to_destroy.destroy
152 redirect_to :controller => 'admin', :action => 'projects'
158 redirect_to :controller => 'admin', :action => 'projects'
153 end
159 end
154 # hide project in layout
160 # hide project in layout
155 @project = nil
161 @project = nil
156 end
162 end
157
163
158 # Add a new issue category to @project
164 # Add a new issue category to @project
159 def add_issue_category
165 def add_issue_category
160 @category = @project.issue_categories.build(params[:category])
166 @category = @project.issue_categories.build(params[:category])
161 if request.post? and @category.save
167 if request.post? and @category.save
162 respond_to do |format|
168 respond_to do |format|
163 format.html do
169 format.html do
164 flash[:notice] = l(:notice_successful_create)
170 flash[:notice] = l(:notice_successful_create)
165 redirect_to :action => 'settings', :tab => 'categories', :id => @project
171 redirect_to :action => 'settings', :tab => 'categories', :id => @project
166 end
172 end
167 format.js do
173 format.js do
168 # IE doesn't support the replace_html rjs method for select box options
174 # IE doesn't support the replace_html rjs method for select box options
169 render(:update) {|page| page.replace "issue_category_id",
175 render(:update) {|page| page.replace "issue_category_id",
170 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]')
176 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]')
171 }
177 }
172 end
178 end
173 end
179 end
174 end
180 end
175 end
181 end
176
182
177 # Add a new version to @project
183 # Add a new version to @project
178 def add_version
184 def add_version
179 @version = @project.versions.build(params[:version])
185 @version = @project.versions.build(params[:version])
180 if request.post? and @version.save
186 if request.post? and @version.save
181 flash[:notice] = l(:notice_successful_create)
187 flash[:notice] = l(:notice_successful_create)
182 redirect_to :action => 'settings', :tab => 'versions', :id => @project
188 redirect_to :action => 'settings', :tab => 'versions', :id => @project
183 end
189 end
184 end
190 end
185
191
186 def add_file
192 def add_file
187 if request.post?
193 if request.post?
188 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
194 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
189 attachments = attach_files(container, params[:attachments])
195 attachments = attach_files(container, params[:attachments])
190 if !attachments.empty? && Setting.notified_events.include?('file_added')
196 if !attachments.empty? && Setting.notified_events.include?('file_added')
191 Mailer.deliver_attachments_added(attachments)
197 Mailer.deliver_attachments_added(attachments)
192 end
198 end
193 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
199 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
194 return
200 return
195 end
201 end
196 @versions = @project.versions.sort
202 @versions = @project.versions.sort
197 end
203 end
198
204
199 def list_files
205 def list_files
200 sort_init 'filename', 'asc'
206 sort_init 'filename', 'asc'
201 sort_update 'filename' => "#{Attachment.table_name}.filename",
207 sort_update 'filename' => "#{Attachment.table_name}.filename",
202 'created_on' => "#{Attachment.table_name}.created_on",
208 'created_on' => "#{Attachment.table_name}.created_on",
203 'size' => "#{Attachment.table_name}.filesize",
209 'size' => "#{Attachment.table_name}.filesize",
204 'downloads' => "#{Attachment.table_name}.downloads"
210 'downloads' => "#{Attachment.table_name}.downloads"
205
211
206 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
212 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
207 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
213 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
208 render :layout => !request.xhr?
214 render :layout => !request.xhr?
209 end
215 end
210
216
211 # Show changelog for @project
217 # Show changelog for @project
212 def changelog
218 def changelog
213 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
219 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
214 retrieve_selected_tracker_ids(@trackers)
220 retrieve_selected_tracker_ids(@trackers)
215 @versions = @project.versions.sort
221 @versions = @project.versions.sort
216 end
222 end
217
223
218 def roadmap
224 def roadmap
219 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
225 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
220 retrieve_selected_tracker_ids(@trackers)
226 retrieve_selected_tracker_ids(@trackers)
221 @versions = @project.versions.sort
227 @versions = @project.versions.sort
222 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
228 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
223 end
229 end
224
230
225 def activity
231 def activity
226 @days = Setting.activity_days_default.to_i
232 @days = Setting.activity_days_default.to_i
227
233
228 if params[:from]
234 if params[:from]
229 begin; @date_to = params[:from].to_date + 1; rescue; end
235 begin; @date_to = params[:from].to_date + 1; rescue; end
230 end
236 end
231
237
232 @date_to ||= Date.today + 1
238 @date_to ||= Date.today + 1
233 @date_from = @date_to - @days
239 @date_from = @date_to - @days
234 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
240 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
235 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
241 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
236
242
237 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
243 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
238 :with_subprojects => @with_subprojects,
244 :with_subprojects => @with_subprojects,
239 :author => @author)
245 :author => @author)
240 @activity.scope_select {|t| !params["show_#{t}"].nil?}
246 @activity.scope_select {|t| !params["show_#{t}"].nil?}
241 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
247 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
242
248
243 events = @activity.events(@date_from, @date_to)
249 events = @activity.events(@date_from, @date_to)
244
250
245 respond_to do |format|
251 respond_to do |format|
246 format.html {
252 format.html {
247 @events_by_day = events.group_by(&:event_date)
253 @events_by_day = events.group_by(&:event_date)
248 render :layout => false if request.xhr?
254 render :layout => false if request.xhr?
249 }
255 }
250 format.atom {
256 format.atom {
251 title = l(:label_activity)
257 title = l(:label_activity)
252 if @author
258 if @author
253 title = @author.name
259 title = @author.name
254 elsif @activity.scope.size == 1
260 elsif @activity.scope.size == 1
255 title = l("label_#{@activity.scope.first.singularize}_plural")
261 title = l("label_#{@activity.scope.first.singularize}_plural")
256 end
262 end
257 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
263 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
258 }
264 }
259 end
265 end
260
266
261 rescue ActiveRecord::RecordNotFound
267 rescue ActiveRecord::RecordNotFound
262 render_404
268 render_404
263 end
269 end
264
270
265 private
271 private
266 # Find project of id params[:id]
272 # Find project of id params[:id]
267 # if not found, redirect to project list
273 # if not found, redirect to project list
268 # Used as a before_filter
274 # Used as a before_filter
269 def find_project
275 def find_project
270 @project = Project.find(params[:id])
276 @project = Project.find(params[:id])
271 rescue ActiveRecord::RecordNotFound
277 rescue ActiveRecord::RecordNotFound
272 render_404
278 render_404
273 end
279 end
274
280
275 def find_optional_project
281 def find_optional_project
276 return true unless params[:id]
282 return true unless params[:id]
277 @project = Project.find(params[:id])
283 @project = Project.find(params[:id])
278 authorize
284 authorize
279 rescue ActiveRecord::RecordNotFound
285 rescue ActiveRecord::RecordNotFound
280 render_404
286 render_404
281 end
287 end
282
288
283 def retrieve_selected_tracker_ids(selectable_trackers)
289 def retrieve_selected_tracker_ids(selectable_trackers)
284 if ids = params[:tracker_ids]
290 if ids = params[:tracker_ids]
285 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
291 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
286 else
292 else
287 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
293 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
288 end
294 end
289 end
295 end
290 end
296 end
@@ -1,24 +1,30
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class WelcomeController < ApplicationController
18 class WelcomeController < ApplicationController
19 caches_action :robots
19
20
20 def index
21 def index
21 @news = News.latest User.current
22 @news = News.latest User.current
22 @projects = Project.latest User.current
23 @projects = Project.latest User.current
23 end
24 end
25
26 def robots
27 @projects = Project.public.active
28 render :layout => false, :content_type => 'text/plain'
29 end
24 end
30 end
@@ -1,318 +1,319
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Project < ActiveRecord::Base
18 class Project < ActiveRecord::Base
19 # Project statuses
19 # Project statuses
20 STATUS_ACTIVE = 1
20 STATUS_ACTIVE = 1
21 STATUS_ARCHIVED = 9
21 STATUS_ARCHIVED = 9
22
22
23 has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
23 has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
24 has_many :users, :through => :members
24 has_many :users, :through => :members
25 has_many :enabled_modules, :dependent => :delete_all
25 has_many :enabled_modules, :dependent => :delete_all
26 has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
26 has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
27 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
27 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
28 has_many :issue_changes, :through => :issues, :source => :journals
28 has_many :issue_changes, :through => :issues, :source => :journals
29 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
29 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
30 has_many :time_entries, :dependent => :delete_all
30 has_many :time_entries, :dependent => :delete_all
31 has_many :queries, :dependent => :delete_all
31 has_many :queries, :dependent => :delete_all
32 has_many :documents, :dependent => :destroy
32 has_many :documents, :dependent => :destroy
33 has_many :news, :dependent => :delete_all, :include => :author
33 has_many :news, :dependent => :delete_all, :include => :author
34 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
34 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
35 has_many :boards, :dependent => :destroy, :order => "position ASC"
35 has_many :boards, :dependent => :destroy, :order => "position ASC"
36 has_one :repository, :dependent => :destroy
36 has_one :repository, :dependent => :destroy
37 has_many :changesets, :through => :repository
37 has_many :changesets, :through => :repository
38 has_one :wiki, :dependent => :destroy
38 has_one :wiki, :dependent => :destroy
39 # Custom field for the project issues
39 # Custom field for the project issues
40 has_and_belongs_to_many :issue_custom_fields,
40 has_and_belongs_to_many :issue_custom_fields,
41 :class_name => 'IssueCustomField',
41 :class_name => 'IssueCustomField',
42 :order => "#{CustomField.table_name}.position",
42 :order => "#{CustomField.table_name}.position",
43 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
43 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
44 :association_foreign_key => 'custom_field_id'
44 :association_foreign_key => 'custom_field_id'
45
45
46 acts_as_nested_set :order => 'name', :dependent => :destroy
46 acts_as_nested_set :order => 'name', :dependent => :destroy
47 acts_as_attachable :view_permission => :view_files,
47 acts_as_attachable :view_permission => :view_files,
48 :delete_permission => :manage_files
48 :delete_permission => :manage_files
49
49
50 acts_as_customizable
50 acts_as_customizable
51 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil
51 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil
52 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
52 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
53 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}},
53 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}},
54 :author => nil
54 :author => nil
55
55
56 attr_protected :status, :enabled_module_names
56 attr_protected :status, :enabled_module_names
57
57
58 validates_presence_of :name, :identifier
58 validates_presence_of :name, :identifier
59 validates_uniqueness_of :name, :identifier
59 validates_uniqueness_of :name, :identifier
60 validates_associated :repository, :wiki
60 validates_associated :repository, :wiki
61 validates_length_of :name, :maximum => 30
61 validates_length_of :name, :maximum => 30
62 validates_length_of :homepage, :maximum => 255
62 validates_length_of :homepage, :maximum => 255
63 validates_length_of :identifier, :in => 2..20
63 validates_length_of :identifier, :in => 2..20
64 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
64 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
65
65
66 before_destroy :delete_all_members
66 before_destroy :delete_all_members
67
67
68 named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
68 named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
69 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
69 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
70 named_scope :public, { :conditions => { :is_public => true } }
70 named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
71 named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
71
72
72 def identifier=(identifier)
73 def identifier=(identifier)
73 super unless identifier_frozen?
74 super unless identifier_frozen?
74 end
75 end
75
76
76 def identifier_frozen?
77 def identifier_frozen?
77 errors[:identifier].nil? && !(new_record? || identifier.blank?)
78 errors[:identifier].nil? && !(new_record? || identifier.blank?)
78 end
79 end
79
80
80 def issues_with_subprojects(include_subprojects=false)
81 def issues_with_subprojects(include_subprojects=false)
81 conditions = nil
82 conditions = nil
82 if include_subprojects
83 if include_subprojects
83 ids = [id] + descendants.collect(&:id)
84 ids = [id] + descendants.collect(&:id)
84 conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"]
85 conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"]
85 end
86 end
86 conditions ||= ["#{Project.table_name}.id = ?", id]
87 conditions ||= ["#{Project.table_name}.id = ?", id]
87 # Quick and dirty fix for Rails 2 compatibility
88 # Quick and dirty fix for Rails 2 compatibility
88 Issue.send(:with_scope, :find => { :conditions => conditions }) do
89 Issue.send(:with_scope, :find => { :conditions => conditions }) do
89 Version.send(:with_scope, :find => { :conditions => conditions }) do
90 Version.send(:with_scope, :find => { :conditions => conditions }) do
90 yield
91 yield
91 end
92 end
92 end
93 end
93 end
94 end
94
95
95 # returns latest created projects
96 # returns latest created projects
96 # non public projects will be returned only if user is a member of those
97 # non public projects will be returned only if user is a member of those
97 def self.latest(user=nil, count=5)
98 def self.latest(user=nil, count=5)
98 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
99 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
99 end
100 end
100
101
101 def self.visible_by(user=nil)
102 def self.visible_by(user=nil)
102 user ||= User.current
103 user ||= User.current
103 if user && user.admin?
104 if user && user.admin?
104 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
105 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
105 elsif user && user.memberships.any?
106 elsif user && user.memberships.any?
106 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
107 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
107 else
108 else
108 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
109 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
109 end
110 end
110 end
111 end
111
112
112 def self.allowed_to_condition(user, permission, options={})
113 def self.allowed_to_condition(user, permission, options={})
113 statements = []
114 statements = []
114 base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
115 base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
115 if perm = Redmine::AccessControl.permission(permission)
116 if perm = Redmine::AccessControl.permission(permission)
116 unless perm.project_module.nil?
117 unless perm.project_module.nil?
117 # If the permission belongs to a project module, make sure the module is enabled
118 # If the permission belongs to a project module, make sure the module is enabled
118 base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)"
119 base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)"
119 end
120 end
120 end
121 end
121 if options[:project]
122 if options[:project]
122 project_statement = "#{Project.table_name}.id = #{options[:project].id}"
123 project_statement = "#{Project.table_name}.id = #{options[:project].id}"
123 project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
124 project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
124 base_statement = "(#{project_statement}) AND (#{base_statement})"
125 base_statement = "(#{project_statement}) AND (#{base_statement})"
125 end
126 end
126 if user.admin?
127 if user.admin?
127 # no restriction
128 # no restriction
128 else
129 else
129 statements << "1=0"
130 statements << "1=0"
130 if user.logged?
131 if user.logged?
131 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
132 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
132 allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
133 allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
133 statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
134 statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
134 elsif Role.anonymous.allowed_to?(permission)
135 elsif Role.anonymous.allowed_to?(permission)
135 # anonymous user allowed on public project
136 # anonymous user allowed on public project
136 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
137 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
137 else
138 else
138 # anonymous user is not authorized
139 # anonymous user is not authorized
139 end
140 end
140 end
141 end
141 statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
142 statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
142 end
143 end
143
144
144 def project_condition(with_subprojects)
145 def project_condition(with_subprojects)
145 cond = "#{Project.table_name}.id = #{id}"
146 cond = "#{Project.table_name}.id = #{id}"
146 cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
147 cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
147 cond
148 cond
148 end
149 end
149
150
150 def self.find(*args)
151 def self.find(*args)
151 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
152 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
152 project = find_by_identifier(*args)
153 project = find_by_identifier(*args)
153 raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
154 raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil?
154 project
155 project
155 else
156 else
156 super
157 super
157 end
158 end
158 end
159 end
159
160
160 def to_param
161 def to_param
161 # id is used for projects with a numeric identifier (compatibility)
162 # id is used for projects with a numeric identifier (compatibility)
162 @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
163 @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
163 end
164 end
164
165
165 def active?
166 def active?
166 self.status == STATUS_ACTIVE
167 self.status == STATUS_ACTIVE
167 end
168 end
168
169
169 # Archives the project and its descendants recursively
170 # Archives the project and its descendants recursively
170 def archive
171 def archive
171 # Archive subprojects if any
172 # Archive subprojects if any
172 children.each do |subproject|
173 children.each do |subproject|
173 subproject.archive
174 subproject.archive
174 end
175 end
175 update_attribute :status, STATUS_ARCHIVED
176 update_attribute :status, STATUS_ARCHIVED
176 end
177 end
177
178
178 # Unarchives the project
179 # Unarchives the project
179 # All its ancestors must be active
180 # All its ancestors must be active
180 def unarchive
181 def unarchive
181 return false if ancestors.detect {|a| !a.active?}
182 return false if ancestors.detect {|a| !a.active?}
182 update_attribute :status, STATUS_ACTIVE
183 update_attribute :status, STATUS_ACTIVE
183 end
184 end
184
185
185 # Returns an array of projects the project can be moved to
186 # Returns an array of projects the project can be moved to
186 def possible_parents
187 def possible_parents
187 @possible_parents ||= (Project.active.find(:all) - self_and_descendants)
188 @possible_parents ||= (Project.active.find(:all) - self_and_descendants)
188 end
189 end
189
190
190 # Sets the parent of the project
191 # Sets the parent of the project
191 # Argument can be either a Project, a String, a Fixnum or nil
192 # Argument can be either a Project, a String, a Fixnum or nil
192 def set_parent!(p)
193 def set_parent!(p)
193 unless p.nil? || p.is_a?(Project)
194 unless p.nil? || p.is_a?(Project)
194 if p.to_s.blank?
195 if p.to_s.blank?
195 p = nil
196 p = nil
196 else
197 else
197 p = Project.find_by_id(p)
198 p = Project.find_by_id(p)
198 return false unless p
199 return false unless p
199 end
200 end
200 end
201 end
201 if p == parent && !p.nil?
202 if p == parent && !p.nil?
202 # Nothing to do
203 # Nothing to do
203 true
204 true
204 elsif p.nil? || (p.active? && move_possible?(p))
205 elsif p.nil? || (p.active? && move_possible?(p))
205 # Insert the project so that target's children or root projects stay alphabetically sorted
206 # Insert the project so that target's children or root projects stay alphabetically sorted
206 sibs = (p.nil? ? self.class.roots : p.children)
207 sibs = (p.nil? ? self.class.roots : p.children)
207 to_be_inserted_before = sibs.detect {|c| c.name.to_s.downcase > name.to_s.downcase }
208 to_be_inserted_before = sibs.detect {|c| c.name.to_s.downcase > name.to_s.downcase }
208 if to_be_inserted_before
209 if to_be_inserted_before
209 move_to_left_of(to_be_inserted_before)
210 move_to_left_of(to_be_inserted_before)
210 elsif p.nil?
211 elsif p.nil?
211 if sibs.empty?
212 if sibs.empty?
212 # move_to_root adds the project in first (ie. left) position
213 # move_to_root adds the project in first (ie. left) position
213 move_to_root
214 move_to_root
214 else
215 else
215 move_to_right_of(sibs.last) unless self == sibs.last
216 move_to_right_of(sibs.last) unless self == sibs.last
216 end
217 end
217 else
218 else
218 # move_to_child_of adds the project in last (ie.right) position
219 # move_to_child_of adds the project in last (ie.right) position
219 move_to_child_of(p)
220 move_to_child_of(p)
220 end
221 end
221 true
222 true
222 else
223 else
223 # Can not move to the given target
224 # Can not move to the given target
224 false
225 false
225 end
226 end
226 end
227 end
227
228
228 # Returns an array of the trackers used by the project and its active sub projects
229 # Returns an array of the trackers used by the project and its active sub projects
229 def rolled_up_trackers
230 def rolled_up_trackers
230 @rolled_up_trackers ||=
231 @rolled_up_trackers ||=
231 Tracker.find(:all, :include => :projects,
232 Tracker.find(:all, :include => :projects,
232 :select => "DISTINCT #{Tracker.table_name}.*",
233 :select => "DISTINCT #{Tracker.table_name}.*",
233 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
234 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
234 :order => "#{Tracker.table_name}.position")
235 :order => "#{Tracker.table_name}.position")
235 end
236 end
236
237
237 # Deletes all project's members
238 # Deletes all project's members
238 def delete_all_members
239 def delete_all_members
239 Member.delete_all(['project_id = ?', id])
240 Member.delete_all(['project_id = ?', id])
240 end
241 end
241
242
242 # Users issues can be assigned to
243 # Users issues can be assigned to
243 def assignable_users
244 def assignable_users
244 members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
245 members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort
245 end
246 end
246
247
247 # Returns the mail adresses of users that should be always notified on project events
248 # Returns the mail adresses of users that should be always notified on project events
248 def recipients
249 def recipients
249 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
250 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
250 end
251 end
251
252
252 # Returns an array of all custom fields enabled for project issues
253 # Returns an array of all custom fields enabled for project issues
253 # (explictly associated custom fields and custom fields enabled for all projects)
254 # (explictly associated custom fields and custom fields enabled for all projects)
254 def all_issue_custom_fields
255 def all_issue_custom_fields
255 @all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
256 @all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
256 end
257 end
257
258
258 def project
259 def project
259 self
260 self
260 end
261 end
261
262
262 def <=>(project)
263 def <=>(project)
263 name.downcase <=> project.name.downcase
264 name.downcase <=> project.name.downcase
264 end
265 end
265
266
266 def to_s
267 def to_s
267 name
268 name
268 end
269 end
269
270
270 # Returns a short description of the projects (first lines)
271 # Returns a short description of the projects (first lines)
271 def short_description(length = 255)
272 def short_description(length = 255)
272 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
273 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
273 end
274 end
274
275
275 def allows_to?(action)
276 def allows_to?(action)
276 if action.is_a? Hash
277 if action.is_a? Hash
277 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
278 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
278 else
279 else
279 allowed_permissions.include? action
280 allowed_permissions.include? action
280 end
281 end
281 end
282 end
282
283
283 def module_enabled?(module_name)
284 def module_enabled?(module_name)
284 module_name = module_name.to_s
285 module_name = module_name.to_s
285 enabled_modules.detect {|m| m.name == module_name}
286 enabled_modules.detect {|m| m.name == module_name}
286 end
287 end
287
288
288 def enabled_module_names=(module_names)
289 def enabled_module_names=(module_names)
289 enabled_modules.clear
290 enabled_modules.clear
290 module_names = [] unless module_names && module_names.is_a?(Array)
291 module_names = [] unless module_names && module_names.is_a?(Array)
291 module_names.each do |name|
292 module_names.each do |name|
292 enabled_modules << EnabledModule.new(:name => name.to_s)
293 enabled_modules << EnabledModule.new(:name => name.to_s)
293 end
294 end
294 end
295 end
295
296
296 # Returns an auto-generated project identifier based on the last identifier used
297 # Returns an auto-generated project identifier based on the last identifier used
297 def self.next_identifier
298 def self.next_identifier
298 p = Project.find(:first, :order => 'created_on DESC')
299 p = Project.find(:first, :order => 'created_on DESC')
299 p.nil? ? nil : p.identifier.to_s.succ
300 p.nil? ? nil : p.identifier.to_s.succ
300 end
301 end
301
302
302 protected
303 protected
303 def validate
304 def validate
304 errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
305 errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
305 end
306 end
306
307
307 private
308 private
308 def allowed_permissions
309 def allowed_permissions
309 @allowed_permissions ||= begin
310 @allowed_permissions ||= begin
310 module_names = enabled_modules.collect {|m| m.name}
311 module_names = enabled_modules.collect {|m| m.name}
311 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
312 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
312 end
313 end
313 end
314 end
314
315
315 def allowed_actions
316 def allowed_actions
316 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
317 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
317 end
318 end
318 end
319 end
@@ -1,253 +1,254
1 ActionController::Routing::Routes.draw do |map|
1 ActionController::Routing::Routes.draw do |map|
2 # Add your own custom routes here.
2 # Add your own custom routes here.
3 # The priority is based upon order of creation: first created -> highest priority.
3 # The priority is based upon order of creation: first created -> highest priority.
4
4
5 # Here's a sample route:
5 # Here's a sample route:
6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 # Keep in mind you can assign values other than :controller and :action
7 # Keep in mind you can assign values other than :controller and :action
8
8
9 # Allow Redmine plugins to map routes and potentially override them
9 # Allow Redmine plugins to map routes and potentially override them
10 Rails.plugins.each do |plugin|
10 Rails.plugins.each do |plugin|
11 map.from_plugin plugin.name.to_sym
11 map.from_plugin plugin.name.to_sym
12 end
12 end
13
13
14 map.home '', :controller => 'welcome'
14 map.home '', :controller => 'welcome'
15
15
16 map.signin 'login', :controller => 'account', :action => 'login'
16 map.signin 'login', :controller => 'account', :action => 'login'
17 map.signout 'logout', :controller => 'account', :action => 'logout'
17 map.signout 'logout', :controller => 'account', :action => 'logout'
18
18
19 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
19 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
20 map.connect 'help/:ctrl/:page', :controller => 'help'
20 map.connect 'help/:ctrl/:page', :controller => 'help'
21
21
22 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
22 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
23 map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog'
23 map.connect 'projects/:project_id/time_entries/new', :action => 'edit', :controller => 'timelog'
24 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog'
24 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'edit', :controller => 'timelog'
25
25
26 map.with_options :controller => 'timelog' do |timelog|
26 map.with_options :controller => 'timelog' do |timelog|
27 timelog.connect 'projects/:project_id/time_entries', :action => 'details'
27 timelog.connect 'projects/:project_id/time_entries', :action => 'details'
28
28
29 timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details|
29 timelog.with_options :action => 'details', :conditions => {:method => :get} do |time_details|
30 time_details.connect 'time_entries'
30 time_details.connect 'time_entries'
31 time_details.connect 'time_entries.:format'
31 time_details.connect 'time_entries.:format'
32 time_details.connect 'issues/:issue_id/time_entries'
32 time_details.connect 'issues/:issue_id/time_entries'
33 time_details.connect 'issues/:issue_id/time_entries.:format'
33 time_details.connect 'issues/:issue_id/time_entries.:format'
34 time_details.connect 'projects/:project_id/time_entries.:format'
34 time_details.connect 'projects/:project_id/time_entries.:format'
35 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries'
35 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries'
36 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format'
36 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format'
37 end
37 end
38 timelog.connect 'projects/:project_id/time_entries/report', :action => 'report'
38 timelog.connect 'projects/:project_id/time_entries/report', :action => 'report'
39 timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report|
39 timelog.with_options :action => 'report',:conditions => {:method => :get} do |time_report|
40 time_report.connect 'time_entries/report'
40 time_report.connect 'time_entries/report'
41 time_report.connect 'time_entries/report.:format'
41 time_report.connect 'time_entries/report.:format'
42 time_report.connect 'projects/:project_id/time_entries/report.:format'
42 time_report.connect 'projects/:project_id/time_entries/report.:format'
43 end
43 end
44
44
45 timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit|
45 timelog.with_options :action => 'edit', :conditions => {:method => :get} do |time_edit|
46 time_edit.connect 'issues/:issue_id/time_entries/new'
46 time_edit.connect 'issues/:issue_id/time_entries/new'
47 end
47 end
48
48
49 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
49 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
50 end
50 end
51
51
52 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
52 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
53 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
53 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
54 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
54 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
55 map.with_options :controller => 'wiki' do |wiki_routes|
55 map.with_options :controller => 'wiki' do |wiki_routes|
56 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
56 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
57 wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
57 wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
58 wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
58 wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
59 wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
59 wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
60 wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
60 wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
61 wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history'
61 wiki_views.connect 'projects/:id/wiki/:page/history', :action => 'history'
62 wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
62 wiki_views.connect 'projects/:id/wiki/:page/diff/:version/vs/:version_from', :action => 'diff'
63 wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate'
63 wiki_views.connect 'projects/:id/wiki/:page/annotate/:version', :action => 'annotate'
64 end
64 end
65
65
66 wiki_routes.connect 'projects/:id/wiki/:page/:action',
66 wiki_routes.connect 'projects/:id/wiki/:page/:action',
67 :action => /edit|rename|destroy|preview|protect/,
67 :action => /edit|rename|destroy|preview|protect/,
68 :conditions => {:method => :post}
68 :conditions => {:method => :post}
69 end
69 end
70
70
71 map.with_options :controller => 'messages' do |messages_routes|
71 map.with_options :controller => 'messages' do |messages_routes|
72 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
72 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
73 messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
73 messages_views.connect 'boards/:board_id/topics/new', :action => 'new'
74 messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
74 messages_views.connect 'boards/:board_id/topics/:id', :action => 'show'
75 messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
75 messages_views.connect 'boards/:board_id/topics/:id/edit', :action => 'edit'
76 end
76 end
77 messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
77 messages_routes.with_options :conditions => {:method => :post} do |messages_actions|
78 messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
78 messages_actions.connect 'boards/:board_id/topics/new', :action => 'new'
79 messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
79 messages_actions.connect 'boards/:board_id/topics/:id/replies', :action => 'reply'
80 messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
80 messages_actions.connect 'boards/:board_id/topics/:id/:action', :action => /edit|destroy/
81 end
81 end
82 end
82 end
83
83
84 map.with_options :controller => 'boards' do |board_routes|
84 map.with_options :controller => 'boards' do |board_routes|
85 board_routes.with_options :conditions => {:method => :get} do |board_views|
85 board_routes.with_options :conditions => {:method => :get} do |board_views|
86 board_views.connect 'projects/:project_id/boards', :action => 'index'
86 board_views.connect 'projects/:project_id/boards', :action => 'index'
87 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
87 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
88 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
88 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
89 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
89 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
90 end
90 end
91 board_routes.with_options :conditions => {:method => :post} do |board_actions|
91 board_routes.with_options :conditions => {:method => :post} do |board_actions|
92 board_actions.connect 'projects/:project_id/boards', :action => 'new'
92 board_actions.connect 'projects/:project_id/boards', :action => 'new'
93 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
93 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
94 end
94 end
95 end
95 end
96
96
97 map.with_options :controller => 'documents' do |document_routes|
97 map.with_options :controller => 'documents' do |document_routes|
98 document_routes.with_options :conditions => {:method => :get} do |document_views|
98 document_routes.with_options :conditions => {:method => :get} do |document_views|
99 document_views.connect 'projects/:project_id/documents', :action => 'index'
99 document_views.connect 'projects/:project_id/documents', :action => 'index'
100 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
100 document_views.connect 'projects/:project_id/documents/new', :action => 'new'
101 document_views.connect 'documents/:id', :action => 'show'
101 document_views.connect 'documents/:id', :action => 'show'
102 document_views.connect 'documents/:id/edit', :action => 'edit'
102 document_views.connect 'documents/:id/edit', :action => 'edit'
103 end
103 end
104 document_routes.with_options :conditions => {:method => :post} do |document_actions|
104 document_routes.with_options :conditions => {:method => :post} do |document_actions|
105 document_actions.connect 'projects/:project_id/documents', :action => 'new'
105 document_actions.connect 'projects/:project_id/documents', :action => 'new'
106 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
106 document_actions.connect 'documents/:id/:action', :action => /destroy|edit/
107 end
107 end
108 end
108 end
109
109
110 map.with_options :controller => 'issues' do |issues_routes|
110 map.with_options :controller => 'issues' do |issues_routes|
111 issues_routes.with_options :conditions => {:method => :get} do |issues_views|
111 issues_routes.with_options :conditions => {:method => :get} do |issues_views|
112 issues_views.connect 'issues', :action => 'index'
112 issues_views.connect 'issues', :action => 'index'
113 issues_views.connect 'issues.:format', :action => 'index'
113 issues_views.connect 'issues.:format', :action => 'index'
114 issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
114 issues_views.connect 'projects/:project_id/issues.:format', :action => 'index'
115 issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
115 issues_views.connect 'projects/:project_id/issues/new', :action => 'new'
116 issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
116 issues_views.connect 'projects/:project_id/issues/:copy_from/copy', :action => 'new'
117 issues_views.connect 'issues/:id', :action => 'show'
117 issues_views.connect 'issues/:id', :action => 'show'
118 issues_views.connect 'issues/:id.:format', :action => 'show'
118 issues_views.connect 'issues/:id.:format', :action => 'show'
119 issues_views.connect 'issues/:id/edit', :action => 'edit'
119 issues_views.connect 'issues/:id/edit', :action => 'edit'
120 issues_views.connect 'issues/:id/move', :action => 'move'
120 issues_views.connect 'issues/:id/move', :action => 'move'
121 end
121 end
122 issues_routes.with_options :conditions => {:method => :post} do |issues_actions|
122 issues_routes.with_options :conditions => {:method => :post} do |issues_actions|
123 issues_actions.connect 'projects/:project_id/issues', :action => 'new'
123 issues_actions.connect 'projects/:project_id/issues', :action => 'new'
124 issues_actions.connect 'issues/:id/quoted', :action => 'reply'
124 issues_actions.connect 'issues/:id/quoted', :action => 'reply'
125 issues_actions.connect 'issues/:id/:action',
125 issues_actions.connect 'issues/:id/:action',
126 :action => /edit|move|destroy/
126 :action => /edit|move|destroy/
127 end
127 end
128 end
128 end
129
129
130 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
130 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
131 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
131 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
132 relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
132 relations.connect 'issues/:issue_id/relations/:id/destroy', :action => 'destroy'
133 end
133 end
134
134
135 map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports|
135 map.with_options :controller => 'reports', :action => 'issue_report', :conditions => {:method => :get} do |reports|
136 reports.connect 'projects/:id/issues/report'
136 reports.connect 'projects/:id/issues/report'
137 reports.connect 'projects/:id/issues/report/:detail'
137 reports.connect 'projects/:id/issues/report/:detail'
138 end
138 end
139
139
140 map.with_options :controller => 'news' do |news_routes|
140 map.with_options :controller => 'news' do |news_routes|
141 news_routes.with_options :conditions => {:method => :get} do |news_views|
141 news_routes.with_options :conditions => {:method => :get} do |news_views|
142 news_views.connect 'news', :action => 'index'
142 news_views.connect 'news', :action => 'index'
143 news_views.connect 'projects/:project_id/news', :action => 'index'
143 news_views.connect 'projects/:project_id/news', :action => 'index'
144 news_views.connect 'projects/:project_id/news.:format', :action => 'index'
144 news_views.connect 'projects/:project_id/news.:format', :action => 'index'
145 news_views.connect 'news.:format', :action => 'index'
145 news_views.connect 'news.:format', :action => 'index'
146 news_views.connect 'projects/:project_id/news/new', :action => 'new'
146 news_views.connect 'projects/:project_id/news/new', :action => 'new'
147 news_views.connect 'news/:id', :action => 'show'
147 news_views.connect 'news/:id', :action => 'show'
148 news_views.connect 'news/:id/edit', :action => 'edit'
148 news_views.connect 'news/:id/edit', :action => 'edit'
149 end
149 end
150 news_routes.with_options do |news_actions|
150 news_routes.with_options do |news_actions|
151 news_actions.connect 'projects/:project_id/news', :action => 'new'
151 news_actions.connect 'projects/:project_id/news', :action => 'new'
152 news_actions.connect 'news/:id/edit', :action => 'edit'
152 news_actions.connect 'news/:id/edit', :action => 'edit'
153 news_actions.connect 'news/:id/destroy', :action => 'destroy'
153 news_actions.connect 'news/:id/destroy', :action => 'destroy'
154 end
154 end
155 end
155 end
156
156
157 map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
157 map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
158
158
159 map.with_options :controller => 'users' do |users|
159 map.with_options :controller => 'users' do |users|
160 users.with_options :conditions => {:method => :get} do |user_views|
160 users.with_options :conditions => {:method => :get} do |user_views|
161 user_views.connect 'users', :action => 'list'
161 user_views.connect 'users', :action => 'list'
162 user_views.connect 'users', :action => 'index'
162 user_views.connect 'users', :action => 'index'
163 user_views.connect 'users/new', :action => 'add'
163 user_views.connect 'users/new', :action => 'add'
164 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
164 user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
165 end
165 end
166 users.with_options :conditions => {:method => :post} do |user_actions|
166 users.with_options :conditions => {:method => :post} do |user_actions|
167 user_actions.connect 'users', :action => 'add'
167 user_actions.connect 'users', :action => 'add'
168 user_actions.connect 'users/new', :action => 'add'
168 user_actions.connect 'users/new', :action => 'add'
169 user_actions.connect 'users/:id/edit', :action => 'edit'
169 user_actions.connect 'users/:id/edit', :action => 'edit'
170 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
170 user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
171 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
171 user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
172 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
172 user_actions.connect 'users/:id/memberships/:membership_id/destroy', :action => 'destroy_membership'
173 end
173 end
174 end
174 end
175
175
176 map.with_options :controller => 'projects' do |projects|
176 map.with_options :controller => 'projects' do |projects|
177 projects.with_options :conditions => {:method => :get} do |project_views|
177 projects.with_options :conditions => {:method => :get} do |project_views|
178 project_views.connect 'projects', :action => 'index'
178 project_views.connect 'projects', :action => 'index'
179 project_views.connect 'projects.:format', :action => 'index'
179 project_views.connect 'projects.:format', :action => 'index'
180 project_views.connect 'projects/new', :action => 'add'
180 project_views.connect 'projects/new', :action => 'add'
181 project_views.connect 'projects/:id', :action => 'show'
181 project_views.connect 'projects/:id', :action => 'show'
182 project_views.connect 'projects/:id/:action', :action => /roadmap|changelog|destroy|settings/
182 project_views.connect 'projects/:id/:action', :action => /roadmap|changelog|destroy|settings/
183 project_views.connect 'projects/:id/files', :action => 'list_files'
183 project_views.connect 'projects/:id/files', :action => 'list_files'
184 project_views.connect 'projects/:id/files/new', :action => 'add_file'
184 project_views.connect 'projects/:id/files/new', :action => 'add_file'
185 project_views.connect 'projects/:id/versions/new', :action => 'add_version'
185 project_views.connect 'projects/:id/versions/new', :action => 'add_version'
186 project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category'
186 project_views.connect 'projects/:id/categories/new', :action => 'add_issue_category'
187 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
187 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
188 end
188 end
189
189
190 projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity|
190 projects.with_options :action => 'activity', :conditions => {:method => :get} do |activity|
191 activity.connect 'projects/:id/activity'
191 activity.connect 'projects/:id/activity'
192 activity.connect 'projects/:id/activity.:format'
192 activity.connect 'projects/:id/activity.:format'
193 activity.connect 'activity'
193 activity.connect 'activity'
194 activity.connect 'activity.:format'
194 activity.connect 'activity.:format'
195 end
195 end
196
196
197 projects.with_options :conditions => {:method => :post} do |project_actions|
197 projects.with_options :conditions => {:method => :post} do |project_actions|
198 project_actions.connect 'projects/new', :action => 'add'
198 project_actions.connect 'projects/new', :action => 'add'
199 project_actions.connect 'projects', :action => 'add'
199 project_actions.connect 'projects', :action => 'add'
200 project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/
200 project_actions.connect 'projects/:id/:action', :action => /destroy|archive|unarchive/
201 project_actions.connect 'projects/:id/files/new', :action => 'add_file'
201 project_actions.connect 'projects/:id/files/new', :action => 'add_file'
202 project_actions.connect 'projects/:id/versions/new', :action => 'add_version'
202 project_actions.connect 'projects/:id/versions/new', :action => 'add_version'
203 project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category'
203 project_actions.connect 'projects/:id/categories/new', :action => 'add_issue_category'
204 end
204 end
205 end
205 end
206
206
207 map.with_options :controller => 'repositories' do |repositories|
207 map.with_options :controller => 'repositories' do |repositories|
208 repositories.with_options :conditions => {:method => :get} do |repository_views|
208 repositories.with_options :conditions => {:method => :get} do |repository_views|
209 repositories.connect 'projects/:id/repository', :action => 'show'
209 repositories.connect 'projects/:id/repository', :action => 'show'
210 repositories.connect 'projects/:id/repository/edit', :action => 'edit'
210 repositories.connect 'projects/:id/repository/edit', :action => 'edit'
211 repositories.connect 'projects/:id/repository/statistics', :action => 'stats'
211 repositories.connect 'projects/:id/repository/statistics', :action => 'stats'
212 repositories.connect 'projects/:id/repository/revisions', :action => 'revisions'
212 repositories.connect 'projects/:id/repository/revisions', :action => 'revisions'
213 repositories.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
213 repositories.connect 'projects/:id/repository/revisions.:format', :action => 'revisions'
214 repositories.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
214 repositories.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
215 repositories.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
215 repositories.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
216 repositories.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
216 repositories.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
217 repositories.connect 'projects/:id/repository/revisions/:rev/:action/*path'
217 repositories.connect 'projects/:id/repository/revisions/:rev/:action/*path'
218 repositories.connect 'projects/:id/repository/:action/*path'
218 repositories.connect 'projects/:id/repository/:action/*path'
219 end
219 end
220
220
221 repositories.connect 'projects/:id/repository/edit', :action => 'edit', :conditions => {:method => :post}
221 repositories.connect 'projects/:id/repository/edit', :action => 'edit', :conditions => {:method => :post}
222 end
222 end
223
223
224 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
224 map.connect 'attachments/:id', :controller => 'attachments', :action => 'show', :id => /\d+/
225 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
225 map.connect 'attachments/:id/:filename', :controller => 'attachments', :action => 'show', :id => /\d+/, :filename => /.*/
226 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
226 map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
227
227
228
228
229 #left old routes at the bottom for backwards compat
229 #left old routes at the bottom for backwards compat
230 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
230 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
231 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
231 map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
232 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
232 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
233 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
233 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
234 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
234 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
235 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
235 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
236 map.connect 'projects/:project_id/news/:action', :controller => 'news'
236 map.connect 'projects/:project_id/news/:action', :controller => 'news'
237 map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
237 map.connect 'projects/:project_id/timelog/:action/:id', :controller => 'timelog', :project_id => /.+/
238 map.with_options :controller => 'repositories' do |omap|
238 map.with_options :controller => 'repositories' do |omap|
239 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
239 omap.repositories_show 'repositories/browse/:id/*path', :action => 'browse'
240 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
240 omap.repositories_changes 'repositories/changes/:id/*path', :action => 'changes'
241 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
241 omap.repositories_diff 'repositories/diff/:id/*path', :action => 'diff'
242 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
242 omap.repositories_entry 'repositories/entry/:id/*path', :action => 'entry'
243 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
243 omap.repositories_entry 'repositories/annotate/:id/*path', :action => 'annotate'
244 omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
244 omap.connect 'repositories/revision/:id/:rev', :action => 'revision'
245 end
245 end
246
246
247 # Allow downloading Web Service WSDL as a file with an extension
247 # Allow downloading Web Service WSDL as a file with an extension
248 # instead of a file named 'wsdl'
248 # instead of a file named 'wsdl'
249 map.connect ':controller/service.wsdl', :action => 'wsdl'
249 map.connect ':controller/service.wsdl', :action => 'wsdl'
250
250
251 # Install the default route as the lowest priority.
251 # Install the default route as the lowest priority.
252 map.connect ':controller/:action/:id'
252 map.connect ':controller/:action/:id'
253 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
253 end
254 end
@@ -1,63 +1,70
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 File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'welcome_controller'
19 require 'welcome_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class WelcomeController; def rescue_action(e) raise e end; end
22 class WelcomeController; def rescue_action(e) raise e end; end
23
23
24 class WelcomeControllerTest < Test::Unit::TestCase
24 class WelcomeControllerTest < Test::Unit::TestCase
25 fixtures :projects, :news
25 fixtures :projects, :news
26
26
27 def setup
27 def setup
28 @controller = WelcomeController.new
28 @controller = WelcomeController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_index
34 def test_index
35 get :index
35 get :index
36 assert_response :success
36 assert_response :success
37 assert_template 'index'
37 assert_template 'index'
38 assert_not_nil assigns(:news)
38 assert_not_nil assigns(:news)
39 assert_not_nil assigns(:projects)
39 assert_not_nil assigns(:projects)
40 assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
40 assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
41 end
41 end
42
42
43 def test_browser_language
43 def test_browser_language
44 Setting.default_language = 'en'
44 Setting.default_language = 'en'
45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
46 get :index
46 get :index
47 assert_equal :fr, @controller.current_language
47 assert_equal :fr, @controller.current_language
48 end
48 end
49
49
50 def test_browser_language_alternate
50 def test_browser_language_alternate
51 Setting.default_language = 'en'
51 Setting.default_language = 'en'
52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
53 get :index
53 get :index
54 assert_equal :"zh-tw", @controller.current_language
54 assert_equal :"zh-tw", @controller.current_language
55 end
55 end
56
56
57 def test_browser_language_alternate_not_valid
57 def test_browser_language_alternate_not_valid
58 Setting.default_language = 'en'
58 Setting.default_language = 'en'
59 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
59 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
60 get :index
60 get :index
61 assert_equal :fr, @controller.current_language
61 assert_equal :fr, @controller.current_language
62 end
62 end
63
64 def test_robots
65 get :robots
66 assert_response :success
67 assert_equal 'text/plain', @response.content_type
68 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues$})
69 end
63 end
70 end
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now