Commit 3c66af1f authored by Riccardo Padovani's avatar Riccardo Padovani Committed by Sincheol (David) Kim

Add `last_used_at` field to personal_access_token API

parent 5017e232
......@@ -40,8 +40,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a
"scopes": [
"api"
],
"active": true,
"user_id": 24,
"last_used_at": "2021-10-06T17:58:37.550Z",
"active": true,
"expires_at": null
}
]
......@@ -61,8 +62,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a
"scopes": [
"api"
],
"active": true,
"user_id": 3,
"last_used_at": "2021-10-06T17:58:37.550Z",
"active": true,
"expires_at": null
}
]
......
......@@ -3,7 +3,7 @@
module API
module Entities
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 :expires_at do |personal_access_token|
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