Skip to content

Commit

Permalink
chore: add another system user for admin tokens (#5915)
Browse files Browse the repository at this point in the history
## About the changes
This admin token user will help us differentiate actions performed by
the system from actions performed with an admin token.

Events created with an admin token should have the id of this user as
createdByUserId property and the username of the token used as the
createdBy property. i.e.
```json
{
  "id": 11,
  "type": "pat-created",
  "createdBy": "admin-token",
  "createdAt": "2024-01-16T13:16:27.887Z",
  "createdByUserId": -42,
  "data": {
    "description": "admin-pat",
    "expiresAt": "2024-02-15T13:16:25.586Z",
    "secret": "***",
    "userId": 1
  },
  "preData": null,
  "tags": [],
  "featureName": null,
  "project": null,
  "environment": null
}
```
  • Loading branch information
gastonfournier committed Jan 16, 2024
1 parent d2366a8 commit 04e5583
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/types/core.ts
Expand Up @@ -30,4 +30,14 @@ export const SYSTEM_USER: Omit<IUser, 'email'> = {
permissions: [],
username: 'unleash_system_user',
};

export const ADMIN_TOKEN_USER: Omit<IUser, 'email'> = {
id: -42,
imageUrl: '',
isAPI: true,
name: 'Unleash Admin Token',
permissions: [],
username: 'unleash_admin_token',
};

export const SYSTEM_USER_ID: number = SYSTEM_USER.id;
22 changes: 22 additions & 0 deletions src/migrations/20240116154700-unleash-admin-token-user.js
@@ -0,0 +1,22 @@
'use strict';

exports.up = function (db, callback) {
db.runSql(
`
INSERT INTO users
(id, name, username, created_by_user_id, is_system)
VALUES
(-42, 'Unleash Admin Token User', 'unleash_admin_token', -1337, true);
`,
callback,
);
};

exports.down = function (db, callback) {
db.runSql(
`
DELETE FROM users WHERE id = -42;
`,
callback,
);
};

0 comments on commit 04e5583

Please sign in to comment.