Revision 1034:ea5d9652c6f6 app/controllers

View differences:

app/controllers/projects_controller.rb
111 111
    end
112 112
    # end of code to be removed
113 113

  
114

  
115
    if validate_parent_id && @project.save
114
    if validate_is_public_key && validate_parent_id && @project.save
116 115
      @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
117 116
      # Add current user as a project member if he is not admin
118 117
      unless User.current.admin?
......
300 299
    render_404
301 300
  end
302 301

  
302
  def validate_is_public_key
303
    # Although is_public isn't mandatory in the project model (it gets
304
    # defaulted), it must be present in params -- it can be true or
305
    # false, but it must be there. This permits us to make forms in
306
    # which the user _has_ to select public or private (rather than
307
    # defaulting it) if we want to
308
    if params.nil? || params[:project].nil? || !params[:project].has_key?(:is_public)
309
      @project.errors.add :is_public, :public_or_private
310
      return false
311
    end
312
    true
313
  end
314

  
303 315
  # Validates parent_id param according to user's permissions
304 316
  # TODO: move it to Project model in a validation that depends on User.current
305 317
  def validate_parent_id

Also available in: Unified diff