Table of Contents

Class PermissionsDecorator<TLinkAddress>

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

The store as one subject sees it (issue #149), the C# port of withPermissions of @link-foundation/ui-links; the Rust counterpart is link_cli::PermissionsDecorator.

public class PermissionsDecorator<TLinkAddress> : LinksDecoratorBase<TLinkAddress>, INamedTypesLinks<TLinkAddress>, ILinks<TLinkAddress>, ILinks<TLinkAddress, LinksConstants<TLinkAddress>>, INamedTypes<TLinkAddress>, IReferencedLinks<TLinkAddress> where TLinkAddress : struct, IUnsignedNumber<TLinkAddress>

Type Parameters

TLinkAddress
Inheritance
LinksOperatorBase<TLinkAddress>
LinksDecoratorBase<TLinkAddress>
PermissionsDecorator<TLinkAddress>
Implements
INamedTypesLinks<TLinkAddress>
ILinks<TLinkAddress>
ILinks<TLinkAddress, LinksConstants<TLinkAddress>>
INamedTypes<TLinkAddress>
IReferencedLinks<TLinkAddress>
Derived
Inherited Members
LinksDecoratorBase<TLinkAddress>._constants
LinksDecoratorBase<TLinkAddress>._facade
LinksDecoratorBase<TLinkAddress>.Facade
LinksDecoratorBase<TLinkAddress>.Constants
LinksOperatorBase<TLinkAddress>._links
LinksOperatorBase<TLinkAddress>.Links
Extension Methods

Remarks

Each(IList<TLinkAddress>?, ReadHandler<TLinkAddress>?) and Count(IList<TLinkAddress>?) skip the links the subject may not read, so a hidden link is as missing as a deleted one: to Exists, to GetLink, and to every write, which answers Link not found. A write the subject may not make throws ForbiddenException and changes nothing. An update needs the right to write the link before and after it.

A link the subject created through this view is its own while it has no type (its source is 0), so it can give it one, and undoing the update that typed it makes it its own again. Forget(TLinkAddress) drops that claim when the link is gone, so a later link at the same address is not the subject's.

The store below may change more than the link asked for: deleting a link deletes the links that use it, and an update that makes a link equal to another merges them, repointing the usages. Every link a write changes must be the subject's to change; when one is not, the write is undone and refused as a whole.

A reference needs CanReference(TLinkAddress): without the right an unreadable address answers as a missing one, to ReferenceExists(TLinkAddress) and to an update. The write check runs first, so a type the subject may not write stays ForbiddenException for hidden and missing alike. A reference a link already holds may stay; once replaced, it cannot be put back without the right. Choosing the address of a new link (RequireAddress(TLinkAddress)) is a reference too, so a limited subject cannot choose addresses.

Names follow references: GetName(TLinkAddress) and GetByName(string) answer only for a link the subject may refer to, so any other name is an unknown name. Naming or unnaming a link needs the right to write it, and taking a name needs the right to write the link that holds it.

Constructors

public PermissionsDecorator(INamedTypesLinks<TLinkAddress> links, IPermissionPolicy<TLinkAddress> policy, Func<TLinkAddress> subject)

Parameters

links INamedTypesLinks<TLinkAddress>

The store below.

policy IPermissionPolicy<TLinkAddress>

Who may read and write what.

subject Func<TLinkAddress>

The subject, asked at every call (the null link is a guest).

public PermissionsDecorator(INamedTypesLinks<TLinkAddress> links, IPermissionPolicy<TLinkAddress> policy, TLinkAddress subject)

Parameters

links INamedTypesLinks<TLinkAddress>

The store below.

policy IPermissionPolicy<TLinkAddress>

Who may read and write what.

subject TLinkAddress

The subject (the null link is a guest).

Properties

Policy

Who may read and write what.

public IPermissionPolicy<TLinkAddress> Policy { get; }

Property Value

IPermissionPolicy<TLinkAddress>

QueryLimits

Optional admission limits for the ordinary query processor.

public QueryLimits? QueryLimits { get; }

Property Value

QueryLimits

Subject

The subject the store is seen as.

public TLinkAddress Subject { get; }

Property Value

TLinkAddress

Methods

CanRead(IList<TLinkAddress>)

Whether the subject may read link.

public virtual bool CanRead(IList<TLinkAddress> link)

Parameters

link IList<TLinkAddress>

Returns

bool

CanReference(TLinkAddress)

Whether the subject may refer to the address address, which may hold no link: a missing address is judged as an untyped link, so only a rule for Anything covers it.

public virtual bool CanReference(TLinkAddress address)

Parameters

address TLinkAddress

Returns

bool

CanWrite(IList<TLinkAddress>)

Whether the subject may write link as it is.

public virtual bool CanWrite(IList<TLinkAddress> link)

Parameters

link IList<TLinkAddress>

Returns

bool

Count(IList<TLinkAddress>?)

Counts the restriction.

public override TLinkAddress Count(IList<TLinkAddress>? restriction)

Parameters

restriction IList<TLinkAddress>

The restriction.

Returns

TLinkAddress

The link

Create(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Creates the restriction.

public override TLinkAddress Create(IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)

Parameters

substitution IList<TLinkAddress>

The restriction.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

The link

Delete(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Deletes the restriction.

public override TLinkAddress Delete(IList<TLinkAddress>? restriction, WriteHandler<TLinkAddress>? handler)

Parameters

restriction IList<TLinkAddress>

The restriction.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

Each(IList<TLinkAddress>?, ReadHandler<TLinkAddress>?)

Eaches the handler.

public override TLinkAddress Each(IList<TLinkAddress>? restriction, ReadHandler<TLinkAddress>? handler)

Parameters

restriction IList<TLinkAddress>

The restriction.

handler ReadHandler<TLinkAddress>

The handler.

Returns

TLinkAddress

The link

Forget(TLinkAddress)

The link at index is gone: a new one there is not the subject's own.

public virtual void Forget(TLinkAddress index)

Parameters

index TLinkAddress

GetByName(string)

The link of a name, when the subject may refer to it; any other name is an unknown name.

public virtual TLinkAddress GetByName(string name)

Parameters

name string

Returns

TLinkAddress

GetName(TLinkAddress)

The name of a link the subject may refer to; any other has none.

public virtual string? GetName(TLinkAddress link)

Parameters

link TLinkAddress

Returns

string

Owns(IList<TLinkAddress>)

Whether link is the subject's own: created through this view and still without a type.

public virtual bool Owns(IList<TLinkAddress> link)

Parameters

link IList<TLinkAddress>

Returns

bool

ReferenceExists(TLinkAddress)

A link the subject may not refer to is as missing as a deleted one.

public virtual bool ReferenceExists(TLinkAddress address)

Parameters

address TLinkAddress

Returns

bool

Remember(TLinkAddress)

The link at index is one the subject made on the store below.

protected void Remember(TLinkAddress index)

Parameters

index TLinkAddress

Remembers(TLinkAddress)

Whether the link at index is one the subject made through this view.

protected bool Remembers(TLinkAddress index)

Parameters

index TLinkAddress

Returns

bool

RemoveName(TLinkAddress)

public virtual void RemoveName(TLinkAddress link)

Parameters

link TLinkAddress

RequireAddress(TLinkAddress)

Choosing the address of a new link is a reference: refuses one the subject may not choose.

public virtual void RequireAddress(TLinkAddress address)

Parameters

address TLinkAddress

Only addresses that do not exist yet are allocations; a preview lists every row, and counting a hidden one would let it answer differently from a missing one. A subject who may not create gets no reservation, so its first new link is refused whether or not the same pair is hidden.

public IReadOnlySet<TLinkAddress>? ReserveQueryAllocations(Action<INamedTypesLinks<TLinkAddress>> preview)

Parameters

preview Action<INamedTypesLinks<TLinkAddress>>

Returns

IReadOnlySet<TLinkAddress>

SetName(TLinkAddress, string)

public virtual TLinkAddress SetName(TLinkAddress link, string name)

Parameters

link TLinkAddress
name string

Returns

TLinkAddress

Update(IList<TLinkAddress>?, IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)

Updates the restriction.

public override TLinkAddress Update(IList<TLinkAddress>? restriction, IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)

Parameters

restriction IList<TLinkAddress>

The restriction.

substitution IList<TLinkAddress>

The substitution.

handler WriteHandler<TLinkAddress>

Optional callback; null continues without invoking a callback.

Returns

TLinkAddress

The link