Class: ApiTokensController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api_tokens_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #api_authenticate!, #authenticated_via_token?, #current_project, #expire_revision!, #followed_projects, #no_cache, #oauth_authorize!, #read_revision, #require_login, #return_or_cache_revision!, #revision, #token_authenticate!, #unfurling?, #with_current_project

Methods included from UrlHelper

#feature_path, #link_to_project_feature

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/api_tokens_controller.rb', line 24

def create
  @api_token = current_user.api_tokens.build(params.require(:api_token).permit(:name))
  authorize! :create, @api_token

  if @api_token.save
    redirect_to edit_api_token_path(@api_token)
  else
    render action: :new, error: @api_token.errors.full_messages.to_sentence
  end
end

#destroyObject



50
51
52
53
54
55
# File 'app/controllers/api_tokens_controller.rb', line 50

def destroy
  authorize! :destroy, @api_token

  @api_token.destroy
  redirect_to my_api_tokens_path, notice: "Deleted API Token \"#{@api_token.name}\""
end

#editObject



35
36
37
38
# File 'app/controllers/api_tokens_controller.rb', line 35

def edit
  @title = "Edit API Token"
  authorize! :update, @api_token
end

#indexObject



5
6
7
8
9
# File 'app/controllers/api_tokens_controller.rb', line 5

def index
  @title = "API Tokens"
  authorize! :read, :all_api_tokens
  @api_tokens = ApiToken.all.preload(:user)
end

#mineObject



11
12
13
14
15
16
# File 'app/controllers/api_tokens_controller.rb', line 11

def mine
  @title = "My API Tokens"
  authorize! :create, ApiToken
  @api_tokens = current_user.api_tokens
  render action: :index
end

#newObject



18
19
20
21
22
# File 'app/controllers/api_tokens_controller.rb', line 18

def new
  @title = "New API Token"
  authorize! :create, ApiToken
  @api_token = ApiToken.new
end

#updateObject



40
41
42
43
44
45
46
47
48
# File 'app/controllers/api_tokens_controller.rb', line 40

def update
  authorize! :update, @api_token

  if @api_token.update_attributes(params.require(:api_token).permit(:name))
    redirect_to my_api_tokens_path
  else
    render action: :new
  end
end