From 45af6be6deae29a147c247df9f3d0caf2a14e2ee Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 15 Nov 2021 16:42:17 +0000 Subject: [PATCH 1/2] Fixing issue found by Mitch, with syncing not functioning for singular role updates. --- packages/server/src/api/controllers/user.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 908018fe51..4461cbfe24 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -115,17 +115,17 @@ exports.syncUser = async function (ctx) { tableId: InternalTables.USER_METADATA, } } - let combined - if (deleting) { - combined = { - ...metadata, - status: UserStatus.INACTIVE, - metadata: BUILTIN_ROLE_IDS.PUBLIC, - } - } else { - combined = combineMetadataAndUser(user, metadata) + let combined = !deleting + ? combineMetadataAndUser(user, metadata) + : { + ...metadata, + status: UserStatus.INACTIVE, + metadata: BUILTIN_ROLE_IDS.PUBLIC, + } + // if its null then there was no updates required + if (combined) { + await db.put(combined) } - await db.put(combined) } } ctx.body = { From 9b5909e367bb02d6f4db45cfb75d6f900333c471 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 15 Nov 2021 16:46:56 +0000 Subject: [PATCH 2/2] Adding role, as it wasn't being set in metadata. --- packages/server/src/api/controllers/user.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 4461cbfe24..6dfaf9847d 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -97,6 +97,7 @@ exports.syncUser = async function (ctx) { .map(([appId]) => appId) } for (let prodAppId of prodAppIds) { + const roleId = roles[prodAppId] const devAppId = getDevelopmentAppID(prodAppId) for (let appId of [prodAppId, devAppId]) { if (!(await doesDatabaseExist(appId))) { @@ -115,6 +116,10 @@ exports.syncUser = async function (ctx) { tableId: InternalTables.USER_METADATA, } } + // assign the roleId for the metadata doc + if (roleId) { + metadata.roleId = roleId + } let combined = !deleting ? combineMetadataAndUser(user, metadata) : {