Commit ffe111c1 authored by Timothy Andrew's avatar Timothy Andrew

Display appropriate errors when personal access token creation/revocation fails.

parent 399a6330
class Profiles::PersonalAccessTokensController < Profiles::ApplicationController class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
before_action :load_personal_access_tokens, only: :index
def index def index
@active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at)
@inactive_personal_access_tokens = current_user.personal_access_tokens.inactive
@personal_access_token = current_user.personal_access_tokens.build @personal_access_token = current_user.personal_access_tokens.build
end end
...@@ -12,6 +12,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -12,6 +12,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
flash[:personal_access_token] = @personal_access_token.token flash[:personal_access_token] = @personal_access_token.token
redirect_to profile_personal_access_tokens_path redirect_to profile_personal_access_tokens_path
else else
load_personal_access_tokens
render :index render :index
end end
end end
...@@ -22,7 +23,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -22,7 +23,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
if @personal_access_token.revoke! if @personal_access_token.revoke!
redirect_to profile_personal_access_tokens_path, notice: "Revoked personal access token #{@personal_access_token.name}!" redirect_to profile_personal_access_tokens_path, notice: "Revoked personal access token #{@personal_access_token.name}!"
else else
render :index redirect_to profile_personal_access_tokens_path, alert: "Could not revoke personal access token #{@personal_access_token.name}."
end end
end end
...@@ -31,4 +32,9 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -31,4 +32,9 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
def personal_access_token_params def personal_access_token_params
params.require(:personal_access_token).permit(:name, :expires_at) params.require(:personal_access_token).permit(:name, :expires_at)
end end
def load_personal_access_tokens
@active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at)
@inactive_personal_access_tokens = current_user.personal_access_tokens.inactive
end
end end
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
= form_for [:profile, @personal_access_token], = form_for [:profile, @personal_access_token],
method: :post, html: { class: 'js-requires-input' } do |f| method: :post, html: { class: 'js-requires-input' } do |f|
= form_errors(@personal_access_token)
.form-group .form-group
= f.label :name, class: 'label-light' = f.label :name, class: 'label-light'
= f.text_field :name, class: "form-control", required: true = f.text_field :name, class: "form-control", required: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment