projects_controller.rb
228 lines
| 6.9 KiB
| text/x-ruby
|
RubyLexer
|
r2861 | # Redmine - project management software | ||
|
r14856 | # Copyright (C) 2006-2016 Jean-Philippe Lang | ||
|
r330 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
|
r6773 | # | ||
|
r330 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r6773 | # | ||
|
r330 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
class ProjectsController < ApplicationController | ||||
|
r1062 | menu_item :overview | ||
menu_item :settings, :only => :settings | ||||
|
r6773 | |||
|
r15273 | before_action :find_project, :except => [ :index, :list, :new, :create, :copy ] | ||
before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] | ||||
before_action :authorize_global, :only => [:new, :create] | ||||
before_action :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | ||||
|
r6077 | accept_rss_auth :index | ||
accept_api_auth :index, :show, :create, :update, :destroy | ||||
|
r13951 | require_sudo_mode :destroy | ||
|
r3956 | |||
|
r330 | helper :custom_fields | ||
|
r783 | helper :issues | ||
|
r330 | helper :queries | ||
|
r556 | helper :repositories | ||
|
r10970 | helper :members | ||
|
r6773 | |||
|
r718 | # Lists visible projects | ||
|
r1450 | def index | ||
|
r13159 | scope = Project.visible.sorted | ||
|
r1451 | respond_to do |format| | ||
|
r6773 | format.html { | ||
|
r9700 | unless params[:closed] | ||
scope = scope.active | ||||
end | ||||
|
r13159 | @projects = scope.to_a | ||
|
r1451 | } | ||
|
r4342 | format.api { | ||
|
r4458 | @offset, @limit = api_offset_and_limit | ||
|
r13159 | @project_count = scope.count | ||
@projects = scope.offset(@offset).limit(@limit).to_a | ||||
|
r3199 | } | ||
|
r1451 | format.atom { | ||
|
r13159 | projects = scope.reorder(:created_on => :desc).limit(Setting.feeds_limit.to_i).to_a | ||
|
r2302 | render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | ||
|
r1451 | } | ||
end | ||||
|
r330 | end | ||
|
r6773 | |||
|
r3955 | def new | ||
|
r13100 | @issue_custom_fields = IssueCustomField.sorted.to_a | ||
@trackers = Tracker.sorted.to_a | ||||
|
r9015 | @project = Project.new | ||
@project.safe_attributes = params[:project] | ||||
|
r3953 | end | ||
def create | ||||
|
r13100 | @issue_custom_fields = IssueCustomField.sorted.to_a | ||
@trackers = Tracker.sorted.to_a | ||||
|
r4378 | @project = Project.new | ||
@project.safe_attributes = params[:project] | ||||
|
r3953 | |||
|
r13465 | if @project.save | ||
|
r3953 | unless User.current.admin? | ||
|
r13160 | @project.add_default_member(User.current) | ||
|
r3953 | end | ||
respond_to do |format| | ||||
|
r6773 | format.html { | ||
|
r3953 | flash[:notice] = l(:notice_successful_create) | ||
|
r10754 | if params[:continue] | ||
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} | ||||
redirect_to new_project_path(attrs) | ||||
else | ||||
redirect_to settings_project_path(@project) | ||||
end | ||||
|
r3953 | } | ||
|
r4352 | format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | ||
|
r3953 | end | ||
|
r330 | else | ||
|
r3953 | respond_to do |format| | ||
|
r3955 | format.html { render :action => 'new' } | ||
|
r4342 | format.api { render_validation_errors(@project) } | ||
|
r2651 | end | ||
|
r3953 | end | ||
|
r330 | end | ||
|
r6773 | |||
|
r2608 | def copy | ||
|
r13100 | @issue_custom_fields = IssueCustomField.sorted.to_a | ||
@trackers = Tracker.sorted.to_a | ||||
|
r2861 | @source_project = Project.find(params[:id]) | ||
|
r2608 | if request.get? | ||
|
r2861 | @project = Project.copy_from(@source_project) | ||
|
r10676 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | ||
|
r2608 | else | ||
|
r3494 | Mailer.with_deliveries(params[:notifications] == '1') do | ||
|
r4378 | @project = Project.new | ||
@project.safe_attributes = params[:project] | ||||
|
r13465 | if @project.copy(@source_project, :only => params[:only]) | ||
|
r3494 | flash[:notice] = l(:notice_successful_create) | ||
|
r10754 | redirect_to settings_project_path(@project) | ||
|
r3494 | elsif !@project.new_record? | ||
# Project was created | ||||
# But some objects were not copied due to validation failures | ||||
# (eg. issues from disabled trackers) | ||||
# TODO: inform about that | ||||
|
r10754 | redirect_to settings_project_path(@project) | ||
|
r3494 | end | ||
|
r3128 | end | ||
|
r2878 | end | ||
rescue ActiveRecord::RecordNotFound | ||||
|
r10676 | # source_project not found | ||
render_404 | ||||
|
r2608 | end | ||
|
r11188 | |||
|
r330 | # Show @project | ||
def show | ||||
|
r10994 | # try to redirect to the requested menu item | ||
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) | ||||
|
r10991 | return | ||
|
r2208 | end | ||
|
r6773 | |||
|
r2635 | @users_by_role = @project.users_by_role | ||
|
r13100 | @subprojects = @project.children.visible.to_a | ||
@news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a | ||||
|
r15158 | @trackers = @project.rolled_up_trackers.visible | ||
|
r6773 | |||
|
r1283 | cond = @project.project_condition(Setting.display_subprojects_issues?) | ||
|
r6773 | |||
|
r12317 | @open_issues_by_tracker = Issue.visible.open.where(cond).group(:tracker).count | ||
@total_issues_by_tracker = Issue.visible.where(cond).group(:tracker).count | ||||
|
r6773 | |||
|
r13893 | if User.current.allowed_to_view_all_time_entries?(@project) | ||
|
r11733 | @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f | ||
|
r1162 | end | ||
|
r6773 | |||
|
r663 | @key = User.current.rss_key | ||
|
r6773 | |||
|
r3199 | respond_to do |format| | ||
format.html | ||||
|
r4352 | format.api | ||
|
r3199 | end | ||
|
r5 | end | ||
|
r330 | |||
def settings | ||||
|
r13100 | @issue_custom_fields = IssueCustomField.sorted.to_a | ||
|
r330 | @issue_category ||= IssueCategory.new | ||
@member ||= @project.members.new | ||||
|
r13100 | @trackers = Tracker.sorted.to_a | ||
|
r13278 | @wiki ||= @project.wiki || Wiki.new(:project => @project) | ||
|
r330 | end | ||
|
r6773 | |||
|
r330 | def edit | ||
|
r3956 | end | ||
def update | ||||
|
r4378 | @project.safe_attributes = params[:project] | ||
|
r13465 | if @project.save | ||
|
r3956 | respond_to do |format| | ||
|
r6773 | format.html { | ||
|
r3956 | flash[:notice] = l(:notice_successful_update) | ||
|
r10754 | redirect_to settings_project_path(@project) | ||
|
r3956 | } | ||
|
r9792 | format.api { render_api_ok } | ||
|
r3956 | end | ||
|
r3199 | else | ||
|
r3956 | respond_to do |format| | ||
|
r6773 | format.html { | ||
|
r3956 | settings | ||
render :action => 'settings' | ||||
} | ||||
|
r4342 | format.api { render_validation_errors(@project) } | ||
|
r330 | end | ||
|
r5 | end | ||
|
r330 | end | ||
|
r4527 | |||
|
r714 | def modules | ||
|
r4527 | @project.enabled_module_names = params[:enabled_module_names] | ||
|
r3451 | flash[:notice] = l(:notice_successful_update) | ||
|
r10754 | redirect_to settings_project_path(@project, :tab => 'modules') | ||
|
r714 | end | ||
|
r330 | |||
|
r546 | def archive | ||
|
r13156 | unless @project.archive | ||
flash[:error] = l(:error_can_not_archive_project) | ||||
|
r3009 | end | ||
|
r10754 | redirect_to admin_projects_path(:status => params[:status]) | ||
|
r546 | end | ||
|
r6773 | |||
|
r546 | def unarchive | ||
|
r13156 | unless @project.active? | ||
@project.unarchive | ||||
end | ||||
|
r10754 | redirect_to admin_projects_path(:status => params[:status]) | ||
|
r546 | end | ||
|
r6773 | |||
|
r9700 | def close | ||
@project.close | ||||
redirect_to project_path(@project) | ||||
end | ||||
def reopen | ||||
@project.reopen | ||||
redirect_to project_path(@project) | ||||
end | ||||
|
r10 | # Delete @project | ||
|
r330 | def destroy | ||
|
r546 | @project_to_destroy = @project | ||
|
r8032 | if api_request? || params[:confirm] | ||
@project_to_destroy.destroy | ||||
respond_to do |format| | ||||
|
r10754 | format.html { redirect_to admin_projects_path } | ||
|
r9792 | format.api { render_api_ok } | ||
|
r3199 | end | ||
|
r330 | end | ||
|
r546 | # hide project in layout | ||
@project = nil | ||||
|
r330 | end | ||
|
r2 | end | ||