cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit access to an ADW extension to a group?

tmeedend_adv
Champ in-the-making
Champ in-the-making

Hi,

We have created 2 extensions for ADW. I would like to restrict these extensions to some functionnal groups.

We have added a rule for this: 

"features": {
    "navbar": [
      {
        "id": "my.ext.nav",
        "rules": {
          "visible": "app.isAffiche"
        },
        "items": [
          {
            "id": "my.ext.main",
            "icon": "extension",
            "title": "My extension",
            "route": "my.ext.route"
          }
        ]
      }
    ]
  }

And an Evaluator : 

    import * as rule from './my-ext.service';
    extensions.setEvaluators({
      'app.isAffiche': rule.isAffiche
    });

We add rule.isAffiche in the service, it works when we make it send true or false: 

But, then I changed to check the user groups:

export const isAffiche = (): boolean =>
{
  groupService: GroupService;
  let groupService;
  const groupsEntries: GroupEntry[] = await groupService.listAllGroupMembershipsForPerson('-me-', {maxItems: 250});
  let groupIdList = groupsEntries.map((obj) => obj.entry.id);
  groupIdList.forEach(group => {
    if (group.includes("My-authorized-group")) {
      return  true;
    }
    return false;
  });
};

But then it doesn’t work anymore. Maybe it is because there is an async call?  

Thank you for your help.

3 REPLIES 3

denys
Confirmed Champ
Confirmed Champ

Yes, the rule engine is synchronous. At this point all evaluators should be sync too.

tmeedend_adv
Champ in-the-making
Champ in-the-making

Ok, so how can we achieve that correctly? Any hint?

Thank you.

denys
Confirmed Champ
Confirmed Champ

You should already have groups as part o the user loading process: https://github.com/Alfresco/alfresco-content-app/blob/6422c32df3a1c34d0cd35624c5658e25f8942acb/proje...

That means your custom evaluators can check the "context.profile.groups" array