annotate .svn/pristine/40/40a074fa4b99359e32098a2704385ed2f567928a.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 class ProjectsController < ApplicationController
Chris@1296 19 menu_item :overview
Chris@1296 20 menu_item :roadmap, :only => :roadmap
Chris@1296 21 menu_item :settings, :only => :settings
Chris@1296 22
Chris@1296 23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ]
Chris@1296 24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
Chris@1296 25 before_filter :authorize_global, :only => [:new, :create]
Chris@1296 26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
Chris@1296 27 accept_rss_auth :index
Chris@1296 28 accept_api_auth :index, :show, :create, :update, :destroy
Chris@1296 29
Chris@1296 30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
Chris@1296 31 if controller.request.post?
Chris@1296 32 controller.send :expire_action, :controller => 'welcome', :action => 'robots'
Chris@1296 33 end
Chris@1296 34 end
Chris@1296 35
Chris@1296 36 helper :sort
Chris@1296 37 include SortHelper
Chris@1296 38 helper :custom_fields
Chris@1296 39 include CustomFieldsHelper
Chris@1296 40 helper :issues
Chris@1296 41 helper :queries
Chris@1296 42 include QueriesHelper
Chris@1296 43 helper :repositories
Chris@1296 44 include RepositoriesHelper
Chris@1296 45 include ProjectsHelper
Chris@1296 46
Chris@1296 47 # Lists visible projects
Chris@1296 48 def index
Chris@1296 49 respond_to do |format|
Chris@1296 50 format.html {
Chris@1296 51 scope = Project
Chris@1296 52 unless params[:closed]
Chris@1296 53 scope = scope.active
Chris@1296 54 end
Chris@1296 55 @projects = scope.visible.order('lft').all
Chris@1296 56 }
Chris@1296 57 format.api {
Chris@1296 58 @offset, @limit = api_offset_and_limit
Chris@1296 59 @project_count = Project.visible.count
Chris@1296 60 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
Chris@1296 61 }
Chris@1296 62 format.atom {
Chris@1296 63 projects = Project.visible.find(:all, :order => 'created_on DESC',
Chris@1296 64 :limit => Setting.feeds_limit.to_i)
Chris@1296 65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
Chris@1296 66 }
Chris@1296 67 end
Chris@1296 68 end
Chris@1296 69
Chris@1296 70 def new
Chris@1296 71 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
Chris@1296 72 @trackers = Tracker.sorted.all
Chris@1296 73 @project = Project.new
Chris@1296 74 @project.safe_attributes = params[:project]
Chris@1296 75 end
Chris@1296 76
Chris@1296 77 def create
Chris@1296 78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
Chris@1296 79 @trackers = Tracker.sorted.all
Chris@1296 80 @project = Project.new
Chris@1296 81 @project.safe_attributes = params[:project]
Chris@1296 82
Chris@1296 83 if validate_parent_id && @project.save
Chris@1296 84 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
Chris@1296 85 # Add current user as a project member if he is not admin
Chris@1296 86 unless User.current.admin?
Chris@1296 87 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
Chris@1296 88 m = Member.new(:user => User.current, :roles => [r])
Chris@1296 89 @project.members << m
Chris@1296 90 end
Chris@1296 91 respond_to do |format|
Chris@1296 92 format.html {
Chris@1296 93 flash[:notice] = l(:notice_successful_create)
Chris@1296 94 redirect_to(params[:continue] ?
Chris@1296 95 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} :
Chris@1296 96 {:controller => 'projects', :action => 'settings', :id => @project}
Chris@1296 97 )
Chris@1296 98 }
Chris@1296 99 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
Chris@1296 100 end
Chris@1296 101 else
Chris@1296 102 respond_to do |format|
Chris@1296 103 format.html { render :action => 'new' }
Chris@1296 104 format.api { render_validation_errors(@project) }
Chris@1296 105 end
Chris@1296 106 end
Chris@1296 107
Chris@1296 108 end
Chris@1296 109
Chris@1296 110 def copy
Chris@1296 111 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
Chris@1296 112 @trackers = Tracker.sorted.all
Chris@1296 113 @root_projects = Project.find(:all,
Chris@1296 114 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
Chris@1296 115 :order => 'name')
Chris@1296 116 @source_project = Project.find(params[:id])
Chris@1296 117 if request.get?
Chris@1296 118 @project = Project.copy_from(@source_project)
Chris@1296 119 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
Chris@1296 120 else
Chris@1296 121 Mailer.with_deliveries(params[:notifications] == '1') do
Chris@1296 122 @project = Project.new
Chris@1296 123 @project.safe_attributes = params[:project]
Chris@1296 124 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
Chris@1296 125 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
Chris@1296 126 flash[:notice] = l(:notice_successful_create)
Chris@1296 127 redirect_to :controller => 'projects', :action => 'settings', :id => @project
Chris@1296 128 elsif !@project.new_record?
Chris@1296 129 # Project was created
Chris@1296 130 # But some objects were not copied due to validation failures
Chris@1296 131 # (eg. issues from disabled trackers)
Chris@1296 132 # TODO: inform about that
Chris@1296 133 redirect_to :controller => 'projects', :action => 'settings', :id => @project
Chris@1296 134 end
Chris@1296 135 end
Chris@1296 136 end
Chris@1296 137 rescue ActiveRecord::RecordNotFound
Chris@1296 138 # source_project not found
Chris@1296 139 render_404
Chris@1296 140 end
Chris@1296 141
Chris@1296 142 # Show @project
Chris@1296 143 def show
Chris@1296 144 if params[:jump]
Chris@1296 145 # try to redirect to the requested menu item
Chris@1296 146 redirect_to_project_menu_item(@project, params[:jump]) && return
Chris@1296 147 end
Chris@1296 148
Chris@1296 149 @users_by_role = @project.users_by_role
Chris@1296 150 @subprojects = @project.children.visible.all
Chris@1296 151 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
Chris@1296 152 @trackers = @project.rolled_up_trackers
Chris@1296 153
Chris@1296 154 cond = @project.project_condition(Setting.display_subprojects_issues?)
Chris@1296 155
Chris@1296 156 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
Chris@1296 157 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
Chris@1296 158
Chris@1296 159 if User.current.allowed_to?(:view_time_entries, @project)
Chris@1296 160 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
Chris@1296 161 end
Chris@1296 162
Chris@1296 163 @key = User.current.rss_key
Chris@1296 164
Chris@1296 165 respond_to do |format|
Chris@1296 166 format.html
Chris@1296 167 format.api
Chris@1296 168 end
Chris@1296 169 end
Chris@1296 170
Chris@1296 171 def settings
Chris@1296 172 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
Chris@1296 173 @issue_category ||= IssueCategory.new
Chris@1296 174 @member ||= @project.members.new
Chris@1296 175 @trackers = Tracker.sorted.all
Chris@1296 176 @wiki ||= @project.wiki
Chris@1296 177 end
Chris@1296 178
Chris@1296 179 def edit
Chris@1296 180 end
Chris@1296 181
Chris@1296 182 def update
Chris@1296 183 @project.safe_attributes = params[:project]
Chris@1296 184 if validate_parent_id && @project.save
Chris@1296 185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
Chris@1296 186 respond_to do |format|
Chris@1296 187 format.html {
Chris@1296 188 flash[:notice] = l(:notice_successful_update)
Chris@1296 189 redirect_to :action => 'settings', :id => @project
Chris@1296 190 }
Chris@1296 191 format.api { render_api_ok }
Chris@1296 192 end
Chris@1296 193 else
Chris@1296 194 respond_to do |format|
Chris@1296 195 format.html {
Chris@1296 196 settings
Chris@1296 197 render :action => 'settings'
Chris@1296 198 }
Chris@1296 199 format.api { render_validation_errors(@project) }
Chris@1296 200 end
Chris@1296 201 end
Chris@1296 202 end
Chris@1296 203
Chris@1296 204 def modules
Chris@1296 205 @project.enabled_module_names = params[:enabled_module_names]
Chris@1296 206 flash[:notice] = l(:notice_successful_update)
Chris@1296 207 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
Chris@1296 208 end
Chris@1296 209
Chris@1296 210 def archive
Chris@1296 211 if request.post?
Chris@1296 212 unless @project.archive
Chris@1296 213 flash[:error] = l(:error_can_not_archive_project)
Chris@1296 214 end
Chris@1296 215 end
Chris@1296 216 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
Chris@1296 217 end
Chris@1296 218
Chris@1296 219 def unarchive
Chris@1296 220 @project.unarchive if request.post? && !@project.active?
Chris@1296 221 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
Chris@1296 222 end
Chris@1296 223
Chris@1296 224 def close
Chris@1296 225 @project.close
Chris@1296 226 redirect_to project_path(@project)
Chris@1296 227 end
Chris@1296 228
Chris@1296 229 def reopen
Chris@1296 230 @project.reopen
Chris@1296 231 redirect_to project_path(@project)
Chris@1296 232 end
Chris@1296 233
Chris@1296 234 # Delete @project
Chris@1296 235 def destroy
Chris@1296 236 @project_to_destroy = @project
Chris@1296 237 if api_request? || params[:confirm]
Chris@1296 238 @project_to_destroy.destroy
Chris@1296 239 respond_to do |format|
Chris@1296 240 format.html { redirect_to :controller => 'admin', :action => 'projects' }
Chris@1296 241 format.api { render_api_ok }
Chris@1296 242 end
Chris@1296 243 end
Chris@1296 244 # hide project in layout
Chris@1296 245 @project = nil
Chris@1296 246 end
Chris@1296 247
Chris@1296 248 private
Chris@1296 249
Chris@1296 250 # Validates parent_id param according to user's permissions
Chris@1296 251 # TODO: move it to Project model in a validation that depends on User.current
Chris@1296 252 def validate_parent_id
Chris@1296 253 return true if User.current.admin?
Chris@1296 254 parent_id = params[:project] && params[:project][:parent_id]
Chris@1296 255 if parent_id || @project.new_record?
Chris@1296 256 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
Chris@1296 257 unless @project.allowed_parents.include?(parent)
Chris@1296 258 @project.errors.add :parent_id, :invalid
Chris@1296 259 return false
Chris@1296 260 end
Chris@1296 261 end
Chris@1296 262 true
Chris@1296 263 end
Chris@1296 264 end