Skip to content

Core Configuration

zehavibarak edited this page Oct 27, 2022 · 1 revision

BizDoc configures both managed and unmanaged server-side objects in bizdoc.json file.

Managed objects accepts .Net Core services using Dependency Injection (DI). BizDoc provides its own services to access its functionalities, as listed in the services.

The configuration file is updated upon initial run by BizDoc, registering all managed objects found in any of project assemblies or referenced assemblies, by administrative utilities, or edited from test editor.

Configuration file

Configuration file may span across multiple files, sharing the base file name.

For example, components in bizdoc.dev.json will be treated as components in bizdoc.json.

Changes made to any of the configuration files from BizDoc core utilities are backed up in the /backups directory.

By default, the base file name is bizdoc.json. File name can be set via program.cs AddBizDoc() options.

Access from code

IOptions<SystemOptions>

You can access BizDoc configuration file for read using IOptions:

public class MyClass {
  private readonly SystemOptions _options;
  public MyClass (IOptions<SystemOptions> options) {
    _options = options.value;
  }
  private void Do() {
    var roles = _options.Roles.Select(r => { ... });
  }
}

To modify configuration components, cast options to IConfigureOptions.

public class MyClass {
  private readonly SystemOptions _options;
  private readonly SystemConfigure _configure;
  
  public MyClass (IOptions<SystemOptions> options,
     IConfigureOptions<SystemOptions> configure) {
    _options = options.value;
    _configure = (SystemConfigure)configure;
  }
  private void Do() {
    var role = new Role {};
    _options.Roles.Add(role);
    role.MarkAsDirty();
    _configure.Save(_options);
  }
}

Set component for update using MarkAsDirty() method.

Permissions

BizDoc configuration components, including form, views, report, widget, utility, guide, folder and cube views, can be restricted to either roles or by a programmatic rule by setting privileges in bizdoc.json file.

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

Roles can be any role defined in configuration, or identity roles, provided by identity manager. In additions to, privileges can be set a rule, which evaluates to a JavaScript expression.

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

Refer to rules on how to introduce new rule variables.

Managed components may override base privileges check. A form, for instance, may override CanCreate() method to test for permissions.

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