You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

projects_controller.rb 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class ProjectsController < ApplicationController
  18. menu_item :overview
  19. menu_item :settings, :only => :settings
  20. before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
  21. before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
  22. before_filter :authorize_global, :only => [:new, :create]
  23. before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
  24. accept_rss_auth :index
  25. accept_api_auth :index, :show, :create, :update, :destroy
  26. after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
  27. if controller.request.post?
  28. controller.send :expire_action, :controller => 'welcome', :action => 'robots'
  29. end
  30. end
  31. helper :custom_fields
  32. helper :issues
  33. helper :queries
  34. helper :repositories
  35. helper :members
  36. # Lists visible projects
  37. def index
  38. scope = Project.visible.sorted
  39. respond_to do |format|
  40. format.html {
  41. unless params[:closed]
  42. scope = scope.active
  43. end
  44. @projects = scope.to_a
  45. }
  46. format.api {
  47. @offset, @limit = api_offset_and_limit
  48. @project_count = scope.count
  49. @projects = scope.offset(@offset).limit(@limit).to_a
  50. }
  51. format.atom {
  52. projects = scope.reorder(:created_on => :desc).limit(Setting.feeds_limit.to_i).to_a
  53. render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
  54. }
  55. end
  56. end
  57. def new
  58. @issue_custom_fields = IssueCustomField.sorted.to_a
  59. @trackers = Tracker.sorted.to_a
  60. @project = Project.new
  61. @project.safe_attributes = params[:project]
  62. end
  63. def create
  64. @issue_custom_fields = IssueCustomField.sorted.to_a
  65. @trackers = Tracker.sorted.to_a
  66. @project = Project.new
  67. @project.safe_attributes = params[:project]
  68. if @project.save
  69. unless User.current.admin?
  70. @project.add_default_member(User.current)
  71. end
  72. respond_to do |format|
  73. format.html {
  74. flash[:notice] = l(:notice_successful_create)
  75. if params[:continue]
  76. attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
  77. redirect_to new_project_path(attrs)
  78. else
  79. redirect_to settings_project_path(@project)
  80. end
  81. }
  82. format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
  83. end
  84. else
  85. respond_to do |format|
  86. format.html { render :action => 'new' }
  87. format.api { render_validation_errors(@project) }
  88. end
  89. end
  90. end
  91. def copy
  92. @issue_custom_fields = IssueCustomField.sorted.to_a
  93. @trackers = Tracker.sorted.to_a
  94. @source_project = Project.find(params[:id])
  95. if request.get?
  96. @project = Project.copy_from(@source_project)
  97. @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
  98. else
  99. Mailer.with_deliveries(params[:notifications] == '1') do
  100. @project = Project.new
  101. @project.safe_attributes = params[:project]
  102. if @project.copy(@source_project, :only => params[:only])
  103. flash[:notice] = l(:notice_successful_create)
  104. redirect_to settings_project_path(@project)
  105. elsif !@project.new_record?
  106. # Project was created
  107. # But some objects were not copied due to validation failures
  108. # (eg. issues from disabled trackers)
  109. # TODO: inform about that
  110. redirect_to settings_project_path(@project)
  111. end
  112. end
  113. end
  114. rescue ActiveRecord::RecordNotFound
  115. # source_project not found
  116. render_404
  117. end
  118. # Show @project
  119. def show
  120. # try to redirect to the requested menu item
  121. if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
  122. return
  123. end
  124. @users_by_role = @project.users_by_role
  125. @subprojects = @project.children.visible.to_a
  126. @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a
  127. @trackers = @project.rolled_up_trackers
  128. cond = @project.project_condition(Setting.display_subprojects_issues?)
  129. @open_issues_by_tracker = Issue.visible.open.where(cond).group(:tracker).count
  130. @total_issues_by_tracker = Issue.visible.where(cond).group(:tracker).count
  131. if User.current.allowed_to?(:view_time_entries, @project)
  132. @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f
  133. end
  134. @key = User.current.rss_key
  135. respond_to do |format|
  136. format.html
  137. format.api
  138. end
  139. end
  140. def settings
  141. @issue_custom_fields = IssueCustomField.sorted.to_a
  142. @issue_category ||= IssueCategory.new
  143. @member ||= @project.members.new
  144. @trackers = Tracker.sorted.to_a
  145. @wiki ||= @project.wiki || Wiki.new(:project => @project)
  146. end
  147. def edit
  148. end
  149. def update
  150. @project.safe_attributes = params[:project]
  151. if @project.save
  152. respond_to do |format|
  153. format.html {
  154. flash[:notice] = l(:notice_successful_update)
  155. redirect_to settings_project_path(@project)
  156. }
  157. format.api { render_api_ok }
  158. end
  159. else
  160. respond_to do |format|
  161. format.html {
  162. settings
  163. render :action => 'settings'
  164. }
  165. format.api { render_validation_errors(@project) }
  166. end
  167. end
  168. end
  169. def modules
  170. @project.enabled_module_names = params[:enabled_module_names]
  171. flash[:notice] = l(:notice_successful_update)
  172. redirect_to settings_project_path(@project, :tab => 'modules')
  173. end
  174. def archive
  175. unless @project.archive
  176. flash[:error] = l(:error_can_not_archive_project)
  177. end
  178. redirect_to admin_projects_path(:status => params[:status])
  179. end
  180. def unarchive
  181. unless @project.active?
  182. @project.unarchive
  183. end
  184. redirect_to admin_projects_path(:status => params[:status])
  185. end
  186. def close
  187. @project.close
  188. redirect_to project_path(@project)
  189. end
  190. def reopen
  191. @project.reopen
  192. redirect_to project_path(@project)
  193. end
  194. # Delete @project
  195. def destroy
  196. @project_to_destroy = @project
  197. if api_request? || params[:confirm]
  198. @project_to_destroy.destroy
  199. respond_to do |format|
  200. format.html { redirect_to admin_projects_path }
  201. format.api { render_api_ok }
  202. end
  203. end
  204. # hide project in layout
  205. @project = nil
  206. end
  207. end