From 28fbcf69ecd8d3dfca35094de59a70ffcc6f1fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Tue, 3 Jan 2023 15:15:32 +0000 Subject: [PATCH] feat: enterprise service accounts (BE) (#2806) https://linear.app/unleash/issue/2-537/back-end-for-service-accounts Supersedes https://github.com/Unleash/unleash/pull/2731 --- src/lib/db/user-store.ts | 13 +++++++++++-- .../20221221144132-service-account-users.js | 19 +++++++++++++++++++ src/server-dev.ts | 1 - 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/migrations/20221221144132-service-account-users.js diff --git a/src/lib/db/user-store.ts b/src/lib/db/user-store.ts index 7794742215..50af160180 100644 --- a/src/lib/db/user-store.ts +++ b/src/lib/db/user-store.ts @@ -100,7 +100,7 @@ class UserStore implements IUserStore { } buildSelectUser(q: IUserLookup): any { - const query = this.activeUsers(); + const query = this.activeAll(); if (q.id) { return query.where('id', q.id); } @@ -113,8 +113,17 @@ class UserStore implements IUserStore { throw new Error('Can only find users with id, username or email.'); } + activeAll(): any { + return this.db(TABLE).where({ + deleted_at: null, + }); + } + activeUsers(): any { - return this.db(TABLE).where('deleted_at', null); + return this.db(TABLE).where({ + deleted_at: null, + is_service: false, + }); } async hasUser(idQuery: IUserLookup): Promise { diff --git a/src/migrations/20221221144132-service-account-users.js b/src/migrations/20221221144132-service-account-users.js new file mode 100644 index 0000000000..f60b0e53ef --- /dev/null +++ b/src/migrations/20221221144132-service-account-users.js @@ -0,0 +1,19 @@ +exports.up = function (db, cb) { + db.runSql( + ` + ALTER table users + ADD COLUMN IF NOT EXISTS is_service boolean DEFAULT false + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + ALTER table users + DROP COLUMN is_service + `, + cb, + ); +}; diff --git a/src/server-dev.ts b/src/server-dev.ts index 231d897965..304a585ac7 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -41,7 +41,6 @@ process.nextTick(async () => { responseTimeWithAppName: true, variantsPerEnvironment: true, maintenance: false, - serviceAccounts: true, }, }, authentication: {