1

In Content Hub DAM I want to create an external component, but want to be able to show or hide information based on the user permissions. Everyone is able to see my entity, but not everyone is allowed to edit.

Would this be possible in a React app? Can any one give me pointers on how to solve this?

2 Answers 2

1

You can use the following code to fetch user group in an external component.

import ReactDOM from "react-dom";
export default function createExternalRoot(container: HTMLElement) {
  return {
    async render(context: any) {
     console.log(context.user.userGroups);
    },
    unmount() {
      ReactDOM.unmountComponentAtNode(container);
    },
  };
}

Based on the user role read, you can disable the component to whom you would not like the component to be editable.

Moreover with the new version, there is a flexibility to show/hide component using settings on component. This can be enabled by clicking on the new experience at the page level on the top right corner.

With this setting, you can show/hide component based on the user member role as below:

enter image description here

You can also read permission of the user group using below code, which enlist all the permissions on the entity.

import { IEntity } from "@sitecore/sc-contenthub-webclient-sdk/dist/contracts/base/entity";
import { IUserGroupPolicy } from "@sitecore/sc-contenthub-webclient-sdk/dist/contracts/policies/user-group-policy";

var group:IEntity = await context.client.users.getUserGroupAsync("${UserGroupName}", EntityLoadConfiguration.Full);
var policy: IUserGroupPolicy = await context.client.policies.getUserGroupPolicyAsync(group.id);
console.log(policy);

Above query will return all the permissions to entity on user group such as read, write etc as below.

enter image description here

Hope this helps!!!

4
  • Would it be possible to check if a user has edit rights to the current entity?
    – Danny Paul
    Commented May 11 at 7:56
  • @DannyPaul I have modified the above answer to fetch rights to the entity, from the user group assigned to it. Hope this helps!!!
    – ckhanna
    Commented May 11 at 9:24
  • Thank you very much!
    – Danny Paul
    Commented May 11 at 15:44
  • @DannyPaul your welcome...glad it helped!!!
    – ckhanna
    Commented May 12 at 8:11
0

Just for additional information and follow-up.

I was able to get my component working with above answer from @ckhanna. I found the following call to receive permissions based on an Entity.

const permissions = await context.client.permissions.getPermissionsAsync(entityId);

This will give you a list based on the current user of the permissions that are available. I then check if "Update" is in the permissions.

Then I can handle the rest of my component one way or the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.