IRepositoryConfiguration Interface

Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository

Summary

Tells the Rule Repository who is making the current request, what that user may do, in which language the repository speaks, and how it behaves: its notifications, its AI features, and its limits. You build one for every request.

Syntax

public interface IRepositoryConfiguration

Remarks

Every method of Context that serves a request takes a configuration. The repository does not keep users, roles or sessions of its own, so the configuration is how your application hands it the answers on every request: the identity of the signed-in user, and the permissions of that user.

The class Configuration implements this interface and covers the usual case. You set AccessMode and ActionList from the role of the signed-in user, and Configuration answers CanPerform from them. Implement the interface yourself only when you want to decide the permissions in your own code, one permission at a time, in CanPerform. An implementation must provide every member. Return null from Agents, Assistant and Limits to use the defaults.

Three groups of members matter most:

  • Who is acting. CurrentUserId is required on every request. CurrentUserName, CurrentUserType, CurrentAgentId and CurrentAgentName describe the user further. The repository stores the user against everything the user creates or changes.
  • What the user may do. AccessMode and ActionList, or your own CanPerform. A configuration that grants nothing, which is the default, lets the user see the grids of source objects, source versions, rules and rule versions, and do nothing. See the ActionPermissionType enumeration for the permissions and Context.ValidatePermissions(..) for testing a role.
  • Everything else. The language of the user interface (UiXml, UiXmlFile), of the rule editors (EditorHelpXml, EditorHelpXmlFile) and of the source objects (SourceLabelsXml, SourceLabelsXmlFile), the resolver of types (TypeResolver), the notifications (Notify), the AI features (Agents, Assistant) and the limits of a request (Limits).

Properties

  • AccessMode

    Type: CodeEffects.Rule.Common.Models.ActionPermissionMode

    Gets or sets how ActionList is read: ViewOnly allows nothing, AllowAllExcept allows everything but the listed permissions, and AllowOnly allows only the listed ones. Set it on every request, from the role of the signed-in user. The Configuration class uses ViewOnly when you do not set it.

  • ActionList

    Type: System.Collections.Generic.ISet<CodeEffects.Rule.Common.Models.ActionPermissionType>

    Gets or sets the permissions that are withheld under AllowAllExcept, or granted under AllowOnly. It is ignored under ViewOnly. The list is flat. How the permissions depend on each other is the repository's own map, and Context.ValidatePermissions(..) reports a set that breaks it.

  • Agents

    Type: CodeEffects.Rule.Repository.AgentSettings

    Gets or sets what AI agents may do beyond their permissions: limits on their test runs, whether those runs are recorded in the user activity, and whether and which data source items they may read. The limits apply to agents that reach the repository through the Code Effects MCP server and to the AI Assistant alike. Optional. null means AgentSettings.Default.

  • Assistant

    Type: CodeEffects.Rule.Repository.AssistantSettings

    Gets or sets the AI Assistant and the AI Rule Editor: the models that your application registers, and how the two features behave. Optional. When it is null, or has no models, neither feature exists for the request.

  • CurrentAgentId

    Type: System.String

    Gets or sets the ID of the AI agent that makes the request on behalf of a person. Leave it null when the person uses the repository directly, and whenever CurrentUserType is not UserType.User: an agent or a service that acts on its own is the current user itself. At most 256 characters, and never the same as CurrentUserId.

    The agent is a user of its own, of type UserType.Agent, stored on first use like any other. The person stays CurrentUserId and is credited with the work, and every activity that the request records also names the agent, so the audit trail says who acted for them. The same agent may act on its own on another request.

    Set it from your own authentication of the caller, for example the client that an access token was issued to, and never from anything that the caller says about itself. An agent can call itself whatever it likes.

  • CurrentAgentName

    Type: System.String

    Gets or sets the display name of the agent named by CurrentAgentId. Optional, and valid only together with that ID. The repository stores and refreshes it as it does CurrentUserName. A name longer than 256 characters is truncated.

  • CurrentUserId

    Type: System.String

    Gets or sets the ID of the user who makes the request. Required on every request. It is whatever your application calls its users: a login, an email address, a directory key. At most 256 characters. The repository stores it against everything the user creates or changes, and shows the display name of the user back to the people who work with the repository.

    Your application is responsible for this value being right. The repository has no user directory to check it against, so an ID it has not seen is simply a user it has not seen yet. It is stored on first use and appears from then on in every "Created By" list. A mistyped ID therefore creates a user and does not raise an error.

  • CurrentUserName

    Type: System.String

    Gets or sets the display name of the user who makes the request. Optional. When you supply it, the repository stores it the first time it sees that user and refreshes it whenever it changes, so a name that changes in your application follows into the repository on the next request. When you leave it out, whatever is already stored is kept, so forgetting it on one request never erases a name. A user who has never been given a name is shown as having none. The ID is never shown in its place.

  • CurrentUserType

    Type: CodeEffects.Rule.Repository.Common.UserType

    Gets or sets what CurrentUserId is: a person (UserType.User, the default), an AI agent that acts on its own (UserType.Agent), or a service with no person behind it (UserType.Service).

    To the repository everything that acts is a user. The type is stored with the user and shown beside the name. Whoever it is, it is credited with the work. Only a person makes a version live, takes one offline, requests or declines approval, or deletes. The saves of an agent or a service always request approval. Set it from your own authentication of the caller, never from anything that the caller says about itself. For example, a token from a client-credentials grant belongs to an agent or a service. The IDs of people, agents and services must be unique across all three types.

  • Limits

    Type: CodeEffects.Rule.Repository.RequestLimits

    Gets or sets the limits that every request is held to: the size of a request and of a stored payload, the number of filters, the number of options of a lookup, and the number of test runs at once. Optional. null means the defaults of RequestLimits.

  • Notify

    Type: CodeEffects.Rule.Repository.NotificationDelegate

    Gets or sets the method that the repository calls when something happens that people may need to hear about: approval requested for a rule version, a request declined, a version made live or taken offline. Optional. When it is null, nothing is raised.

    The repository keeps no list of who should be told. You know your users, their permissions and how to reach them, so you decide who hears about each NotificationAction and how. The repository calls the method after the change is committed, on the thread of the request. A slow method slows the request, so queue the work if it takes time. An exception that the method throws is caught and ignored, because the change it reports has already happened and the user is not told that it failed.

  • TypeResolver

    Type: CodeEffects.Rule.Common.Models.GetTypeDelegate

    Gets or sets the method that finds a type by name when the runtime cannot. Leave it null unless the repository reports that a type could not be loaded.

    A stored source definition names the types it was built from, assembly included, and the rule editor loads them again when it builds itself. A data source provider or an external method class is an example. Normally those names resolve on their own, because they name assemblies that your application already has. They do not resolve when a type has moved: renamed, versioned, or lifted into another assembly since the definition was stored. The repository asks this method for those names. Returning null for one leaves the answer of the runtime standing. It is the same method, for the same reason, as SourceSettings.TypeResolver, which the repository uses when it reads the definitions you pass to Context.SyncSources(..). An application that needs one usually needs both, and can pass the same method to each.

  • UiXml

    Type: System.Xml.XmlDocument

    Gets or sets the user interface XML document. Set it to run the repository in a language other than English, or to reword the default English. Your document replaces the default one entirely, so it must declare every node that the default declares. Translate the document that Context.GetDefaultUiXml() returns, without changing its layout or structure, and it will. A document that lacks a node, or declares one the repository does not read, fails the request with a MalformedXmlException that names what is wrong. It is ignored when it is null or has no root element, and it takes precedence over UiXmlFile.

  • UiXmlFile

    Type: System.String

    Gets or sets the full physical path to the file that holds the user interface XML document. It is not a virtual path. It is ignored when it is empty or when UiXml is set. A file that cannot be read fails the request with a MalformedXmlException.

  • EditorHelpXml

    Type: System.Xml.XmlDocument

    Gets or sets the Help XML of every rule editor the repository builds: the menus, operators, clauses, flow words and Help String messages, to show the editors in another language. Translate the document that Context.GetDefaultEditorHelpXml() returns. It is ignored when it is null or has no root element, and it takes precedence over EditorHelpXmlFile. See Help XML and Multilingual Support.

  • EditorHelpXmlFile

    Type: System.String

    Gets or sets the full physical path to the file that holds the rule editors' Help XML. It is not a virtual path. It is ignored when it is empty or when EditorHelpXml is set. A file that cannot be read fails the request with CE10262.

  • SourceLabelsXml

    Type: System.Xml.XmlDocument

    Gets or sets the source labels document: the display names and descriptions of the source objects' members in another language. Each label names its member by identity (a field by its property path, a method or action by its name and parameters, an enumeration value by its type and number), never by its display name, so one document serves every source version. The repository lays the labels over a source version wherever people read it: the rule editors' menus and rule text, the Help String, and the Source Fields tree. Stored source versions, Rule XML and the code panes keep the source's own names, and AI agents work with the source's own names, the labels given beside them. Make the document to translate with Xml.GetSourceLabelsDocument(..). It is ignored when it is null or has no root element, and it takes precedence over SourceLabelsXmlFile.

  • SourceLabelsXmlFile

    Type: System.String

    Gets or sets the full physical path to the file that holds the source labels. It is not a virtual path. It is ignored when it is empty or when SourceLabelsXml is set. A file that cannot be read fails the request with CE10263.

Methods

  • CanPerform

    Returns: System.Boolean - true when the current user has the permission.

    bool CanPerform(ActionPermissionType action)

    Says whether the current user has the permission. The repository asks this once for each permission on every request and checks the request against the answers. Configuration answers from AccessMode and ActionList. A class that implements the interface itself decides here, and the repository never allows the user past it by default.

    Parameters

    • action (CodeEffects.Rule.Common.Models.ActionPermissionType) - The permission to answer for.

    Remarks

    The answers must make a complete set. A permission that you grant without one that it requires, DraftUpdate without DraftView for example, is a configuration error, and every request then fails with a RepositoryException that carries the control number CE10218 and lists what is missing. Check the set of each role in your own tests with Context.ValidatePermissions(..). Only Configuration with AccessMode set to AllowAllExcept completes the set by itself, by withholding whatever depends on what it withholds.

    An AI agent that acts on its own or for a person, and a service, never go live, take versions offline, approve, decline or delete, whatever your answers are.

Example

using System.Collections.Generic;
using System.Xml;
using CodeEffects.Rule.Common.Models;
using CodeEffects.Rule.Repository;
using CodeEffects.Rule.Repository.Common;

// A configuration that decides permissions in its own code.
public class RoleConfiguration : IRepositoryConfiguration
{
	private readonly User user;

	public RoleConfiguration(User user)
	{
		this.user = user;
		this.CurrentUserId = user.Id;
		this.CurrentUserName = user.Name;
	}

	public ActionPermissionMode AccessMode { get; set; }
	public ISet<ActionPermissionType> ActionList { get; set; }
	public XmlDocument UiXml { get; set; }
	public string UiXmlFile { get; set; }
	public XmlDocument EditorHelpXml { get; set; }
	public string EditorHelpXmlFile { get; set; }
	public XmlDocument SourceLabelsXml { get; set; }
	public string SourceLabelsXmlFile { get; set; }
	public GetTypeDelegate TypeResolver { get; set; }
	public string CurrentUserId { get; set; }
	public string CurrentUserName { get; set; }
	public UserType CurrentUserType { get; set; } = UserType.User;
	public string CurrentAgentId { get; set; }
	public string CurrentAgentName { get; set; }
	public NotificationDelegate Notify { get; set; }
	public AgentSettings Agents { get; set; }
	public AssistantSettings Assistant { get; set; }
	public RequestLimits Limits { get; set; }

	public bool CanPerform(ActionPermissionType action)
	{
		// Administrators may do everything; everyone else may only look at drafts.
		return user.IsAdmin || action == ActionPermissionType.DraftView;
	}
}

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×