Skip to main content

zaun_community_protocol/permissions/restrict/
accessors.rs

1//! Read-only views of a [`Resolver`]'s per-member state.
2
3use crate::bits::Permissions;
4
5use super::super::hierarchy::{Party, Top};
6use super::Resolver;
7
8impl Resolver<'_> {
9    /// `base(m)` (steps 1–2), before any restriction; empty for a non-admitted member.
10    #[must_use]
11    pub const fn base(&self) -> Permissions {
12        self.base
13    }
14
15    /// Whether the member is the owner.
16    #[must_use]
17    pub const fn is_owner(&self) -> bool {
18        self.owner
19    }
20
21    /// Whether the member holds `ADMINISTRATOR` (and is admitted); false for the owner.
22    #[must_use]
23    pub const fn is_admin(&self) -> bool {
24        self.admin && !self.owner
25    }
26
27    /// Whether step 7a applies (never to the owner or an administrator).
28    #[must_use]
29    pub const fn is_timed_out(&self) -> bool {
30        self.timed_out
31    }
32
33    /// Whether the admission policy's waiting period still applies.
34    #[must_use]
35    pub const fn in_waiting_period(&self) -> bool {
36        self.waiting
37    }
38
39    /// The member as the management hierarchy sees it (§4).
40    #[must_use]
41    pub fn party(&self) -> Party {
42        Party {
43            id: self.subject.id,
44            is_owner: self.owner,
45            is_admin: self.is_admin(),
46            top: Top::of(self.owner, self.subject.roles),
47        }
48    }
49}