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:
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.
Hope this helps!!!