##// END OF EJS Templates
Fixed: private subprojects names are revealed on the project overview (#1152)....
Jean-Philippe Lang -
r1384:2d11265ec5e1
parent child
Show More
@@ -1,433 +1,433
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 layout 'base'
19 layout 'base'
20 menu_item :overview
20 menu_item :overview
21 menu_item :activity, :only => :activity
21 menu_item :activity, :only => :activity
22 menu_item :roadmap, :only => :roadmap
22 menu_item :roadmap, :only => :roadmap
23 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :files, :only => [:list_files, :add_file]
24 menu_item :settings, :only => :settings
24 menu_item :settings, :only => :settings
25 menu_item :issues, :only => [:changelog]
25 menu_item :issues, :only => [:changelog]
26
26
27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 before_filter :find_optional_project, :only => :activity
28 before_filter :find_optional_project, :only => :activity
29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 accept_key_auth :activity, :calendar
31 accept_key_auth :activity, :calendar
32
32
33 helper :sort
33 helper :sort
34 include SortHelper
34 include SortHelper
35 helper :custom_fields
35 helper :custom_fields
36 include CustomFieldsHelper
36 include CustomFieldsHelper
37 helper :ifpdf
37 helper :ifpdf
38 include IfpdfHelper
38 include IfpdfHelper
39 helper :issues
39 helper :issues
40 helper IssuesHelper
40 helper IssuesHelper
41 helper :queries
41 helper :queries
42 include QueriesHelper
42 include QueriesHelper
43 helper :repositories
43 helper :repositories
44 include RepositoriesHelper
44 include RepositoriesHelper
45 include ProjectsHelper
45 include ProjectsHelper
46
46
47 def index
47 def index
48 list
48 list
49 render :action => 'list' unless request.xhr?
49 render :action => 'list' unless request.xhr?
50 end
50 end
51
51
52 # Lists visible projects
52 # Lists visible projects
53 def list
53 def list
54 projects = Project.find :all,
54 projects = Project.find :all,
55 :conditions => Project.visible_by(User.current),
55 :conditions => Project.visible_by(User.current),
56 :include => :parent
56 :include => :parent
57 @project_tree = projects.group_by {|p| p.parent || p}
57 @project_tree = projects.group_by {|p| p.parent || p}
58 @project_tree.each_key {|p| @project_tree[p] -= [p]}
58 @project_tree.each_key {|p| @project_tree[p] -= [p]}
59 end
59 end
60
60
61 # Add a new project
61 # Add a new project
62 def add
62 def add
63 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
63 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
64 @trackers = Tracker.all
64 @trackers = Tracker.all
65 @root_projects = Project.find(:all,
65 @root_projects = Project.find(:all,
66 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
66 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
67 :order => 'name')
67 :order => 'name')
68 @project = Project.new(params[:project])
68 @project = Project.new(params[:project])
69 if request.get?
69 if request.get?
70 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
70 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
71 @project.trackers = Tracker.all
71 @project.trackers = Tracker.all
72 @project.is_public = Setting.default_projects_public?
72 @project.is_public = Setting.default_projects_public?
73 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
73 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
74 else
74 else
75 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
75 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
76 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
76 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
77 @project.custom_values = @custom_values
77 @project.custom_values = @custom_values
78 @project.enabled_module_names = params[:enabled_modules]
78 @project.enabled_module_names = params[:enabled_modules]
79 if @project.save
79 if @project.save
80 flash[:notice] = l(:notice_successful_create)
80 flash[:notice] = l(:notice_successful_create)
81 redirect_to :controller => 'admin', :action => 'projects'
81 redirect_to :controller => 'admin', :action => 'projects'
82 end
82 end
83 end
83 end
84 end
84 end
85
85
86 # Show @project
86 # Show @project
87 def show
87 def show
88 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
88 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
89 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
89 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
90 @subprojects = @project.active_children
90 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
91 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
91 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
92 @trackers = @project.rolled_up_trackers
92 @trackers = @project.rolled_up_trackers
93
93
94 cond = @project.project_condition(Setting.display_subprojects_issues?)
94 cond = @project.project_condition(Setting.display_subprojects_issues?)
95 Issue.visible_by(User.current) do
95 Issue.visible_by(User.current) do
96 @open_issues_by_tracker = Issue.count(:group => :tracker,
96 @open_issues_by_tracker = Issue.count(:group => :tracker,
97 :include => [:project, :status, :tracker],
97 :include => [:project, :status, :tracker],
98 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
98 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
99 @total_issues_by_tracker = Issue.count(:group => :tracker,
99 @total_issues_by_tracker = Issue.count(:group => :tracker,
100 :include => [:project, :status, :tracker],
100 :include => [:project, :status, :tracker],
101 :conditions => cond)
101 :conditions => cond)
102 end
102 end
103 TimeEntry.visible_by(User.current) do
103 TimeEntry.visible_by(User.current) do
104 @total_hours = TimeEntry.sum(:hours,
104 @total_hours = TimeEntry.sum(:hours,
105 :include => :project,
105 :include => :project,
106 :conditions => cond).to_f
106 :conditions => cond).to_f
107 end
107 end
108 @key = User.current.rss_key
108 @key = User.current.rss_key
109 end
109 end
110
110
111 def settings
111 def settings
112 @root_projects = Project.find(:all,
112 @root_projects = Project.find(:all,
113 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
113 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
114 :order => 'name')
114 :order => 'name')
115 @custom_fields = IssueCustomField.find(:all)
115 @custom_fields = IssueCustomField.find(:all)
116 @issue_category ||= IssueCategory.new
116 @issue_category ||= IssueCategory.new
117 @member ||= @project.members.new
117 @member ||= @project.members.new
118 @trackers = Tracker.all
118 @trackers = Tracker.all
119 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
119 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
120 @repository ||= @project.repository
120 @repository ||= @project.repository
121 @wiki ||= @project.wiki
121 @wiki ||= @project.wiki
122 end
122 end
123
123
124 # Edit @project
124 # Edit @project
125 def edit
125 def edit
126 if request.post?
126 if request.post?
127 if params[:custom_fields]
127 if params[:custom_fields]
128 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
128 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
129 @project.custom_values = @custom_values
129 @project.custom_values = @custom_values
130 end
130 end
131 @project.attributes = params[:project]
131 @project.attributes = params[:project]
132 if @project.save
132 if @project.save
133 flash[:notice] = l(:notice_successful_update)
133 flash[:notice] = l(:notice_successful_update)
134 redirect_to :action => 'settings', :id => @project
134 redirect_to :action => 'settings', :id => @project
135 else
135 else
136 settings
136 settings
137 render :action => 'settings'
137 render :action => 'settings'
138 end
138 end
139 end
139 end
140 end
140 end
141
141
142 def modules
142 def modules
143 @project.enabled_module_names = params[:enabled_modules]
143 @project.enabled_module_names = params[:enabled_modules]
144 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
144 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
145 end
145 end
146
146
147 def archive
147 def archive
148 @project.archive if request.post? && @project.active?
148 @project.archive if request.post? && @project.active?
149 redirect_to :controller => 'admin', :action => 'projects'
149 redirect_to :controller => 'admin', :action => 'projects'
150 end
150 end
151
151
152 def unarchive
152 def unarchive
153 @project.unarchive if request.post? && !@project.active?
153 @project.unarchive if request.post? && !@project.active?
154 redirect_to :controller => 'admin', :action => 'projects'
154 redirect_to :controller => 'admin', :action => 'projects'
155 end
155 end
156
156
157 # Delete @project
157 # Delete @project
158 def destroy
158 def destroy
159 @project_to_destroy = @project
159 @project_to_destroy = @project
160 if request.post? and params[:confirm]
160 if request.post? and params[:confirm]
161 @project_to_destroy.destroy
161 @project_to_destroy.destroy
162 redirect_to :controller => 'admin', :action => 'projects'
162 redirect_to :controller => 'admin', :action => 'projects'
163 end
163 end
164 # hide project in layout
164 # hide project in layout
165 @project = nil
165 @project = nil
166 end
166 end
167
167
168 # Add a new issue category to @project
168 # Add a new issue category to @project
169 def add_issue_category
169 def add_issue_category
170 @category = @project.issue_categories.build(params[:category])
170 @category = @project.issue_categories.build(params[:category])
171 if request.post? and @category.save
171 if request.post? and @category.save
172 respond_to do |format|
172 respond_to do |format|
173 format.html do
173 format.html do
174 flash[:notice] = l(:notice_successful_create)
174 flash[:notice] = l(:notice_successful_create)
175 redirect_to :action => 'settings', :tab => 'categories', :id => @project
175 redirect_to :action => 'settings', :tab => 'categories', :id => @project
176 end
176 end
177 format.js do
177 format.js do
178 # IE doesn't support the replace_html rjs method for select box options
178 # IE doesn't support the replace_html rjs method for select box options
179 render(:update) {|page| page.replace "issue_category_id",
179 render(:update) {|page| page.replace "issue_category_id",
180 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]')
180 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]')
181 }
181 }
182 end
182 end
183 end
183 end
184 end
184 end
185 end
185 end
186
186
187 # Add a new version to @project
187 # Add a new version to @project
188 def add_version
188 def add_version
189 @version = @project.versions.build(params[:version])
189 @version = @project.versions.build(params[:version])
190 if request.post? and @version.save
190 if request.post? and @version.save
191 flash[:notice] = l(:notice_successful_create)
191 flash[:notice] = l(:notice_successful_create)
192 redirect_to :action => 'settings', :tab => 'versions', :id => @project
192 redirect_to :action => 'settings', :tab => 'versions', :id => @project
193 end
193 end
194 end
194 end
195
195
196 def add_file
196 def add_file
197 if request.post?
197 if request.post?
198 @version = @project.versions.find_by_id(params[:version_id])
198 @version = @project.versions.find_by_id(params[:version_id])
199 attachments = attach_files(@version, params[:attachments])
199 attachments = attach_files(@version, params[:attachments])
200 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
200 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
201 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
201 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
202 end
202 end
203 @versions = @project.versions.sort
203 @versions = @project.versions.sort
204 end
204 end
205
205
206 def list_files
206 def list_files
207 sort_init "#{Attachment.table_name}.filename", "asc"
207 sort_init "#{Attachment.table_name}.filename", "asc"
208 sort_update
208 sort_update
209 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
209 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
210 render :layout => !request.xhr?
210 render :layout => !request.xhr?
211 end
211 end
212
212
213 # Show changelog for @project
213 # Show changelog for @project
214 def changelog
214 def changelog
215 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
215 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
216 retrieve_selected_tracker_ids(@trackers)
216 retrieve_selected_tracker_ids(@trackers)
217 @versions = @project.versions.sort
217 @versions = @project.versions.sort
218 end
218 end
219
219
220 def roadmap
220 def roadmap
221 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
221 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
222 retrieve_selected_tracker_ids(@trackers)
222 retrieve_selected_tracker_ids(@trackers)
223 @versions = @project.versions.sort
223 @versions = @project.versions.sort
224 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
224 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
225 end
225 end
226
226
227 def activity
227 def activity
228 @days = Setting.activity_days_default.to_i
228 @days = Setting.activity_days_default.to_i
229
229
230 if params[:from]
230 if params[:from]
231 begin; @date_to = params[:from].to_date; rescue; end
231 begin; @date_to = params[:from].to_date; rescue; end
232 end
232 end
233
233
234 @date_to ||= Date.today + 1
234 @date_to ||= Date.today + 1
235 @date_from = @date_to - @days
235 @date_from = @date_to - @days
236
236
237 @event_types = %w(issues news files documents changesets wiki_pages messages)
237 @event_types = %w(issues news files documents changesets wiki_pages messages)
238 if @project
238 if @project
239 @event_types.delete('wiki_pages') unless @project.wiki
239 @event_types.delete('wiki_pages') unless @project.wiki
240 @event_types.delete('changesets') unless @project.repository
240 @event_types.delete('changesets') unless @project.repository
241 @event_types.delete('messages') unless @project.boards.any?
241 @event_types.delete('messages') unless @project.boards.any?
242 # only show what the user is allowed to view
242 # only show what the user is allowed to view
243 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
243 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
244 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
244 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
245 end
245 end
246 @scope = @event_types.select {|t| params["show_#{t}"]}
246 @scope = @event_types.select {|t| params["show_#{t}"]}
247 # default events if none is specified in parameters
247 # default events if none is specified in parameters
248 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
248 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
249
249
250 @events = []
250 @events = []
251
251
252 if @scope.include?('issues')
252 if @scope.include?('issues')
253 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
253 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
254 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
254 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
255 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
255 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
256
256
257 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
257 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
258 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
258 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
259 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
259 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
260 end
260 end
261
261
262 if @scope.include?('news')
262 if @scope.include?('news')
263 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
263 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
264 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
264 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
265 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
265 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
266 end
266 end
267
267
268 if @scope.include?('files')
268 if @scope.include?('files')
269 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
269 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
270 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
270 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
271 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
271 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
272 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
272 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
273 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
273 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
274 :conditions => cond.conditions)
274 :conditions => cond.conditions)
275 end
275 end
276
276
277 if @scope.include?('documents')
277 if @scope.include?('documents')
278 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
278 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
279 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
279 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
280 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
280 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
281
281
282 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
282 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
283 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
283 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
284 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
284 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
285 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
285 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
286 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
286 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
287 :conditions => cond.conditions)
287 :conditions => cond.conditions)
288 end
288 end
289
289
290 if @scope.include?('wiki_pages')
290 if @scope.include?('wiki_pages')
291 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
291 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
292 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
292 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
293 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
293 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
294 "#{WikiContent.versioned_table_name}.id"
294 "#{WikiContent.versioned_table_name}.id"
295 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
295 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
296 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
296 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
297 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
297 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
298
298
299 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
299 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
300 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
300 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
301 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
301 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
302 end
302 end
303
303
304 if @scope.include?('changesets')
304 if @scope.include?('changesets')
305 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
305 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
306 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
306 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
307 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
307 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
308 end
308 end
309
309
310 if @scope.include?('messages')
310 if @scope.include?('messages')
311 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
311 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
312 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
312 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
313 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
313 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
314 end
314 end
315
315
316 @events_by_day = @events.group_by(&:event_date)
316 @events_by_day = @events.group_by(&:event_date)
317
317
318 respond_to do |format|
318 respond_to do |format|
319 format.html { render :layout => false if request.xhr? }
319 format.html { render :layout => false if request.xhr? }
320 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
320 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
321 end
321 end
322 end
322 end
323
323
324 def calendar
324 def calendar
325 @trackers = @project.rolled_up_trackers
325 @trackers = @project.rolled_up_trackers
326 retrieve_selected_tracker_ids(@trackers)
326 retrieve_selected_tracker_ids(@trackers)
327
327
328 if params[:year] and params[:year].to_i > 1900
328 if params[:year] and params[:year].to_i > 1900
329 @year = params[:year].to_i
329 @year = params[:year].to_i
330 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
330 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
331 @month = params[:month].to_i
331 @month = params[:month].to_i
332 end
332 end
333 end
333 end
334 @year ||= Date.today.year
334 @year ||= Date.today.year
335 @month ||= Date.today.month
335 @month ||= Date.today.month
336 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
336 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
337 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
337 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
338 events = []
338 events = []
339 @project.issues_with_subprojects(@with_subprojects) do
339 @project.issues_with_subprojects(@with_subprojects) do
340 events += Issue.find(:all,
340 events += Issue.find(:all,
341 :include => [:tracker, :status, :assigned_to, :priority, :project],
341 :include => [:tracker, :status, :assigned_to, :priority, :project],
342 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
342 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
343 ) unless @selected_tracker_ids.empty?
343 ) unless @selected_tracker_ids.empty?
344 events += Version.find(:all, :include => :project,
344 events += Version.find(:all, :include => :project,
345 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
345 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
346 end
346 end
347 @calendar.events = events
347 @calendar.events = events
348
348
349 render :layout => false if request.xhr?
349 render :layout => false if request.xhr?
350 end
350 end
351
351
352 def gantt
352 def gantt
353 @trackers = @project.rolled_up_trackers
353 @trackers = @project.rolled_up_trackers
354 retrieve_selected_tracker_ids(@trackers)
354 retrieve_selected_tracker_ids(@trackers)
355
355
356 if params[:year] and params[:year].to_i >0
356 if params[:year] and params[:year].to_i >0
357 @year_from = params[:year].to_i
357 @year_from = params[:year].to_i
358 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
358 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
359 @month_from = params[:month].to_i
359 @month_from = params[:month].to_i
360 else
360 else
361 @month_from = 1
361 @month_from = 1
362 end
362 end
363 else
363 else
364 @month_from ||= Date.today.month
364 @month_from ||= Date.today.month
365 @year_from ||= Date.today.year
365 @year_from ||= Date.today.year
366 end
366 end
367
367
368 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
368 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
369 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
369 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
370 months = (params[:months] || User.current.pref[:gantt_months]).to_i
370 months = (params[:months] || User.current.pref[:gantt_months]).to_i
371 @months = (months > 0 && months < 25) ? months : 6
371 @months = (months > 0 && months < 25) ? months : 6
372
372
373 # Save gantt paramters as user preference (zoom and months count)
373 # Save gantt paramters as user preference (zoom and months count)
374 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
374 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
375 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
375 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
376 User.current.preference.save
376 User.current.preference.save
377 end
377 end
378
378
379 @date_from = Date.civil(@year_from, @month_from, 1)
379 @date_from = Date.civil(@year_from, @month_from, 1)
380 @date_to = (@date_from >> @months) - 1
380 @date_to = (@date_from >> @months) - 1
381 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
381 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
382
382
383 @events = []
383 @events = []
384 @project.issues_with_subprojects(@with_subprojects) do
384 @project.issues_with_subprojects(@with_subprojects) do
385 @events += Issue.find(:all,
385 @events += Issue.find(:all,
386 :order => "start_date, due_date",
386 :order => "start_date, due_date",
387 :include => [:tracker, :status, :assigned_to, :priority, :project],
387 :include => [:tracker, :status, :assigned_to, :priority, :project],
388 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
388 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
389 ) unless @selected_tracker_ids.empty?
389 ) unless @selected_tracker_ids.empty?
390 @events += Version.find(:all, :include => :project,
390 @events += Version.find(:all, :include => :project,
391 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
391 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
392 end
392 end
393 @events.sort! {|x,y| x.start_date <=> y.start_date }
393 @events.sort! {|x,y| x.start_date <=> y.start_date }
394
394
395 if params[:format]=='pdf'
395 if params[:format]=='pdf'
396 @options_for_rfpdf ||= {}
396 @options_for_rfpdf ||= {}
397 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
397 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
398 render :template => "projects/gantt.rfpdf", :layout => false
398 render :template => "projects/gantt.rfpdf", :layout => false
399 elsif params[:format]=='png' && respond_to?('gantt_image')
399 elsif params[:format]=='png' && respond_to?('gantt_image')
400 image = gantt_image(@events, @date_from, @months, @zoom)
400 image = gantt_image(@events, @date_from, @months, @zoom)
401 image.format = 'PNG'
401 image.format = 'PNG'
402 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
402 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
403 else
403 else
404 render :template => "projects/gantt.rhtml"
404 render :template => "projects/gantt.rhtml"
405 end
405 end
406 end
406 end
407
407
408 private
408 private
409 # Find project of id params[:id]
409 # Find project of id params[:id]
410 # if not found, redirect to project list
410 # if not found, redirect to project list
411 # Used as a before_filter
411 # Used as a before_filter
412 def find_project
412 def find_project
413 @project = Project.find(params[:id])
413 @project = Project.find(params[:id])
414 rescue ActiveRecord::RecordNotFound
414 rescue ActiveRecord::RecordNotFound
415 render_404
415 render_404
416 end
416 end
417
417
418 def find_optional_project
418 def find_optional_project
419 return true unless params[:id]
419 return true unless params[:id]
420 @project = Project.find(params[:id])
420 @project = Project.find(params[:id])
421 authorize
421 authorize
422 rescue ActiveRecord::RecordNotFound
422 rescue ActiveRecord::RecordNotFound
423 render_404
423 render_404
424 end
424 end
425
425
426 def retrieve_selected_tracker_ids(selectable_trackers)
426 def retrieve_selected_tracker_ids(selectable_trackers)
427 if ids = params[:tracker_ids]
427 if ids = params[:tracker_ids]
428 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
428 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
429 else
429 else
430 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
430 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
431 end
431 end
432 end
432 end
433 end
433 end
@@ -1,27 +1,33
1 ---
1 ---
2 members_001:
2 members_001:
3 created_on: 2006-07-19 19:35:33 +02:00
3 created_on: 2006-07-19 19:35:33 +02:00
4 project_id: 1
4 project_id: 1
5 role_id: 1
5 role_id: 1
6 id: 1
6 id: 1
7 user_id: 2
7 user_id: 2
8 members_002:
8 members_002:
9 created_on: 2006-07-19 19:35:36 +02:00
9 created_on: 2006-07-19 19:35:36 +02:00
10 project_id: 1
10 project_id: 1
11 role_id: 2
11 role_id: 2
12 id: 2
12 id: 2
13 user_id: 3
13 user_id: 3
14 members_003:
14 members_003:
15 created_on: 2006-07-19 19:35:36 +02:00
15 created_on: 2006-07-19 19:35:36 +02:00
16 project_id: 2
16 project_id: 2
17 role_id: 2
17 role_id: 2
18 id: 3
18 id: 3
19 user_id: 2
19 user_id: 2
20 members_004:
20 members_004:
21 id: 4
21 id: 4
22 created_on: 2006-07-19 19:35:36 +02:00
22 created_on: 2006-07-19 19:35:36 +02:00
23 project_id: 1
23 project_id: 1
24 role_id: 2
24 role_id: 2
25 # Locked user
25 # Locked user
26 user_id: 5
26 user_id: 5
27 members_005:
28 id: 5
29 created_on: 2006-07-19 19:35:33 +02:00
30 project_id: 5
31 role_id: 1
32 user_id: 2
27 No newline at end of file
33
@@ -1,45 +1,57
1 ---
1 ---
2 projects_001:
2 projects_001:
3 created_on: 2006-07-19 19:13:59 +02:00
3 created_on: 2006-07-19 19:13:59 +02:00
4 name: eCookbook
4 name: eCookbook
5 updated_on: 2006-07-19 22:53:01 +02:00
5 updated_on: 2006-07-19 22:53:01 +02:00
6 projects_count: 2
6 projects_count: 3
7 id: 1
7 id: 1
8 description: Recipes management application
8 description: Recipes management application
9 homepage: http://ecookbook.somenet.foo/
9 homepage: http://ecookbook.somenet.foo/
10 is_public: true
10 is_public: true
11 identifier: ecookbook
11 identifier: ecookbook
12 parent_id:
12 parent_id:
13 projects_002:
13 projects_002:
14 created_on: 2006-07-19 19:14:19 +02:00
14 created_on: 2006-07-19 19:14:19 +02:00
15 name: OnlineStore
15 name: OnlineStore
16 updated_on: 2006-07-19 19:14:19 +02:00
16 updated_on: 2006-07-19 19:14:19 +02:00
17 projects_count: 0
17 projects_count: 0
18 id: 2
18 id: 2
19 description: E-commerce web site
19 description: E-commerce web site
20 homepage: ""
20 homepage: ""
21 is_public: false
21 is_public: false
22 identifier: onlinestore
22 identifier: onlinestore
23 parent_id:
23 parent_id:
24 projects_003:
24 projects_003:
25 created_on: 2006-07-19 19:15:21 +02:00
25 created_on: 2006-07-19 19:15:21 +02:00
26 name: eCookbook Subproject 1
26 name: eCookbook Subproject 1
27 updated_on: 2006-07-19 19:18:12 +02:00
27 updated_on: 2006-07-19 19:18:12 +02:00
28 projects_count: 0
28 projects_count: 0
29 id: 3
29 id: 3
30 description: eCookBook Subproject 1
30 description: eCookBook Subproject 1
31 homepage: ""
31 homepage: ""
32 is_public: true
32 is_public: true
33 identifier: subproject1
33 identifier: subproject1
34 parent_id: 1
34 parent_id: 1
35 projects_004:
35 projects_004:
36 created_on: 2006-07-19 19:15:51 +02:00
36 created_on: 2006-07-19 19:15:51 +02:00
37 name: eCookbook Subproject 2
37 name: eCookbook Subproject 2
38 updated_on: 2006-07-19 19:17:07 +02:00
38 updated_on: 2006-07-19 19:17:07 +02:00
39 projects_count: 0
39 projects_count: 0
40 id: 4
40 id: 4
41 description: eCookbook Subproject 2
41 description: eCookbook Subproject 2
42 homepage: ""
42 homepage: ""
43 is_public: true
43 is_public: true
44 identifier: subproject2
44 identifier: subproject2
45 parent_id: 1
45 parent_id: 1
46 projects_005:
47 created_on: 2006-07-19 19:15:51 +02:00
48 name: Private child of eCookbook
49 updated_on: 2006-07-19 19:17:07 +02:00
50 projects_count: 0
51 id: 5
52 description: This is a private subproject of a public project
53 homepage: ""
54 is_public: false
55 identifier: private_child
56 parent_id: 1
57 No newline at end of file
@@ -1,268 +1,283
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 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
27
27
28 def setup
28 def setup
29 @controller = ProjectsController.new
29 @controller = ProjectsController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
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 'list'
37 assert_template 'list'
38 end
38 end
39
39
40 def test_list
40 def test_list
41 get :list
41 get :list
42 assert_response :success
42 assert_response :success
43 assert_template 'list'
43 assert_template 'list'
44 assert_not_nil assigns(:project_tree)
44 assert_not_nil assigns(:project_tree)
45 # Root project as hash key
45 # Root project as hash key
46 assert assigns(:project_tree).has_key?(Project.find(1))
46 assert assigns(:project_tree).has_key?(Project.find(1))
47 # Subproject in corresponding value
47 # Subproject in corresponding value
48 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
48 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
49 end
49 end
50
50
51 def test_show_by_id
51 def test_show_by_id
52 get :show, :id => 1
52 get :show, :id => 1
53 assert_response :success
53 assert_response :success
54 assert_template 'show'
54 assert_template 'show'
55 assert_not_nil assigns(:project)
55 assert_not_nil assigns(:project)
56 end
56 end
57
57
58 def test_show_by_identifier
58 def test_show_by_identifier
59 get :show, :id => 'ecookbook'
59 get :show, :id => 'ecookbook'
60 assert_response :success
60 assert_response :success
61 assert_template 'show'
61 assert_template 'show'
62 assert_not_nil assigns(:project)
62 assert_not_nil assigns(:project)
63 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
63 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
64 end
64 end
65
65
66 def test_private_subprojects_hidden
67 get :show, :id => 'ecookbook'
68 assert_response :success
69 assert_template 'show'
70 assert_no_tag :tag => 'a', :content => /Private child/
71 end
72
73 def test_private_subprojects_visible
74 @request.session[:user_id] = 2 # manager who is a member of the private subproject
75 get :show, :id => 'ecookbook'
76 assert_response :success
77 assert_template 'show'
78 assert_tag :tag => 'a', :content => /Private child/
79 end
80
66 def test_settings
81 def test_settings
67 @request.session[:user_id] = 2 # manager
82 @request.session[:user_id] = 2 # manager
68 get :settings, :id => 1
83 get :settings, :id => 1
69 assert_response :success
84 assert_response :success
70 assert_template 'settings'
85 assert_template 'settings'
71 end
86 end
72
87
73 def test_edit
88 def test_edit
74 @request.session[:user_id] = 2 # manager
89 @request.session[:user_id] = 2 # manager
75 post :edit, :id => 1, :project => {:name => 'Test changed name',
90 post :edit, :id => 1, :project => {:name => 'Test changed name',
76 :custom_field_ids => ['']}
91 :custom_field_ids => ['']}
77 assert_redirected_to 'projects/settings/ecookbook'
92 assert_redirected_to 'projects/settings/ecookbook'
78 project = Project.find(1)
93 project = Project.find(1)
79 assert_equal 'Test changed name', project.name
94 assert_equal 'Test changed name', project.name
80 end
95 end
81
96
82 def test_get_destroy
97 def test_get_destroy
83 @request.session[:user_id] = 1 # admin
98 @request.session[:user_id] = 1 # admin
84 get :destroy, :id => 1
99 get :destroy, :id => 1
85 assert_response :success
100 assert_response :success
86 assert_template 'destroy'
101 assert_template 'destroy'
87 assert_not_nil Project.find_by_id(1)
102 assert_not_nil Project.find_by_id(1)
88 end
103 end
89
104
90 def test_post_destroy
105 def test_post_destroy
91 @request.session[:user_id] = 1 # admin
106 @request.session[:user_id] = 1 # admin
92 post :destroy, :id => 1, :confirm => 1
107 post :destroy, :id => 1, :confirm => 1
93 assert_redirected_to 'admin/projects'
108 assert_redirected_to 'admin/projects'
94 assert_nil Project.find_by_id(1)
109 assert_nil Project.find_by_id(1)
95 end
110 end
96
111
97 def test_list_files
112 def test_list_files
98 get :list_files, :id => 1
113 get :list_files, :id => 1
99 assert_response :success
114 assert_response :success
100 assert_template 'list_files'
115 assert_template 'list_files'
101 assert_not_nil assigns(:versions)
116 assert_not_nil assigns(:versions)
102 end
117 end
103
118
104 def test_changelog
119 def test_changelog
105 get :changelog, :id => 1
120 get :changelog, :id => 1
106 assert_response :success
121 assert_response :success
107 assert_template 'changelog'
122 assert_template 'changelog'
108 assert_not_nil assigns(:versions)
123 assert_not_nil assigns(:versions)
109 end
124 end
110
125
111 def test_roadmap
126 def test_roadmap
112 get :roadmap, :id => 1
127 get :roadmap, :id => 1
113 assert_response :success
128 assert_response :success
114 assert_template 'roadmap'
129 assert_template 'roadmap'
115 assert_not_nil assigns(:versions)
130 assert_not_nil assigns(:versions)
116 # Version with no date set appears
131 # Version with no date set appears
117 assert assigns(:versions).include?(Version.find(3))
132 assert assigns(:versions).include?(Version.find(3))
118 # Completed version doesn't appear
133 # Completed version doesn't appear
119 assert !assigns(:versions).include?(Version.find(1))
134 assert !assigns(:versions).include?(Version.find(1))
120 end
135 end
121
136
122 def test_roadmap_with_completed_versions
137 def test_roadmap_with_completed_versions
123 get :roadmap, :id => 1, :completed => 1
138 get :roadmap, :id => 1, :completed => 1
124 assert_response :success
139 assert_response :success
125 assert_template 'roadmap'
140 assert_template 'roadmap'
126 assert_not_nil assigns(:versions)
141 assert_not_nil assigns(:versions)
127 # Version with no date set appears
142 # Version with no date set appears
128 assert assigns(:versions).include?(Version.find(3))
143 assert assigns(:versions).include?(Version.find(3))
129 # Completed version appears
144 # Completed version appears
130 assert assigns(:versions).include?(Version.find(1))
145 assert assigns(:versions).include?(Version.find(1))
131 end
146 end
132
147
133 def test_project_activity
148 def test_project_activity
134 get :activity, :id => 1, :with_subprojects => 0
149 get :activity, :id => 1, :with_subprojects => 0
135 assert_response :success
150 assert_response :success
136 assert_template 'activity'
151 assert_template 'activity'
137 assert_not_nil assigns(:events_by_day)
152 assert_not_nil assigns(:events_by_day)
138 assert_not_nil assigns(:events)
153 assert_not_nil assigns(:events)
139
154
140 # subproject issue not included by default
155 # subproject issue not included by default
141 assert !assigns(:events).include?(Issue.find(5))
156 assert !assigns(:events).include?(Issue.find(5))
142
157
143 assert_tag :tag => "h3",
158 assert_tag :tag => "h3",
144 :content => /#{2.days.ago.to_date.day}/,
159 :content => /#{2.days.ago.to_date.day}/,
145 :sibling => { :tag => "dl",
160 :sibling => { :tag => "dl",
146 :child => { :tag => "dt",
161 :child => { :tag => "dt",
147 :attributes => { :class => 'issue-edit' },
162 :attributes => { :class => 'issue-edit' },
148 :child => { :tag => "a",
163 :child => { :tag => "a",
149 :content => /(#{IssueStatus.find(2).name})/,
164 :content => /(#{IssueStatus.find(2).name})/,
150 }
165 }
151 }
166 }
152 }
167 }
153
168
154 get :activity, :id => 1, :from => 3.days.ago.to_date
169 get :activity, :id => 1, :from => 3.days.ago.to_date
155 assert_response :success
170 assert_response :success
156 assert_template 'activity'
171 assert_template 'activity'
157 assert_not_nil assigns(:events_by_day)
172 assert_not_nil assigns(:events_by_day)
158
173
159 assert_tag :tag => "h3",
174 assert_tag :tag => "h3",
160 :content => /#{3.day.ago.to_date.day}/,
175 :content => /#{3.day.ago.to_date.day}/,
161 :sibling => { :tag => "dl",
176 :sibling => { :tag => "dl",
162 :child => { :tag => "dt",
177 :child => { :tag => "dt",
163 :attributes => { :class => 'issue' },
178 :attributes => { :class => 'issue' },
164 :child => { :tag => "a",
179 :child => { :tag => "a",
165 :content => /#{Issue.find(1).subject}/,
180 :content => /#{Issue.find(1).subject}/,
166 }
181 }
167 }
182 }
168 }
183 }
169 end
184 end
170
185
171 def test_activity_with_subprojects
186 def test_activity_with_subprojects
172 get :activity, :id => 1, :with_subprojects => 1
187 get :activity, :id => 1, :with_subprojects => 1
173 assert_response :success
188 assert_response :success
174 assert_template 'activity'
189 assert_template 'activity'
175 assert_not_nil assigns(:events)
190 assert_not_nil assigns(:events)
176
191
177 assert assigns(:events).include?(Issue.find(1))
192 assert assigns(:events).include?(Issue.find(1))
178 assert !assigns(:events).include?(Issue.find(4))
193 assert !assigns(:events).include?(Issue.find(4))
179 # subproject issue
194 # subproject issue
180 assert assigns(:events).include?(Issue.find(5))
195 assert assigns(:events).include?(Issue.find(5))
181 end
196 end
182
197
183 def test_global_activity_anonymous
198 def test_global_activity_anonymous
184 get :activity
199 get :activity
185 assert_response :success
200 assert_response :success
186 assert_template 'activity'
201 assert_template 'activity'
187 assert_not_nil assigns(:events)
202 assert_not_nil assigns(:events)
188
203
189 assert assigns(:events).include?(Issue.find(1))
204 assert assigns(:events).include?(Issue.find(1))
190 # Issue of a private project
205 # Issue of a private project
191 assert !assigns(:events).include?(Issue.find(4))
206 assert !assigns(:events).include?(Issue.find(4))
192 end
207 end
193
208
194 def test_global_activity_logged_user
209 def test_global_activity_logged_user
195 @request.session[:user_id] = 2 # manager
210 @request.session[:user_id] = 2 # manager
196 get :activity
211 get :activity
197 assert_response :success
212 assert_response :success
198 assert_template 'activity'
213 assert_template 'activity'
199 assert_not_nil assigns(:events)
214 assert_not_nil assigns(:events)
200
215
201 assert assigns(:events).include?(Issue.find(1))
216 assert assigns(:events).include?(Issue.find(1))
202 # Issue of a private project the user belongs to
217 # Issue of a private project the user belongs to
203 assert assigns(:events).include?(Issue.find(4))
218 assert assigns(:events).include?(Issue.find(4))
204 end
219 end
205
220
206
221
207 def test_global_activity_with_all_types
222 def test_global_activity_with_all_types
208 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
223 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
209 assert_response :success
224 assert_response :success
210 assert_template 'activity'
225 assert_template 'activity'
211 assert_not_nil assigns(:events)
226 assert_not_nil assigns(:events)
212
227
213 assert assigns(:events).include?(Issue.find(1))
228 assert assigns(:events).include?(Issue.find(1))
214 assert !assigns(:events).include?(Issue.find(4))
229 assert !assigns(:events).include?(Issue.find(4))
215 assert assigns(:events).include?(Message.find(5))
230 assert assigns(:events).include?(Message.find(5))
216 end
231 end
217
232
218 def test_calendar
233 def test_calendar
219 get :calendar, :id => 1
234 get :calendar, :id => 1
220 assert_response :success
235 assert_response :success
221 assert_template 'calendar'
236 assert_template 'calendar'
222 assert_not_nil assigns(:calendar)
237 assert_not_nil assigns(:calendar)
223 end
238 end
224
239
225 def test_calendar_with_subprojects
240 def test_calendar_with_subprojects
226 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
241 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
227 assert_response :success
242 assert_response :success
228 assert_template 'calendar'
243 assert_template 'calendar'
229 assert_not_nil assigns(:calendar)
244 assert_not_nil assigns(:calendar)
230 end
245 end
231
246
232 def test_gantt
247 def test_gantt
233 get :gantt, :id => 1
248 get :gantt, :id => 1
234 assert_response :success
249 assert_response :success
235 assert_template 'gantt.rhtml'
250 assert_template 'gantt.rhtml'
236 assert_not_nil assigns(:events)
251 assert_not_nil assigns(:events)
237 end
252 end
238
253
239 def test_gantt_with_subprojects
254 def test_gantt_with_subprojects
240 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
255 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
241 assert_response :success
256 assert_response :success
242 assert_template 'gantt.rhtml'
257 assert_template 'gantt.rhtml'
243 assert_not_nil assigns(:events)
258 assert_not_nil assigns(:events)
244 end
259 end
245
260
246 def test_gantt_export_to_pdf
261 def test_gantt_export_to_pdf
247 get :gantt, :id => 1, :format => 'pdf'
262 get :gantt, :id => 1, :format => 'pdf'
248 assert_response :success
263 assert_response :success
249 assert_template 'gantt.rfpdf'
264 assert_template 'gantt.rfpdf'
250 assert_equal 'application/pdf', @response.content_type
265 assert_equal 'application/pdf', @response.content_type
251 assert_not_nil assigns(:events)
266 assert_not_nil assigns(:events)
252 end
267 end
253
268
254 def test_archive
269 def test_archive
255 @request.session[:user_id] = 1 # admin
270 @request.session[:user_id] = 1 # admin
256 post :archive, :id => 1
271 post :archive, :id => 1
257 assert_redirected_to 'admin/projects'
272 assert_redirected_to 'admin/projects'
258 assert !Project.find(1).active?
273 assert !Project.find(1).active?
259 end
274 end
260
275
261 def test_unarchive
276 def test_unarchive
262 @request.session[:user_id] = 1 # admin
277 @request.session[:user_id] = 1 # admin
263 Project.find(1).archive
278 Project.find(1).archive
264 post :unarchive, :id => 1
279 post :unarchive, :id => 1
265 assert_redirected_to 'admin/projects'
280 assert_redirected_to 'admin/projects'
266 assert Project.find(1).active?
281 assert Project.find(1).active?
267 end
282 end
268 end
283 end
@@ -1,132 +1,132
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
19
20 class ProjectTest < Test::Unit::TestCase
20 class ProjectTest < Test::Unit::TestCase
21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
22
22
23 def setup
23 def setup
24 @ecookbook = Project.find(1)
24 @ecookbook = Project.find(1)
25 @ecookbook_sub1 = Project.find(3)
25 @ecookbook_sub1 = Project.find(3)
26 end
26 end
27
27
28 def test_truth
28 def test_truth
29 assert_kind_of Project, @ecookbook
29 assert_kind_of Project, @ecookbook
30 assert_equal "eCookbook", @ecookbook.name
30 assert_equal "eCookbook", @ecookbook.name
31 end
31 end
32
32
33 def test_update
33 def test_update
34 assert_equal "eCookbook", @ecookbook.name
34 assert_equal "eCookbook", @ecookbook.name
35 @ecookbook.name = "eCook"
35 @ecookbook.name = "eCook"
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
37 @ecookbook.reload
37 @ecookbook.reload
38 assert_equal "eCook", @ecookbook.name
38 assert_equal "eCook", @ecookbook.name
39 end
39 end
40
40
41 def test_validate
41 def test_validate
42 @ecookbook.name = ""
42 @ecookbook.name = ""
43 assert !@ecookbook.save
43 assert !@ecookbook.save
44 assert_equal 1, @ecookbook.errors.count
44 assert_equal 1, @ecookbook.errors.count
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
46 end
46 end
47
47
48 def test_public_projects
48 def test_public_projects
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
50 assert_equal 3, public_projects.length
50 assert_equal 3, public_projects.length
51 assert_equal true, public_projects[0].is_public?
51 assert_equal true, public_projects[0].is_public?
52 end
52 end
53
53
54 def test_archive
54 def test_archive
55 user = @ecookbook.members.first.user
55 user = @ecookbook.members.first.user
56 @ecookbook.archive
56 @ecookbook.archive
57 @ecookbook.reload
57 @ecookbook.reload
58
58
59 assert !@ecookbook.active?
59 assert !@ecookbook.active?
60 assert !user.projects.include?(@ecookbook)
60 assert !user.projects.include?(@ecookbook)
61 # Subproject are also archived
61 # Subproject are also archived
62 assert !@ecookbook.children.empty?
62 assert !@ecookbook.children.empty?
63 assert @ecookbook.active_children.empty?
63 assert @ecookbook.active_children.empty?
64 end
64 end
65
65
66 def test_unarchive
66 def test_unarchive
67 user = @ecookbook.members.first.user
67 user = @ecookbook.members.first.user
68 @ecookbook.archive
68 @ecookbook.archive
69 # A subproject of an archived project can not be unarchived
69 # A subproject of an archived project can not be unarchived
70 assert !@ecookbook_sub1.unarchive
70 assert !@ecookbook_sub1.unarchive
71
71
72 # Unarchive project
72 # Unarchive project
73 assert @ecookbook.unarchive
73 assert @ecookbook.unarchive
74 @ecookbook.reload
74 @ecookbook.reload
75 assert @ecookbook.active?
75 assert @ecookbook.active?
76 assert user.projects.include?(@ecookbook)
76 assert user.projects.include?(@ecookbook)
77 # Subproject can now be unarchived
77 # Subproject can now be unarchived
78 @ecookbook_sub1.reload
78 @ecookbook_sub1.reload
79 assert @ecookbook_sub1.unarchive
79 assert @ecookbook_sub1.unarchive
80 end
80 end
81
81
82 def test_destroy
82 def test_destroy
83 # 2 active members
83 # 2 active members
84 assert_equal 2, @ecookbook.members.size
84 assert_equal 2, @ecookbook.members.size
85 # and 1 is locked
85 # and 1 is locked
86 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
86 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
87 # some boards
87 # some boards
88 assert @ecookbook.boards.any?
88 assert @ecookbook.boards.any?
89
89
90 @ecookbook.destroy
90 @ecookbook.destroy
91 # make sure that the project non longer exists
91 # make sure that the project non longer exists
92 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
92 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
93 # make sure related data was removed
93 # make sure related data was removed
94 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
94 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
95 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
95 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
96 end
96 end
97
97
98 def test_subproject_ok
98 def test_subproject_ok
99 sub = Project.find(2)
99 sub = Project.find(2)
100 sub.parent = @ecookbook
100 sub.parent = @ecookbook
101 assert sub.save
101 assert sub.save
102 assert_equal @ecookbook.id, sub.parent.id
102 assert_equal @ecookbook.id, sub.parent.id
103 @ecookbook.reload
103 @ecookbook.reload
104 assert_equal 3, @ecookbook.children.size
104 assert_equal 4, @ecookbook.children.size
105 end
105 end
106
106
107 def test_subproject_invalid
107 def test_subproject_invalid
108 sub = Project.find(2)
108 sub = Project.find(2)
109 sub.parent = @ecookbook_sub1
109 sub.parent = @ecookbook_sub1
110 assert !sub.save
110 assert !sub.save
111 end
111 end
112
112
113 def test_subproject_invalid_2
113 def test_subproject_invalid_2
114 sub = @ecookbook
114 sub = @ecookbook
115 sub.parent = Project.find(2)
115 sub.parent = Project.find(2)
116 assert !sub.save
116 assert !sub.save
117 end
117 end
118
118
119 def test_rolled_up_trackers
119 def test_rolled_up_trackers
120 parent = Project.find(1)
120 parent = Project.find(1)
121 child = parent.children.find(3)
121 child = parent.children.find(3)
122
122
123 assert_equal [1, 2], parent.tracker_ids
123 assert_equal [1, 2], parent.tracker_ids
124 assert_equal [2, 3], child.tracker_ids
124 assert_equal [2, 3], child.tracker_ids
125
125
126 assert_kind_of Tracker, parent.rolled_up_trackers.first
126 assert_kind_of Tracker, parent.rolled_up_trackers.first
127 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
127 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
128
128
129 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
129 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
130 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
130 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
131 end
131 end
132 end
132 end
General Comments 0
You need to be logged in to leave comments. Login now