From ca03ef35b9392a6cfd54196836ac892b30a60b89 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Mon, 8 Jan 2024 17:41:38 -0500 Subject: [PATCH] treat LEFT role as special case --- src/capabilities.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/capabilities.js b/src/capabilities.js index ecc8a2d4..97a6b136 100644 --- a/src/capabilities.js +++ b/src/capabilities.js @@ -43,12 +43,7 @@ export const CREATOR_CAPABILITIES = { { readOwn: true, writeOwn: true, readOthers: true, writeOthers: true }, ] }), - roleAssignment: [ - COORDINATOR_ROLE_ID, - MEMBER_ROLE_ID, - BLOCKED_ROLE_ID, - LEFT_ROLE_ID, - ], + roleAssignment: [COORDINATOR_ROLE_ID, MEMBER_ROLE_ID, BLOCKED_ROLE_ID], sync: { auth: 'allowed', config: 'allowed', @@ -76,8 +71,7 @@ export const NO_ROLE_CAPABILITIES = { { readOwn: true, writeOwn: true, readOthers: false, writeOthers: false }, ] }), - // TODO: Does this make sense? - roleAssignment: [LEFT_ROLE_ID], + roleAssignment: [], sync: { auth: 'allowed', config: 'allowed', @@ -97,7 +91,7 @@ export const DEFAULT_CAPABILITIES = { { readOwn: true, writeOwn: true, readOthers: true, writeOthers: false }, ] }), - roleAssignment: [LEFT_ROLE_ID], + roleAssignment: [], sync: { auth: 'allowed', config: 'allowed', @@ -114,12 +108,7 @@ export const DEFAULT_CAPABILITIES = { { readOwn: true, writeOwn: true, readOthers: true, writeOthers: true }, ] }), - roleAssignment: [ - COORDINATOR_ROLE_ID, - MEMBER_ROLE_ID, - BLOCKED_ROLE_ID, - LEFT_ROLE_ID, - ], + roleAssignment: [COORDINATOR_ROLE_ID, MEMBER_ROLE_ID, BLOCKED_ROLE_ID], sync: { auth: 'allowed', config: 'allowed', @@ -288,10 +277,6 @@ export class Capabilities { * @param {keyof typeof DEFAULT_CAPABILITIES} roleId */ async assignRole(deviceId, roleId) { - if (deviceId !== this.#ownDeviceId && roleId === LEFT_ROLE_ID) { - throw new Error('Can only assign LEFT role to your own device') - } - let fromIndex = 0 let authCoreId try { @@ -315,8 +300,15 @@ export class Capabilities { ) } const ownCapabilities = await this.getCapabilities(this.#ownDeviceId) - if (!ownCapabilities.roleAssignment.includes(roleId)) { - throw new Error('No capability to assign role ' + roleId) + + if (roleId === LEFT_ROLE_ID) { + if (deviceId !== this.#ownDeviceId) { + throw new Error('Cannot assign LEFT role to another device') + } + } else { + if (!ownCapabilities.roleAssignment.includes(roleId)) { + throw new Error('No capability to assign role ' + roleId) + } } const existingRoleDoc = await this.#dataType