Class: KeysController

Inherits:
ConsoleController show all
Defined in:
app/controllers/keys_controller.rb

Instance Method Summary collapse

Methods inherited from ConsoleController

#active_tab

Methods included from SshkeyAware

#sshkey_uploaded?

Methods included from DomainAware

#domain_is_missing, #user_default_domain

Methods included from CapabilityAware

#user_capabilities

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/keys_controller.rb', line 7

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

  if @key.save
    redirect_to (@first ? :back : ), :flash => {:success => 'Your public key has been created'} rescue redirect_to 
  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

#destroyObject



38
39
40
41
42
# File 'app/controllers/keys_controller.rb', line 38

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

#newObject



2
3
4
5
# File 'app/controllers/keys_controller.rb', line 2

def new
  @first = true if params[:first]
  @key = Key.new
end