Commit 4d50d8a6 authored by Timothy Andrew's avatar Timothy Andrew

Only show a personal access token right after its creation.

parent c75aea5e
...@@ -218,6 +218,14 @@ ...@@ -218,6 +218,14 @@
max-width: 500px max-width: 500px
} }
.created-personal-access-token {
margin: 15px 15px 0 0;
pre {
max-width: 400px;
display: inline;
}
}
.user-profile { .user-profile {
@media (max-width: $screen-xs-max) { @media (max-width: $screen-xs-max) {
.cover-block { .cover-block {
......
...@@ -9,7 +9,8 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -9,7 +9,8 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
@personal_access_token = current_user.personal_access_tokens.generate(personal_access_token_params) @personal_access_token = current_user.personal_access_tokens.generate(personal_access_token_params)
if @personal_access_token.save if @personal_access_token.save
redirect_to profile_personal_access_tokens_path, notice: "Created personal access token!" flash[:personal_access_token] = @personal_access_token.token
redirect_to profile_personal_access_tokens_path
else else
render :index render :index
end end
......
...@@ -8,6 +8,16 @@ ...@@ -8,6 +8,16 @@
%p %p
You can generate a personal access token for each application you use that needs access to GitLab. You can generate a personal access token for each application you use that needs access to GitLab.
.col-lg-9 .col-lg-9
- if flash[:personal_access_token]
.panel.panel-success
.panel-heading Success!
.panel-body
Your new personal access token has been created. Make sure to save it - you can't see it again on this page.
.created-personal-access-token
%pre= flash[:personal_access_token]
= clipboard_button(clipboard_text: flash[:personal_access_token])
%h5.prepend-top-0 %h5.prepend-top-0
Add a Personal Access Token Add a Personal Access Token
%p.profile-settings-content %p.profile-settings-content
...@@ -37,7 +47,6 @@ ...@@ -37,7 +47,6 @@
%thead %thead
%tr %tr
%th Name %th Name
%th Token
%th Created %th Created
%th Expires %th Expires
%th Actions %th Actions
...@@ -45,11 +54,6 @@ ...@@ -45,11 +54,6 @@
- @active_personal_access_tokens.each do |token| - @active_personal_access_tokens.each do |token|
%tr %tr
%td= token.name %td= token.name
%td.input-group.personal-access-tokens-token-column
%input.form-control{ type: "text", value: token.token, readonly: true }
%div.input-group-btn
%button.btn.btn-default{ type: "button", data: { clipboard_text: token.token } }
%i.fa.fa-clipboard
%td= token.created_at.to_date.to_s(:medium) %td= token.created_at.to_date.to_s(:medium)
- if token.expires_at.present? - if token.expires_at.present?
%td= token.expires_at.to_date.to_s(:medium) %td= token.expires_at.to_date.to_s(:medium)
...@@ -71,17 +75,11 @@ ...@@ -71,17 +75,11 @@
%thead %thead
%tr %tr
%th Name %th Name
%th Token
%th Created %th Created
%tbody %tbody
- @inactive_personal_access_tokens.each do |token| - @inactive_personal_access_tokens.each do |token|
%tr %tr
%td= token.name %td= token.name
%td.input-group.personal-access-tokens-token-column
%input.form-control{ type: "text", value: token.token, readonly: true }
%div.input-group-btn
%button.btn.btn-default{ type: "button", data: { clipboard_text: token.token } }
%i.fa.fa-clipboard
%td= token.created_at.to_date.to_s(:medium) %td= token.created_at.to_date.to_s(:medium)
- else - else
...@@ -91,5 +89,5 @@ ...@@ -91,5 +89,5 @@
:javascript :javascript
$(".datepicker").datepicker({ $(".datepicker").datepicker({
dateFormat: "yy-mm-dd", dateFormat: "yy-mm-dd",
onSelect: function(dateText, inst) { $("#personal_access_token_params_expires_at").val(dateText) } onSelect: function(dateText, inst) { $("#personal_access_token_expires_at").val(dateText) }
}).datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $('#personal_access_token_params_expires_at').val())); }).datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $('#personal_access_token_expires_at').val()));
...@@ -3,21 +3,35 @@ require 'spec_helper' ...@@ -3,21 +3,35 @@ require 'spec_helper'
describe 'Profile > Personal Access Tokens', feature: true, js: true do describe 'Profile > Personal Access Tokens', feature: true, js: true do
let(:user) { create(:user) } let(:user) { create(:user) }
def active_personal_access_tokens
find(".table.active-personal-access-tokens").native['innerHTML']
end
def inactive_personal_access_tokens
find(".table.inactive-personal-access-tokens").native['innerHTML']
end
def created_personal_access_token
find(".created-personal-access-token pre").native['innerHTML']
end
before do before do
login_as(user) login_as(user)
end end
describe "token creation" do describe "token creation" do
it "allows creation of a token with an optional expiry date" do it "allows creation of a token" do
visit profile_personal_access_tokens_path visit profile_personal_access_tokens_path
fill_in "Name", with: FFaker::Product.brand fill_in "Name", with: FFaker::Product.brand
expect {click_on "Add Personal Access Token"}.to change { PersonalAccessToken.count }.by(1)
active_personal_access_tokens = find(".table.active-personal-access-tokens").native['innerHTML'] expect {click_on "Add Personal Access Token"}.to change { PersonalAccessToken.count }.by(1)
expect(created_personal_access_token).to eq(PersonalAccessToken.last.token)
expect(active_personal_access_tokens).to match(PersonalAccessToken.last.name) expect(active_personal_access_tokens).to match(PersonalAccessToken.last.name)
expect(active_personal_access_tokens).to match("Never") expect(active_personal_access_tokens).to match("Never")
expect(active_personal_access_tokens).to match(PersonalAccessToken.last.token) end
it "allows creation of a token with an expiry date" do
visit profile_personal_access_tokens_path
fill_in "Name", with: FFaker::Product.brand fill_in "Name", with: FFaker::Product.brand
# Set date to 1st of next month # Set date to 1st of next month
...@@ -25,11 +39,9 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do ...@@ -25,11 +39,9 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
click_on "1" click_on "1"
expect {click_on "Add Personal Access Token"}.to change { PersonalAccessToken.count }.by(1) expect {click_on "Add Personal Access Token"}.to change { PersonalAccessToken.count }.by(1)
expect(created_personal_access_token).to eq(PersonalAccessToken.last.token)
active_personal_access_tokens = find(".table.active-personal-access-tokens").native['innerHTML']
expect(active_personal_access_tokens).to match(PersonalAccessToken.last.name) expect(active_personal_access_tokens).to match(PersonalAccessToken.last.name)
expect(active_personal_access_tokens).to match(Date.today.next_month.at_beginning_of_month.to_s) expect(active_personal_access_tokens).to match(Date.today.next_month.at_beginning_of_month.to_s(:medium))
expect(active_personal_access_tokens).to match(PersonalAccessToken.last.token)
end end
end end
...@@ -39,18 +51,14 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do ...@@ -39,18 +51,14 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
visit profile_personal_access_tokens_path visit profile_personal_access_tokens_path
click_on "Revoke" click_on "Revoke"
inactive_personal_access_tokens = find(".table.inactive-personal-access-tokens").native['innerHTML']
expect(inactive_personal_access_tokens).to match(personal_access_token.name) expect(inactive_personal_access_tokens).to match(personal_access_token.name)
expect(inactive_personal_access_tokens).to match(personal_access_token.token)
end end
it "moves expired tokens to the 'inactive' section" do it "moves expired tokens to the 'inactive' section" do
personal_access_token = create(:personal_access_token, expires_at: 5.days.ago, user: user) personal_access_token = create(:personal_access_token, expires_at: 5.days.ago, user: user)
visit profile_personal_access_tokens_path visit profile_personal_access_tokens_path
inactive_personal_access_tokens = find(".table.inactive-personal-access-tokens").native['innerHTML']
expect(inactive_personal_access_tokens).to match(personal_access_token.name) expect(inactive_personal_access_tokens).to match(personal_access_token.name)
expect(inactive_personal_access_tokens).to match(personal_access_token.token)
end end
end end
end end
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