Table of Contents

Class PermissionPolicy<TLinkAddress>

Namespace
Foundation.Data.Doublets.Cli
Assembly
Foundation.Data.Doublets.Cli.dll

Permissions stored as links (issue #149), the C# port of createPolicy of @link-foundation/ui-links; the Rust counterpart is link_cli::PermissionPolicy.

public class PermissionPolicy<TLinkAddress> : IPermissionPolicy<TLinkAddress> where TLinkAddress : struct, IUnsignedNumber<TLinkAddress>, IComparisonOperators<TLinkAddress, TLinkAddress, bool>, IShiftOperators<TLinkAddress, int, TLinkAddress>, IBitwiseOperators<TLinkAddress, TLinkAddress, TLinkAddress>, IMinMaxValue<TLinkAddress>

Type Parameters

TLinkAddress
Inheritance
PermissionPolicy<TLinkAddress>
Implements
IPermissionPolicy<TLinkAddress>
Inherited Members

Remarks

A rule is a pair (g: Subject Object) marked as (r: AllowRead g) or (r: AllowWrite g): the subjects that are Subject (the subject itself, or a link of that type) may read, or read and write, the links of type Object: its values and sub-types, not the link of Object itself, which is changed by who may change its parent. Anything in either place matches every subject or every link. Types are those of ITypes<TLinkAddress> (issue #148): through any depth of sub-types and multiple inheritance; the pairs that wire the hierarchy are of type Extends.

The markers are points of the data, so every address a rule holds is an address of the data. The rules (the pairs and their marks) live in the data itself or in a store of their own. Rules in the data are links like any other: a subject that may write them may change the rules, so give Anything writes to administrators only, or keep the rules apart.

Referring to a link is a right of its own (issue #161). Without it an address the subject may not read answers Link not found, exactly as a missing one. A subject may refer to an address when it may read the link there, when it is that link, when a rule (r: AllowReference (g: Subject Object)) covers it (Object itself and the links of type Object), or when it is the Object of an AllowRead or AllowWrite rule of the subject, so User writes Note is enough to type a link as Note. AllowReference does not allow reading. A rule from Anything to Anything lets every subject refer to every link.

Constructors

The policy of the rules in rules over data, whose points named Type, Extends, AllowRead, AllowWrite, Anything and AllowReference are created when missing.

public PermissionPolicy(INamedTypesLinks<TLinkAddress> data, ILinks<TLinkAddress> rules)

Parameters

data INamedTypesLinks<TLinkAddress>
rules ILinks<TLinkAddress>
public PermissionPolicy(ILinks<TLinkAddress> rules, PermissionMarkers<TLinkAddress> markers, ITypes<TLinkAddress> types)

Parameters

rules ILinks<TLinkAddress>

The store of the rules: the data itself or a store of its own.

markers PermissionMarkers<TLinkAddress>

The markers, points of the data.

types ITypes<TLinkAddress>

The types of the data.

Properties

Markers

The markers the rules are made of.

public PermissionMarkers<TLinkAddress> Markers { get; }

Property Value

PermissionMarkers<TLinkAddress>

Rules

The store of the rules.

public ILinks<TLinkAddress> Rules { get; }

Property Value

ILinks<TLinkAddress>

Types

The types of the data.

public ITypes<TLinkAddress> Types { get; }

Property Value

ITypes<TLinkAddress>

Methods

Writes a rule into rules: subject may access the links of object. The rule is the pair (subject object) marked by (marker rule); returns the pair.

public static TLinkAddress Allow(ILinks<TLinkAddress> rules, PermissionMarkers<TLinkAddress> markers, PermissionAccess access, TLinkAddress subject, TLinkAddress @object)

Parameters

rules ILinks<TLinkAddress>
markers PermissionMarkers<TLinkAddress>
access PermissionAccess
subject TLinkAddress
object TLinkAddress

Returns

TLinkAddress

Allows(TLinkAddress, TLinkAddress, IList<TLinkAddress>)

Whether a rule of marker lets subject at link.

protected virtual bool Allows(TLinkAddress marker, TLinkAddress subject, IList<TLinkAddress> link)

Parameters

marker TLinkAddress
subject TLinkAddress
link IList<TLinkAddress>

Returns

bool

CanCreate(TLinkAddress)

Whether subject may write anything at all, and so create links.

public virtual bool CanCreate(TLinkAddress subject)

Parameters

subject TLinkAddress

Returns

bool

CanRead(TLinkAddress, IList<TLinkAddress>)

Whether subject may read link; writing allows reading.

public virtual bool CanRead(TLinkAddress subject, IList<TLinkAddress> link)

Parameters

subject TLinkAddress
link IList<TLinkAddress>

Returns

bool

CanReference(TLinkAddress, IList<TLinkAddress>)

Whether subject may refer to link although it need not read it. A missing address is asked about as an untyped link. A policy without this right allows references to readable links only.

public virtual bool CanReference(TLinkAddress subject, IList<TLinkAddress> link)

Parameters

subject TLinkAddress
link IList<TLinkAddress>

Returns

bool

CanWrite(TLinkAddress, IList<TLinkAddress>)

Whether subject may write link, as it is or as it will be.

public virtual bool CanWrite(TLinkAddress subject, IList<TLinkAddress> link)

Parameters

subject TLinkAddress
link IList<TLinkAddress>

Returns

bool

The points named AllowRead, AllowWrite, Anything and AllowReference in the data, each created as a point (x: x x) and named when missing. AllowReference comes last, so the others keep their addresses in a store made before it was added.

public static PermissionMarkers<TLinkAddress> EnsureMarkers(ILinks<TLinkAddress> links, INamedTypes<TLinkAddress> names)

Parameters

links ILinks<TLinkAddress>
names INamedTypes<TLinkAddress>

Returns

PermissionMarkers<TLinkAddress>

Granted(TLinkAddress)

The rules (Subject Object) that marker marks, in the order of their marks.

public virtual IReadOnlyList<(TLinkAddress Subject, TLinkAddress Object)> Granted(TLinkAddress marker)

Parameters

marker TLinkAddress

Returns

IReadOnlyList<(TLinkAddress Subject, TLinkAddress Object)>

IsObject(IList<TLinkAddress>, TLinkAddress)

Whether link is of type.

protected virtual bool IsObject(IList<TLinkAddress> link, TLinkAddress type)

Parameters

link IList<TLinkAddress>
type TLinkAddress

Returns

bool

IsSubject(TLinkAddress, TLinkAddress)

Whether subject is type or of it; a guest is only Anything.

protected virtual bool IsSubject(TLinkAddress subject, TLinkAddress type)

Parameters

subject TLinkAddress
type TLinkAddress

Returns

bool

ParseAccess(string)

public static PermissionAccess ParseAccess(string access)

Parameters

access string

Returns

PermissionAccess