uprtcl / js-uprtcl

Libraries, tools and modules to create _Prtcl web apps
http://www.uprtcl.io/
Other
43 stars 13 forks source link

Extend web2 access control logic #173

Closed pepoospina closed 4 years ago

pepoospina commented 4 years ago

Extend the UI permissions-admin component to have multiple members with different roles of canRead, canWrite and canAdmin each.

Context - Permissions UI Architecture

The permissions UI is dynamic, in the sense that the component that is used to see and configure the access control of a perspective depends of the type of permissions that entity has.

Dynamically show the access control UI for a given remote

The process starts at component (which is the one shown in the Wiki's home page), where the component is used sending it the perspective id (this.uref).

The PermissionsForEntity component loads the permissions of an object using the GraphQL query to fill this.permissions. Internally, the query uses a _context special property to read, from GQL, the patterns of an object. It then selects the accessControl property, which was registered as a pattern of a perspective here. Because the pattern was registered, _context query exposes acccessControl which is an object with a canWrite boolean property and a generic permissions object.

The permissions object is returned by the EveesRemote, and depends on each remote. For the EveesHttp, the access control is a BasicAdminAccessControlService type of object, which can be public or private, with different canRead, canWrite and canAdmin users as lists. Ultimately, the permissions for an entity is given by this HTTP request to the API.

Going back to the component, the permissions object is sent to a component called cortex-pattern, which is a component that receives an object, and renders it using the lenses registered to that component.

The pattern for an object that describes the permissions on the API is here, and it includes a lenses which uses the <permissions-admin> component to render the permissions.

This is where we currently show the "owner" as the canAdmin[0] user, and let that user make the perspective public or private.

Task - Extend UI to configure access control

Using the permissions-admin as a reference, create a new component in a file called permissions-admin-inherited.ts which will be able to show if the permissions of an entity are inherited from another one or not (use this wireframe as a guideline).

{
    delegated: boolean;
    delegatesTo: string;
    permissions: BasicAdminPermissions 
}
pepoospina commented 4 years ago

A stub with the change in the backend on access.services.ts

  async getPermissionsConfigOfElement(elementId: string, userId: string) {
    const accessConfig = await this.accessRepo.getAccessConfigOfElement(elementId, userId);
    if (!accessConfig.permissionsUid) throw new Error(`persmissions not found for element ${elementId}`);
    const permissions = this.getPermissionsConfig(accessConfig.permissionsUid);
    return {
      delegate: accessConfig.delegate,
      delegateTo: accessConfig.delegateTo,
      finDelegatedTo: accessConfig.finDelegatedTo,
      permissions: permissions
    }
  }