Sha256: 72d1da150a55c946271cece211ea0a581e7181bc3d7d6a07dff385aea8f10817

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

class KeysController < ConsoleController
  def new
    @first = true if params[:first]
    @key = Key.new
  end

  def create
    @first = true if params[:first]
    @key ||= Key.new params[:key]
    @key.as = current_user

    if @key.save
      redirect_to (@first ? :back : account_path), :flash => {:success => 'Your public key has been created'} rescue redirect_to account_path
    else
      Rails.logger.debug @key.errors.inspect
      render :new
    end

  # If a key already exists with that name
  # FIXME When resource validation is added, we may need the server to return a unique code
  # for this condition with the error, and then this logic should be moved to Key.rescue_save_failure
  # which should throw a more specific exception Key::NameExists / Key::ContentExists
  rescue Key::DuplicateName
    if @first
      if @key.default?
        @key = Key.default(:as => current_user).load(params[:key])
      else
        @key.make_unique! "#{@key.name}%s"
      end
      raise if @retried
      @retried = true
      retry
    end
    @key.errors.add(:name, 'You have already created a key with that name')
    render :new
  end

  def destroy
    @key = Key.find params[:id], :as => current_user
    @key.destroy
    redirect_to account_path
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openshift-origin-console-1.3.4 app/controllers/keys_controller.rb
openshift-origin-console-1.3.3 app/controllers/keys_controller.rb
openshift-origin-console-1.3.2 app/controllers/keys_controller.rb