annotate .svn/pristine/9b/9bf94035a49b8aa87d158a47dd211e57ab733c6a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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