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