diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js
index 193a47a2a0..fb70350827 100644
--- a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js
+++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js
@@ -119,7 +119,15 @@ const ApiTokenCreateView = () => {
toggleNotification({
type: 'success',
- message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),
+ message: isCreating
+ ? formatMessage({
+ id: 'notification.success.tokencreated',
+ defaultMessage: 'API Token successfully created',
+ })
+ : formatMessage({
+ id: 'notification.success.tokenedited',
+ defaultMessage: 'API Token successfully edited',
+ }),
});
trackUsageRef.current(isCreating ? 'didCreateToken' : 'didEditToken', {
diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js
index b1e297fd18..99e01edab2 100644
--- a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js
+++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js
@@ -1,5 +1,4 @@
import React from 'react';
-import { useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
@@ -13,13 +12,11 @@ import {
pxToRem,
useTracking,
} from '@strapi/helper-plugin';
-
import DeleteButton from './DeleteButton';
import UpdateButton from './UpdateButton';
import ReadButton from './ReadButton';
const TableRows = ({ canDelete, canUpdate, canRead, onClickDelete, withBulkActions, rows }) => {
- const { formatMessage } = useIntl();
const [{ query }] = useQueryParams();
const [, sortOrder] = query.sort.split(':');
const {
@@ -60,16 +57,15 @@ const TableRows = ({ canDelete, canUpdate, canRead, onClickDelete, withBulkActio
- {formatMessage({
- id: `Settings.apiTokens.types.${apiToken.type}`,
- defaultMessage: 'Type unknown',
- })}
+
|
-
-
-
+ {apiToken.lastUsedAt && (
+
+
+
+ )}
|
{withBulkActions && (
diff --git a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/tests/index.test.js b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/tests/index.test.js
index ed83bb207c..0c1fbcb464 100644
--- a/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/tests/index.test.js
+++ b/packages/core/admin/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/tests/index.test.js
@@ -806,10 +806,10 @@ describe('ADMIN | Pages | API TOKENS | ListPage', () => {
- Token type
+ Created at
{
- Created at
+ Last used
{
aria-colindex="3"
class="c21"
tabindex="-1"
- >
-
- Type unknown
-
-
-
{
|
+ |
{
});
});
+ describe('Regenerate an API token', () => {
+ const token = {
+ id: 1,
+ name: 'api-token_tests-regenerate',
+ description: 'api-token_tests-description',
+ type: 'read-only',
+ };
+
+ test('Regenerates an API token successfully', async () => {
+ const regenerate = jest.fn().mockResolvedValue(token);
+ const getById = jest.fn().mockResolvedValue(token);
+ const created = jest.fn();
+ const ctx = createContext({ params: { id: token.id } }, { created });
+
+ global.strapi = {
+ admin: {
+ services: {
+ 'api-token': {
+ regenerate,
+ getById,
+ },
+ },
+ },
+ };
+
+ await apiTokenController.regenerate(ctx);
+
+ expect(regenerate).toHaveBeenCalledWith(token.id);
+ });
+
+ test('Fails if token not found', async () => {
+ const regenerate = jest.fn().mockResolvedValue(token);
+ const getById = jest.fn().mockResolvedValue(null);
+ const created = jest.fn();
+ const notFound = jest.fn();
+ const ctx = createContext({ params: { id: token.id } }, { created, notFound });
+
+ global.strapi = {
+ admin: {
+ services: {
+ 'api-token': {
+ regenerate,
+ getById,
+ },
+ },
+ },
+ };
+
+ await apiTokenController.regenerate(ctx);
+
+ expect(regenerate).not.toHaveBeenCalled();
+ expect(getById).toHaveBeenCalledWith(token.id);
+ expect(notFound).toHaveBeenCalledWith('API Token not found');
+ });
+ });
+
describe('Retrieve an API token', () => {
const token = {
id: 1,
diff --git a/packages/core/admin/server/tests/admin-permission.test.e2e.js b/packages/core/admin/server/tests/admin-permission.test.e2e.js
index 66b5a1898c..7e418618b1 100644
--- a/packages/core/admin/server/tests/admin-permission.test.e2e.js
+++ b/packages/core/admin/server/tests/admin-permission.test.e2e.js
@@ -293,6 +293,12 @@ describe('Role CRUD End to End', () => {
},
],
"settings": Array [
+ Object {
+ "action": "admin::api-tokens.access",
+ "category": "api tokens",
+ "displayName": "Access the API tokens settings page",
+ "subCategory": "api Tokens",
+ },
Object {
"action": "admin::api-tokens.create",
"category": "api tokens",
@@ -784,6 +790,12 @@ describe('Role CRUD End to End', () => {
},
],
"settings": Array [
+ Object {
+ "action": "admin::api-tokens.access",
+ "category": "api tokens",
+ "displayName": "Access the API tokens settings page",
+ "subCategory": "api Tokens",
+ },
Object {
"action": "admin::api-tokens.create",
"category": "api tokens",
@@ -1210,6 +1222,12 @@ describe('Role CRUD End to End', () => {
},
],
"settings": Array [
+ Object {
+ "action": "admin::api-tokens.access",
+ "category": "api tokens",
+ "displayName": "Access the API tokens settings page",
+ "subCategory": "api Tokens",
+ },
Object {
"action": "admin::api-tokens.create",
"category": "api tokens",
|