/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a // license agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// import { IHttpClient } from "./IHttpClient"; import { json } from "./impl/Utils"; /** * A roles determines what permissions {@link User | users} have on a {@link Project | project}. */ export class Role { private _data: any; protected projectId: string; protected httpClient: IHttpClient; /** * @param data - An object that implements role data storage. * @param projectId - Owner project ID. * @param httpClient - Http client. */ constructor(data: any, projectId: string, httpClient: IHttpClient) { this.httpClient = httpClient; this.projectId = projectId; this.data = data; } private internalGet() { return this.httpClient.get(`/projects/${this.projectId}/roles/${this.name}`); } private internalPut(body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null) { return this.httpClient.put(`/projects/${this.projectId}/roles/${this.name}`, body); } private internalDelete() { return this.httpClient.delete(`/projects/${this.projectId}/roles/${this.name}`); } /** * Role description. */ get description(): string { return this.data.description; } set description(value: string) { this._data.description = value; } /** * Raw role data received from the server. * * @readonly */ get data(): any { return this._data; } set data(value: any) { this._data = value; } /** * Role name. */ get name(): string { return this.data.name; } set name(value: string) { this._data.name = value; } /** * Role actions are allowed to be performed. * * @property {string[]} projectActions - Actions are allowed to be performed at the project * level: `update`, `createTopic`, `createDocument`. * @property {string[]} topicActions - Actions are allowed to be performed at the topic * level: `update`, `updateBimSnippet`, `updateRelatedTopics`, `updateDocumentReferences`, * `updateFiles`, `createComment`, `createViewpoint`, `delete`. * @property {string[]} commentActions - Actions are allowed to be performed at the comment * level: `update`, `delete`. * @property {string[]} viewpointActions - Actions are allowed to be performed at the * viewpoint level: `delete`. * @property {string[]} odaGroupActions - Actions are allowed to be performed at the members * level: `update`, `delete`. * @property {string[]} odaRoleActions - Actions are allowed to be performed at the roles * level: `update`, `delete`. */ get permissions(): any { return this.data.permissions; } set permissions(value: any) { this.data.permissions = value || {}; } /** * Refresh role data. * * @async */ async checkout(): Promise { this.data = await json(this.internalGet()); return this; } /** * Update role data on the server. * * @async * @param data - Raw role data. */ async update(data: any): Promise { this.data = await json(this.internalPut(data)); return this; } /** * Delete a role from the project. * * @async * @returns Returns the raw data of a deleted role. */ delete(): Promise { return json(this.internalDelete()); } /** * Save role data changes to the server. Call this method to update role data on the server * after any changes. * * @async */ save(): Promise { return this.update(this.data); } }