Mercurial > hg > soundsoftware-site
comparison app/controllers/projects_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 1aee31f54e13 |
children | 4f746d8966dd fc0fecf09eb9 |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
27 accept_rss_auth :index | 27 accept_rss_auth :index |
28 accept_api_auth :index, :show, :create, :update, :destroy | 28 accept_api_auth :index, :show, :create, :update, :destroy |
29 | 29 |
30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| | 30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| |
31 if controller.request.post? | 31 if controller.request.post? |
32 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' | 32 controller.send :expire_action, :controller => 'welcome', :action => 'robots' |
33 end | 33 end |
34 end | 34 end |
35 | 35 |
36 helper :sort | 36 helper :sort |
37 include SortHelper | 37 include SortHelper |
55 sort_update %w(name lft created_on updated_on) | 55 sort_update %w(name lft created_on updated_on) |
56 @limit = per_page_option | 56 @limit = per_page_option |
57 @project_count = Project.visible_roots.count | 57 @project_count = Project.visible_roots.count |
58 @project_pages = Paginator.new self, @project_count, @limit, params['page'] | 58 @project_pages = Paginator.new self, @project_count, @limit, params['page'] |
59 @offset ||= @project_pages.current.offset | 59 @offset ||= @project_pages.current.offset |
60 @projects = Project.visible_roots.all(:offset => @offset, :limit => @limit, :order => sort_clause) | 60 @projects = Project.visible_roots.all(:offset => @offset, :limit => @limit, :order => sort_clause) |
61 render :template => 'projects/index.html.erb', :layout => !request.xhr? | 61 render :template => 'projects/index.html.erb', :layout => !request.xhr? |
62 | |
63 ## Redmine 2.2: | |
64 # scope = Project | |
65 # unless params[:closed] | |
66 # scope = scope.active | |
67 # end | |
68 # @projects = scope.visible.order('lft').all | |
62 } | 69 } |
63 format.api { | 70 format.api { |
64 @offset, @limit = api_offset_and_limit | 71 @offset, @limit = api_offset_and_limit |
65 @project_count = Project.visible.count | 72 @project_count = Project.visible.count |
66 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') | 73 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') |
83 end | 90 end |
84 end | 91 end |
85 | 92 |
86 def new | 93 def new |
87 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 94 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
88 @trackers = Tracker.all | 95 @trackers = Tracker.sorted.all |
89 @project = Project.new | 96 @project = Project.new |
90 @project.safe_attributes = params[:project] | 97 @project.safe_attributes = params[:project] |
91 end | 98 end |
92 | 99 |
93 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
94 def create | 100 def create |
95 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 101 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
96 @trackers = Tracker.all | 102 @trackers = Tracker.sorted.all |
97 @project = Project.new | 103 @project = Project.new |
98 @project.safe_attributes = params[:project] | 104 @project.safe_attributes = params[:project] |
99 | |
100 | |
101 # todo: luisf: this should be removed from here... | |
102 if params && params[:project] && !params[:project][:tag_list].nil? | |
103 new_tags = params[:project][:tag_list].to_s.downcase | |
104 | |
105 @project.tag_list = ActionController::Base.helpers.strip_tags(new_tags) | |
106 end | |
107 # end of code to be removed | |
108 | 105 |
109 if validate_is_public_key && validate_parent_id && @project.save | 106 if validate_is_public_key && validate_parent_id && @project.save |
110 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 107 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
111 # Add current user as a project member if he is not admin | 108 # Add current user as a project member if he is not admin |
112 unless User.current.admin? | 109 unless User.current.admin? |
133 | 130 |
134 end | 131 end |
135 | 132 |
136 def copy | 133 def copy |
137 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 134 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
138 @trackers = Tracker.all | 135 @trackers = Tracker.sorted.all |
139 @root_projects = Project.find(:all, | 136 @root_projects = Project.find(:all, |
140 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | 137 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
141 :order => 'name') | 138 :order => 'name') |
142 @source_project = Project.find(params[:id]) | 139 @source_project = Project.find(params[:id]) |
143 if request.get? | 140 if request.get? |
144 @project = Project.copy_from(@source_project) | 141 @project = Project.copy_from(@source_project) |
145 if @project | 142 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
146 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | |
147 else | |
148 redirect_to :controller => 'admin', :action => 'projects' | |
149 end | |
150 else | 143 else |
151 Mailer.with_deliveries(params[:notifications] == '1') do | 144 Mailer.with_deliveries(params[:notifications] == '1') do |
152 @project = Project.new | 145 @project = Project.new |
153 @project.safe_attributes = params[:project] | 146 @project.safe_attributes = params[:project] |
154 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | 147 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
163 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 156 redirect_to :controller => 'projects', :action => 'settings', :id => @project |
164 end | 157 end |
165 end | 158 end |
166 end | 159 end |
167 rescue ActiveRecord::RecordNotFound | 160 rescue ActiveRecord::RecordNotFound |
168 redirect_to :controller => 'admin', :action => 'projects' | 161 # source_project not found |
169 end | 162 render_404 |
170 | 163 end |
164 | |
171 # Show @project | 165 # Show @project |
172 def show | 166 def show |
173 if params[:jump] | 167 if params[:jump] |
174 # try to redirect to the requested menu item | 168 # try to redirect to the requested menu item |
175 redirect_to_project_menu_item(@project, params[:jump]) && return | 169 redirect_to_project_menu_item(@project, params[:jump]) && return |
180 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | 174 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
181 @trackers = @project.rolled_up_trackers | 175 @trackers = @project.rolled_up_trackers |
182 | 176 |
183 cond = @project.project_condition(Setting.display_subprojects_issues?) | 177 cond = @project.project_condition(Setting.display_subprojects_issues?) |
184 | 178 |
185 @open_issues_by_tracker = Issue.visible.count(:group => :tracker, | 179 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) |
186 :include => [:project, :status, :tracker], | 180 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) |
187 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) | |
188 @total_issues_by_tracker = Issue.visible.count(:group => :tracker, | |
189 :include => [:project, :status, :tracker], | |
190 :conditions => cond) | |
191 | 181 |
192 if User.current.allowed_to?(:view_time_entries, @project) | 182 if User.current.allowed_to?(:view_time_entries, @project) |
193 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f | 183 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f |
194 end | 184 end |
195 | 185 |
203 | 193 |
204 def settings | 194 def settings |
205 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 195 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
206 @issue_category ||= IssueCategory.new | 196 @issue_category ||= IssueCategory.new |
207 @member ||= @project.members.new | 197 @member ||= @project.members.new |
208 @trackers = Tracker.all | 198 @trackers = Tracker.sorted.all |
209 @repository ||= @project.repository | |
210 @wiki ||= @project.wiki | 199 @wiki ||= @project.wiki |
211 end | 200 end |
212 | 201 |
213 def edit | 202 def edit |
214 end | 203 end |
215 | 204 |
216 # TODO: convert to PUT only | |
217 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
218 def update | 205 def update |
219 @project.safe_attributes = params[:project] | 206 @project.safe_attributes = params[:project] |
220 if validate_parent_id && @project.save | 207 if validate_parent_id && @project.save |
221 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 208 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
222 respond_to do |format| | 209 respond_to do |format| |
223 format.html { | 210 format.html { |
224 flash[:notice] = l(:notice_successful_update) | 211 flash[:notice] = l(:notice_successful_update) |
225 redirect_to :action => 'settings', :id => @project | 212 redirect_to :action => 'settings', :id => @project |
226 } | 213 } |
227 format.api { head :ok } | 214 format.api { render_api_ok } |
228 end | 215 end |
229 else | 216 else |
230 respond_to do |format| | 217 respond_to do |format| |
231 format.html { | 218 format.html { |
232 settings | 219 settings |
235 format.api { render_validation_errors(@project) } | 222 format.api { render_validation_errors(@project) } |
236 end | 223 end |
237 end | 224 end |
238 end | 225 end |
239 | 226 |
240 verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed } | |
241 | |
242 def overview | 227 def overview |
243 @project.has_welcome_page = params[:has_welcome_page] | 228 @project.has_welcome_page = params[:has_welcome_page] |
244 if @project.save | 229 if @project.save |
245 flash[:notice] = l(:notice_successful_update) | 230 flash[:notice] = l(:notice_successful_update) |
246 end | 231 end |
265 def unarchive | 250 def unarchive |
266 @project.unarchive if request.post? && !@project.active? | 251 @project.unarchive if request.post? && !@project.active? |
267 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 252 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
268 end | 253 end |
269 | 254 |
255 def close | |
256 @project.close | |
257 redirect_to project_path(@project) | |
258 end | |
259 | |
260 def reopen | |
261 @project.reopen | |
262 redirect_to project_path(@project) | |
263 end | |
264 | |
270 # Delete @project | 265 # Delete @project |
271 def destroy | 266 def destroy |
272 @project_to_destroy = @project | 267 @project_to_destroy = @project |
273 if request.get? | 268 if api_request? || params[:confirm] |
274 # display confirmation view | 269 @project_to_destroy.destroy |
275 else | 270 respond_to do |format| |
276 if api_request? || params[:confirm] | 271 format.html { redirect_to :controller => 'admin', :action => 'projects' } |
277 @project_to_destroy.destroy | 272 format.api { render_api_ok } |
278 respond_to do |format| | |
279 format.html { redirect_to :controller => 'admin', :action => 'projects' } | |
280 format.api { head :ok } | |
281 end | |
282 end | 273 end |
283 end | 274 end |
284 # hide project in layout | 275 # hide project in layout |
285 @project = nil | 276 @project = nil |
286 end | 277 end |
287 | 278 |
288 private | 279 private |
289 def find_optional_project | |
290 return true unless params[:id] | |
291 @project = Project.find(params[:id]) | |
292 authorize | |
293 rescue ActiveRecord::RecordNotFound | |
294 render_404 | |
295 end | |
296 | 280 |
297 def validate_is_public_key | 281 def validate_is_public_key |
298 # Although is_public isn't mandatory in the project model (it gets | 282 # Although is_public isn't mandatory in the project model (it gets |
299 # defaulted), it must be present in params -- it can be true or | 283 # defaulted), it must be present in params -- it can be true or |
300 # false, but it must be there. This permits us to make forms in | 284 # false, but it must be there. This permits us to make forms in |