Skip to main content

WorkspacePolicy

Struct WorkspacePolicy 

pub struct WorkspacePolicy {
    pub workspace: String,
    pub owner: Option<String>,
    pub members: BTreeMap<String, Role>,
    pub joined: BTreeMap<String, u64>,
    pub grants: Vec<Grant>,
}
Expand description

Everything that decides authority in one workspace.

The built-in roles’ grants are the code’s (roles::role_rules): a stored policy loads with them as defined now (Self::with_current_roles), so a workspace written before a role changed gets the role as it is. Grants given in the workspace stay as stored.

Fields§

§workspace: String

The workspace this policy governs. Written under room, the name a stored policy names it by: a policy travels to devices and hosts on other builds, and their reader knows no other. The key it is read under is [StoredWorkspacePolicy]’s.

§owner: Option<String>

The owner, by person id. Structural: holds everything and cannot be removed, demoted or denied by a grant.

§members: BTreeMap<String, Role>

Members other than the owner and the role preset each holds.

§joined: BTreeMap<String, u64>

When the workspace admitted each member, Unix milliseconds, by person id. Recorded once, by whoever admitted them, and kept through role changes; a member admitted before workspaces recorded it has none. People who share a name are numbered in this order.

§grants: Vec<Grant>

Every grant in the workspace, role presets included.

Implementations§

§

impl WorkspacePolicy

pub fn new( workspace: impl Into<String>, owner: impl Into<String>, ) -> WorkspacePolicy

A new workspace: its owner and every role’s preset grants.

pub fn has_others(&self, person: &str) -> bool

Whether anyone besides person belongs to the workspace, its owner or a member: what the workspace holds is shared with them whether or not they are here right now.

pub fn unowned( workspace: impl Into<String>, presets_by: &Subject, ) -> WorkspacePolicy

A workspace with no owner yet and the role presets in place.

pub fn with_current_roles(self) -> WorkspacePolicy

The policy with each built-in role’s grants as the code defines them now (roles::current_role_grants). Whatever reads a stored policy calls it, so stored copies of a role never decide.

pub fn rehome(&mut self, workspace: impl Into<String>)

Move the policy to another workspace id: every grant on this workspace’s nodes now names workspace. Grants on other workspaces are untouched.

pub fn node(&self) -> TreePath

pub fn is_owner(&self, person: &str) -> bool

pub fn role_of(&self, person: &str) -> Option<Role>

The role a person holds: Owner for the owner, None for a non-member.

pub fn joined_at(&self, person: &str) -> Option<u64>

When the workspace admitted person, Unix milliseconds: as recorded, or for an owner the workspace has no time for, 0, as they hold it since it began. None for a non-member or a member admitted unrecorded.

pub fn is_blocked(&self, person: &str) -> bool

Whether person is blocked: their own grants deny every kind on the whole workspace. A blocked member stays on record (history keeps naming them) but holds nothing; the owner is never blocked.

pub fn active_role(&self, person: &str) -> Option<Role>

The role person acts with: their role, unless they are blocked.

pub fn block(&self, person: &str, granted_by: Subject) -> Grant

pub fn is_banned(&self, person: &str) -> bool

Whether person is banned: the workspace holds their block:<person> grant. A banned person is not admitted again until unban.

pub fn restricted_until(&self, person: &str, cx: &Context<'_>) -> Option<u64>

Until when person is restricted, if a restriction of theirs is live in cx.

pub fn is_member(&self, person: &str) -> bool

pub fn subjects_of(&self, person: &str) -> Vec<Subject>

The subjects a person is known by here: themselves and their role.

pub fn party(&self, person: &str) -> Party<'_>

pub fn person_on_device<'a>( &'a self, person: &str, foreign: bool, foreign_bound: &'a [Grant], ) -> Authority<'a>

person’s authority from one of their devices: their own, and from a device that is not theirs (foreign), held to foreign_bound and to the workspace’s grants for such devices too.

pub fn party_of(&self, subject: Subject) -> Party<'_>

The workspace’s grants naming a delegation subject (an agent, an app, a task), for bounding a person’s authority.

pub fn app_authors(&self, app: &str, cx: &Context<'_>) -> bool

Whether application app is an author in the workspace: its grants let it change its own records there (roles::app_authorship).

pub fn grants_of<'a>( &'a self, subject: &'a Subject, ) -> impl Iterator<Item = &'a Grant> + 'a

The grants naming subject.

pub fn check_action( &self, actor: &Authority<'_>, action: &str, cx: &Context<'_>, approved: bool, ) -> Result<(), Refusal>

Whether the actor may perform a governance action. approved says the host witnessed the person’s approval when the answer is Ask.

§Errors

Refusal::NotPermitted or Refusal::NeedsApproval.

pub fn spend(&mut self, spent: &[GrantId]) -> bool

Drop the Once grants among spent: an action ran on them. Any other grant named stays. Returns whether anything was dropped.

pub fn check_invite( &self, actor_person: &str, actor: &Authority<'_>, role: Role, cx: &Context<'_>, approved: bool, ) -> Result<(), Refusal>

Whether actor_person (acting through actor) may invite someone with role. An invite never carries more than the inviter’s role.

pub fn check( &self, actor_person: &str, actor: &Authority<'_>, change: &Change, cx: &Context<'_>, approved: bool, ) -> Result<(), Refusal>

Whether actor_person (acting through actor) may make change, without making it: what a door asks before it commits the change by its own means.

§Errors

As Self::apply.

pub fn apply( &mut self, actor_person: &str, actor: &Authority<'_>, change: Change, cx: &Context<'_>, approved: bool, ) -> Result<(), Refusal>

Applies a governance change made by actor_person through actor.

Leaving needs no grant: whoever removes themselves from a workspace does it by being who they are, and a ban or a restriction stops it no more than the remove action would (check_reach).

§Errors

When the action is not granted, or the change breaks a structural rule: the owner stays, roles and grants never exceed the actor’s own.

pub fn check_within( actor: &Authority<'_>, grant: &Grant, cx: &Context<'_>, ) -> Result<(), Refusal>

Whether grant gives no more than actor holds on its node, for each kind it covers. A Deny never exceeds.

§Errors

Refusal::AboveActorGrant for the first kind it exceeds.

Trait Implementations§

§

impl Clone for WorkspacePolicy

§

fn clone(&self) -> WorkspacePolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for WorkspacePolicy

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for WorkspacePolicy

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<WorkspacePolicy, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<StoredWorkspacePolicy> for WorkspacePolicy

§

fn from(stored: StoredWorkspacePolicy) -> WorkspacePolicy

Converts to this type from the input type.
§

impl PartialEq for WorkspacePolicy

§

fn eq(&self, other: &WorkspacePolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for WorkspacePolicy

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for WorkspacePolicy

§

impl StructuralPartialEq for WorkspacePolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

§

impl<T> AsAny for T
where T: 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> CommonTraits for T
where T: AsAny + Any + Debug + WasmNotSendSync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T

§

impl<T> WasmNotSync for T
where T: Sync,