Commit ce50e231 authored by Sincheol (David) Kim's avatar Sincheol (David) Kim

Merge branch '#328043-personal-access-tokens-last-used-at' into 'master'

Add `last_used_at` field to personal_access_token API

See merge request gitlab-org/gitlab!71849
parents 9051cd17 3c66af1f
...@@ -40,8 +40,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a ...@@ -40,8 +40,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a
"scopes": [ "scopes": [
"api" "api"
], ],
"active": true,
"user_id": 24, "user_id": 24,
"last_used_at": "2021-10-06T17:58:37.550Z",
"active": true,
"expires_at": null "expires_at": null
} }
] ]
...@@ -61,8 +62,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a ...@@ -61,8 +62,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a
"scopes": [ "scopes": [
"api" "api"
], ],
"active": true,
"user_id": 3, "user_id": 3,
"last_used_at": "2021-10-06T17:58:37.550Z",
"active": true,
"expires_at": null "expires_at": null
} }
] ]
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module API module API
module Entities module Entities
class PersonalAccessToken < Grape::Entity class PersonalAccessToken < Grape::Entity
expose :id, :name, :revoked, :created_at, :scopes, :user_id expose :id, :name, :revoked, :created_at, :scopes, :user_id, :last_used_at
expose :active?, as: :active expose :active?, as: :active
expose :expires_at do |personal_access_token| expose :expires_at do |personal_access_token|
personal_access_token.expires_at ? personal_access_token.expires_at.strftime("%Y-%m-%d") : nil personal_access_token.expires_at ? personal_access_token.expires_at.strftime("%Y-%m-%d") : nil
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::PersonalAccessToken do
describe '#as_json' do
let_it_be(:user) { create(:user) }
let_it_be(:token) { create(:personal_access_token, user: user, expires_at: nil) }
let(:entity) { described_class.new(token) }
it 'returns token data' do
expect(entity.as_json).to eq({
id: token.id,
name: token.name,
revoked: false,
created_at: token.created_at,
scopes: ['api'],
user_id: user.id,
last_used_at: nil,
active: true,
expires_at: nil
})
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