moding-il / bizdoc.core

Developer framework for designing organization forms
Other
2 stars 2 forks source link

Restrict components permissions #8

Closed zehavibarak closed 2 years ago

zehavibarak commented 3 years ago

BizDoc configuration components, including form, report, widget, utility, guide, folder and cube views, can be restricted by setting privileges in bizdoc.json configuration file.

{
  "Forms": [
    {
      "Privileges": {
          "Roles": ["identity-role"]
        }
    }
  ]
}

In additions to identity roles, provided by identity manager, privileges accepts a rule, which evaluates to a JavaScript expression.

{
  "Forms": [
    {
      "Privileges": {
          "Rule": ["isSystem == true"]
        }
    }
  ]
}

Refer to rules on how to introduct new rule variables.

Note that some managed components have a method you can implementate to program complex privileges, such as testing a 3rd party system. One of those is Form, which has CanCreate() method you can be override.

public class MyForm : FormBase<MyModel> {
  private readonly IHttpContext _httpContext;
  public MyForm(IHttpContext httpContext) => _httpContext = httpContext;
  ...
  public override bool CanCreate => _httpContext.Identity.IsInRole("System");
}