diff --git a/api/Project.js b/api/Project.js index 48aea229..a7c9738a 100644 --- a/api/Project.js +++ b/api/Project.js @@ -139,6 +139,7 @@ export default class Project { throw new Error(`Error removing member: ${response.status}`) } + delete this.collaborators[userId] return await response } catch (error) { userMessage(error.message) @@ -160,6 +161,9 @@ export default class Project { throw new Error(`Error promoting user to LEADER: ${response.status}`) } + if (this.collaborators[userId] && !this.collaborators[userId].roles.includes("LEADER")) { + this.collaborators[userId].roles.push("LEADER") + } return response } catch (error) { userMessage(error.message) @@ -181,6 +185,9 @@ export default class Project { throw new Error(`Error removing LEADER role: ${response.status}`) } + if (this.collaborators[userId]) { + this.collaborators[userId].roles = this.collaborators[userId].roles.filter(role => role !== "LEADER") + } return response } catch (error) { userMessage(error.message) @@ -201,8 +208,9 @@ export default class Project { if (!response.ok) { throw new Error(`Error revoking write access: ${response.status}`) } - - return response + if (this.collaborators[userId]) { + this.collaborators[userId].roles = ["VIEWER"] + } return response } catch (error) { userMessage(error.message) } @@ -223,6 +231,9 @@ export default class Project { throw new Error(`Error setting user roles: ${response.status}`) } + if (this.collaborators[userId]) { + this.collaborators[userId].roles = roles + } return response } catch (error) { userMessage(error.message) diff --git a/components/manage-role/index.js b/components/manage-role/index.js index 76b0a927..0819730d 100644 --- a/components/manage-role/index.js +++ b/components/manage-role/index.js @@ -18,6 +18,8 @@ class ManageRole extends HTMLElement { permissions = [] isExistingRole = false + /** @type {Object} Local cache of roles for this component */ + group = {} constructor() { super() @@ -55,10 +57,11 @@ class ManageRole extends HTMLElement { 'Authorization': `Bearer ${TPEN.getAuthorization()}` } }).then(response => response.json()) - this.render(group) + this.group = group || {} + this.render(this.group) } - render(group) { + render(group = this.group) { this.shadowRoot.innerHTML = ` -
-