Configuration Class
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
The standard implementation of IRepositoryConfiguration. It tells the Rule Repository who is making the current request and what that user may do, from an access mode and a list of permissions that you set from the role of the signed-in user.
Syntax
public class Configuration : CodeEffects.Rule.Repository.IRepositoryConfiguration
Build a new Configuration for every request from the user who is signed in to your application, and pass it to Context.GetResponse(..). Do not cache one and share it between users: it holds the identity and the permissions of one user.
The meaning of every member is described on IRepositoryConfiguration. This page lists the defaults.
Watch the defaults. A configuration that never sets AccessMode is ViewOnly, so every request that writes is refused. A configuration with AccessMode set to AllowAllExcept and an empty ActionList grants everything, deleting included. The list of an AllowAllExcept configuration also completes itself: withholding a permission withholds every permission that requires it. AllowOnly does not. The list you give it must already contain what each of its permissions requires, or every request fails. Test a role with Context.ValidatePermissions(..).
Combining the permissions of two roles is a union of their lists, and the union of two complete sets is always complete.
Constructors
Configuration()
Initializes a new instance of the Configuration class with the defaults listed under Properties. A new instance grants no permission at all, because AccessMode is ViewOnly, and it names no user. Set at least CurrentUserId, and set AccessMode and ActionList to what the user may do.
Properties
AccessMode
Type: CodeEffects.Rule.Common.Models.ActionPermissionMode
Gets or sets how ActionList is read: ViewOnly, AllowAllExcept or AllowOnly. The default is ViewOnly: the user sees the grids of source objects, source versions, rules and rule versions and can do nothing.
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 default is an empty HashSet. Setting it to null is the same as an empty list for AllowAllExcept (everything is granted) and for AllowOnly (nothing is granted).
Agents
Type: CodeEffects.Rule.Repository.AgentSettings
Gets or sets what AI agents may do beyond their permissions. The default is null, which means AgentSettings.Default.
Assistant
Type: CodeEffects.Rule.Repository.AssistantSettings
Gets or sets the AI Assistant and the AI Rule Editor. The default is null, which means that neither feature exists.
CurrentAgentId
Type: System.String
Gets or sets the ID of the AI agent that makes the request on behalf of a person. The default is null. Leave it null unless an agent acts for a person. See IRepositoryConfiguration.CurrentAgentId.
CurrentAgentName
Type: System.String
Gets or sets the display name of that agent. The default is null. It is valid only together with CurrentAgentId, and a name longer than 256 characters is truncated.
CurrentUserId
Type: System.String
Gets or sets the ID of the user who makes the request. The default is null, and requests fail until you set it. At most 256 characters. See IRepositoryConfiguration.CurrentUserId for what your application is responsible for.
CurrentUserName
Type: System.String
Gets or sets the display name of the user. The default is null, which keeps whatever name the repository already has for the user.
CurrentUserType
Type: CodeEffects.Rule.Repository.Common.UserType
Gets or sets what CurrentUserId is. The default is UserType.User, a person.
Limits
Type: CodeEffects.Rule.Repository.RequestLimits
Gets or sets the limits that every request is held to. The default is null, which means the defaults of RequestLimits.
Notify
Type: CodeEffects.Rule.Repository.NotificationDelegate
Gets or sets the method that receives the notifications of the repository. The default is null: no notifications are raised.
TypeResolver
Type: CodeEffects.Rule.Common.Models.GetTypeDelegate
Gets or sets the method that finds a type by name when the runtime cannot. The default is null. Pass the same method to SourceSettings.TypeResolver when you need it for both.
UiXml
Type: System.Xml.XmlDocument
Gets or sets the user interface XML document, to run the repository in another language or to reword the English text. The default is null, which means the English document that Context.GetDefaultUiXml() returns. 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. The default is null. It is ignored when it is empty or when UiXml is set.
EditorHelpXml
Type: System.Xml.XmlDocument
Gets or sets the Help XML of the rule editors inside the repository: their menus, operators, clauses and Help String, to show them in another language. The default is null, which means the editor's English document that Context.GetDefaultEditorHelpXml() returns. 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. The default is null. It is ignored when it is empty or when EditorHelpXml is set.
SourceLabelsXml
Type: System.Xml.XmlDocument
Gets or sets the source labels: the display names and descriptions of the source objects' fields, in-rule methods, actions and enumeration values in another language, keyed by each member's identity. The repository shows every source version with these labels, in its rule editors and its Source Fields; stored sources and rules don't change. The default is null, which means the sources' own names. It takes precedence over SourceLabelsXmlFile. See Help XML and Multilingual Support.
SourceLabelsXmlFile
Type: System.String
Gets or sets the full physical path to the file that holds the source labels. The default is null. It is ignored when it is empty or when SourceLabelsXml is set.
Methods
-
Returns: System.Boolean - true when the current user has the permission.
public bool CanPerform(ActionPermissionType action)
Answers from AccessMode and ActionList. Under AllowAllExcept it returns true for every permission that is not in the list. Under AllowOnly it returns true only for a permission in the list. Under ViewOnly, it returns false for every permission. The repository calls it itself. You rarely call it.
Parameters
- action (
CodeEffects.Rule.Common.Models.ActionPermissionType) - The permission to answer for.
Example
using System.Collections.Generic;
using CodeEffects.Rule.Common.Models;
using CodeEffects.Rule.Repository;
// An editor who may do everything except delete, built for the signed-in user.
var config = new Configuration
{
CurrentUserId = user.Id,
CurrentUserName = user.Name,
AccessMode = ActionPermissionMode.AllowAllExcept,
ActionList = new HashSet<ActionPermissionType>
{
ActionPermissionType.SourceDelete,
ActionPermissionType.SourceVersionDelete,
ActionPermissionType.RuleDelete,
ActionPermissionType.RuleVersionDelete
}
};