BigW Consortium Gitlab

Commit fb2da679 by Timothy Andrew

Add an "Inactive Personal Access Tokens" section.

- Show the count for each section in parens - Remove the `revoked?` check, because everything in the active section is guaranteed to not be revoked.
parent 41b4e119
...@@ -211,4 +211,8 @@ ...@@ -211,4 +211,8 @@
.personal-access-tokens-never-expires-label { .personal-access-tokens-never-expires-label {
color: #bbb; color: #bbb;
}
.personal-access-tokens-token-column {
max-width: 500px
} }
\ No newline at end of file
class Profiles::PersonalAccessTokensController < Profiles::ApplicationController class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
def index def index
@user = current_user @active_personal_access_tokens = current_user.personal_access_tokens.active.order(:expires_at)
@inactive_personal_access_tokens = current_user.personal_access_tokens.inactive
# Prefer this to `@user.personal_access_tokens.new`, because it # Prefer this to `@user.personal_access_tokens.new`, because it
# litters the view's call to `@user.personal_access_tokens` with # litters the view's call to `@user.personal_access_tokens` with
......
class PersonalAccessToken < ActiveRecord::Base class PersonalAccessToken < ActiveRecord::Base
belongs_to :user belongs_to :user
scope :active, -> { where.not(revoked: true).where("expires_at >= :current", current: Time.current) } scope :active, -> { where(revoked: false).where("expires_at >= :current OR expires_at IS NULL", current: Time.current) }
scope :inactive, -> { where("revoked = true OR expires_at < :current", current: Time.current) }
def self.generate(params) def self.generate(params)
personal_access_token = self.new(params) personal_access_token = self.new(params)
......
...@@ -27,38 +27,64 @@ ...@@ -27,38 +27,64 @@
%hr %hr
%h5 %h5= "Active Personal Access Tokens (#{@active_personal_access_tokens.count})"
Active Personal Access Tokens
- if @user.personal_access_tokens.exists? - if @active_personal_access_tokens.exists?
.table-responsive .table-responsive
%table.table.table-striped %table.table.table-striped.table-hover
%thead %thead
%tr %tr
%th Name %th Name
%th Token %th Token
%th Created At %th Created
%th Expires At %th Expires
%th Actions %th Actions
%tbody %tbody
- @user.personal_access_tokens.order("revoked, expires_at").each do |token| - @active_personal_access_tokens.active.each do |token|
%tr %tr
%td= token.name %td= token.name
%td= token.token %td.input-group.personal-access-tokens-token-column
%td= token.created_at %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
- if token.expires_at.present? - if token.expires_at.present?
%td= token.expires_at.to_date %td= token.expires_at.to_date
- else - else
%td %td
%span.personal-access-tokens-never-expires-label Never %span.personal-access-tokens-never-expires-label Never
- if token.revoked? %td= link_to "Revoke", revoke_profile_personal_access_token_path(token), method: :put, class: "btn btn-danger", data: {confirm: t('profile.personal_access_tokens.revoke.confirmation')}
%td
%span.personal-access-tokens-revoked-label Revoked
- else
%td= link_to "Revoke", revoke_profile_personal_access_token_path(token), method: :put, class: "btn btn-danger", data: {confirm: t('profile.personal_access_tokens.revoke.confirmation')}
- else - else
%span You don't have any tokens yet. %span You don't have any active tokens yet.
%hr
%h5= "Inactive Personal Access Tokens (#{@inactive_personal_access_tokens.count})"
- if @inactive_personal_access_tokens.exists?
.table-responsive
%table.table.table-striped.table-hover
%thead
%tr
%th Name
%th Token
%th Created
%tbody
- @inactive_personal_access_tokens.order("revoked, expires_at").each do |token|
%tr
%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
- else
%span No inactive tokens.
:javascript :javascript
$(".datepicker").datepicker({ $(".datepicker").datepicker({
......
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