pub struct CommunityRoles {
pub roles: Vec<Role>,
pub grants: Vec<MemberGrant>,
pub everyone: Option<Permissions>,
pub overwrites: Vec<Overwrite>,
pub syncs: BTreeMap<String, String>,
pub legacy_channels: Option<BTreeSet<String>>,
pub creators: BTreeMap<String, String>,
}Expand description
The role graph a client AGGREGATES from the fetched per-entity events (RoleMetadata + per-member Grant). Not an on-wire document — the enforcement engine queries this.
Fields§
§roles: Vec<Role>§grants: Vec<MemberGrant>§everyone: Option<Permissions>What every member holds before any Role (CORD-04 §2), once Roles v2 is active.
overwrites: Vec<Overwrite>Channel permission overwrites (CORD-04 §8), on Roles v2.
syncs: BTreeMap<String, String>Channels that take their Category’s overwrites instead of their own: channel → category.
legacy_channels: Option<BTreeSet<String>>The Channels that stood before Roles v2 (CORD-04 §2), as the activating @everyone
listed them: the only ones an unmarked Channel edition may still describe.
creators: BTreeMap<String, String>Private Channels’ creators, as each Channel’s sealed metadata names them: channel → member.
Implementations§
Source§impl CommunityRoles
impl CommunityRoles
Sourcepub fn roles_of<'a>(
&'a self,
member_hex: &'a str,
) -> impl Iterator<Item = &'a Role> + 'a
pub fn roles_of<'a>( &'a self, member_hex: &'a str, ) -> impl Iterator<Item = &'a Role> + 'a
The roles granted to member_hex (resolved through the grant list).
Sourcepub fn channel_permissions_holding(
&self,
owner_hex: Option<&str>,
member_hex: &str,
channel_hex: &str,
role_ids: &[String],
private: bool,
) -> Permissions
pub fn channel_permissions_holding( &self, owner_hex: Option<&str>, member_hex: &str, channel_hex: &str, role_ids: &[String], private: bool, ) -> Permissions
A member’s permissions in one Channel (CORD-04 §8), holding role_ids (their Grant,
or one about to replace it): server permissions, then the Channel’s @everyone
overwrite, its Roles’ denies then allows, and their own overwrite last. Without
VIEW_CHANNEL they hold nothing there. The owner holds everything. A private Channel
is closed to @everyone whatever its overwrites say: only a Role’s or a member’s
allow opens it, so no overwrite a manager can clear is all that keeps it private.
Sourcepub fn everyone_sends(&self, channel_hex: &str) -> bool
pub fn everyone_sends(&self, channel_hex: &str) -> bool
Whether @everyone, resolved up to the View Channel step, may post in a Channel: one
where it can’t is restricted (CORD-03 §1). A legacy Roster restricts nothing.
Sourcepub fn everyone_writes_nothing(&self, channel_hex: &str) -> bool
pub fn everyone_writes_nothing(&self, channel_hex: &str) -> bool
Whether @everyone, resolved the same way, may write nothing in a Channel: no post, no
reaction, no call. Such a Channel is Locked: every write takes its writer key. A legacy
Roster locks nothing.
Sourcepub fn everyone_reads_history(&self, channel_hex: &str) -> bool
pub fn everyone_reads_history(&self, channel_hex: &str) -> bool
Whether @everyone, resolved the same way, reads a Channel’s history: its earlier planes are
then every member’s (CORD-03 §2). A legacy Roster holds no such bit, and reads it.
Sourcepub fn channel_permissions(
&self,
owner_hex: Option<&str>,
member_hex: &str,
channel_hex: &str,
private: bool,
) -> Permissions
pub fn channel_permissions( &self, owner_hex: Option<&str>, member_hex: &str, channel_hex: &str, private: bool, ) -> Permissions
Self::channel_permissions_holding for the Roles the member holds now.
Sourcepub fn effective_permissions(&self, member_hex: &str) -> Permissions
pub fn effective_permissions(&self, member_hex: &str) -> Permissions
Effective permissions for a member: @everyone and every granted Role’s bits.
Sourcepub fn permissions_above(&self, member_hex: &str, bound: u32) -> Permissions
pub fn permissions_above(&self, member_hex: &str, bound: u32) -> Permissions
The permissions a member holds through Roles positioned strictly above bound: the only
standing an action on something at bound may draw on (CORD-04 §3). Authority then flows
strictly downward, so no Role can prop up the authority that admits it.
Sourcepub fn has_permission(&self, member_hex: &str, bits: u64) -> bool
pub fn has_permission(&self, member_hex: &str, bits: u64) -> bool
True iff the member’s effective permissions include every bit in bits.
Sourcepub fn highest_position(&self, member_hex: &str) -> Option<u32>
pub fn highest_position(&self, member_hex: &str) -> Option<u32>
Highest authority (lowest position index) among the member’s roles; None if
they hold no role. The owner (implicit position 0) is handled by the caller.
Sourcepub fn is_privileged(&self, member_hex: &str) -> bool
pub fn is_privileged(&self, member_hex: &str) -> bool
True iff the member holds at least one role (i.e. is privileged below the owner).
Sourcepub fn is_admin(&self, member_hex: &str) -> bool
pub fn is_admin(&self, member_hex: &str) -> bool
True iff the member holds a role with management permissions — an “admin” (vs. a member who holds only a non-management/social role). Drives the member-list crown.
Sourcepub fn is_staff(&self, member_hex: &str, owner_hex: Option<&str>) -> bool
pub fn is_staff(&self, member_hex: &str, owner_hex: Option<&str>) -> bool
Whether a member is STAFF (CORD-04 §3): the owner, or any holder of a
Control-writing bit (Permissions::STAFF_MASK) — the set entitled to
the control_root (CORD-02 §2).
Sourcepub fn roles_make_staff(&self, role_ids: &[String]) -> bool
pub fn roles_make_staff(&self, role_ids: &[String]) -> bool
Whether a grant’s role set leaves its member staff, judged against this
roster’s role definitions — the granter-side trigger for delivering the
control_root inside the Grant itself (CORD-04 §3). An id with no known
definition contributes nothing (never a reason to hand out the secret).
Is actor_hex authorized for an action requiring permission? The owner (the
proven owner npub, if known) is supreme and always authorized; otherwise the actor must hold
a role granting permission. This is the grant-set check the inner-author-proof gates on: a
demoted member is no longer in the grant set, so their actions stop being honored.
Every grantee is_authorized for permission, found in one pass
over the grants rather than one scan of them per member.
Sourcepub fn can_manage_position(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_position: u32,
) -> bool
pub fn can_manage_position( &self, actor_hex: &str, owner_hex: Option<&str>, target_position: u32, ) -> bool
escalation defense — may actor_hex manage something sitting at target_position
(grant/revoke/edit/reorder a role)? The actor must strictly outrank it (their highest
authority is a lower position number) AND hold MANAGE_ROLES. The owner is supreme
(implicit position 0, above every role) and always may. Equal cannot act on equal: an admin
can never grant/revoke a peer admin at the same position — only someone strictly above can.
This is what stops an admin granting the Admin role (pos == pos, refused) while still
letting them manage any role beneath them.
Sourcepub fn can_manage_member(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_hex: &str,
) -> bool
pub fn can_manage_member( &self, actor_hex: &str, owner_hex: Option<&str>, target_hex: &str, ) -> bool
May actor_hex act on MEMBER target_hex for a role change (add/remove a role)? Resolves the
target’s highest authority and applies the MANAGE_ROLES position rule. The owner is never a
valid target (supreme, unremovable — the sole hardcoded exception).
Sourcepub fn outranks(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_position: u32,
) -> bool
pub fn outranks( &self, actor_hex: &str, owner_hex: Option<&str>, target_position: u32, ) -> bool
The pure position test (no permission bit): does actor_hex strictly outrank
target_position? The owner (implicit position 0) outranks everything; a roleless actor
outranks nothing. This is the position half of every authority check — callers AND it with the
specific permission the action needs (BAN, MANAGE_MESSAGES, MANAGE_ROLES, …).
Sourcepub fn can_act_on_position(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_position: u32,
permission: u64,
) -> bool
pub fn can_act_on_position( &self, actor_hex: &str, owner_hex: Option<&str>, target_position: u32, permission: u64, ) -> bool
Generalized authority test: may actor_hex perform an action requiring permission against a
target at target_position? Owner is supreme; otherwise the actor must hold permission AND
strictly outrank the target. (can_manage_position is this with MANAGE_ROLES; bans pass
BAN, moderation-hides pass MANAGE_MESSAGES.)
Sourcepub fn can_act_on_member(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_hex: &str,
permission: u64,
) -> bool
pub fn can_act_on_member( &self, actor_hex: &str, owner_hex: Option<&str>, target_hex: &str, permission: u64, ) -> bool
Generalized member-targeting authority test (ban / kick / hide / role-change). The owner is
never a valid target; a roleless member sits below everyone. The actor needs permission
plus a strict outrank of the target’s highest role.
Sourcepub fn may_name(
&self,
actor_hex: &str,
owner_hex: Option<&str>,
target_hex: &str,
) -> bool
pub fn may_name( &self, actor_hex: &str, owner_hex: Option<&str>, target_hex: &str, ) -> bool
May actor_hex set target_hex’s Nickname (CORD-04 §10)? Their own takes CHANGE_NICKNAME,
@everyone’s included, and a legacy Roster restricts nobody’s; anyone else’s takes
MANAGE_NICKNAMES and a strict outrank.
Sourcepub fn channel_roles(&self, channel_hex: &str) -> Vec<&Role>
pub fn channel_roles(&self, channel_hex: &str) -> Vec<&Role>
The roles conferring read access to channel_hex, in display order
(highest authority first).
A Private Channel with none is readable by nobody but the owner and whoever already holds the key — degenerate rather than “open”, so clients shouldn’t create it, but one arriving that way from elsewhere still reads correctly and its key holders keep reading it.
Sourcepub fn channel_role_ids(&self, channel_hex: &str) -> Vec<String>
pub fn channel_role_ids(&self, channel_hex: &str) -> Vec<String>
channel_roles, by id.
Sourcepub fn is_entitled(
&self,
owner_hex: Option<&str>,
member_hex: &str,
channel_hex: &str,
with: &[String],
without: &[String],
) -> bool
pub fn is_entitled( &self, owner_hex: Option<&str>, member_hex: &str, channel_hex: &str, with: &[String], without: &[String], ) -> bool
Is member_hex entitled to channel_hex’s key? The owner always is
(position 0, supreme and unremovable).
with/without overlay a Grant that was JUST published, so a caller can
settle key custody against the change it just made rather than against a
fold that lags its own publish.
Sourcepub fn reads_history(
&self,
owner_hex: Option<&str>,
member_hex: &str,
channel_hex: &str,
with: &[String],
without: &[String],
) -> bool
pub fn reads_history( &self, owner_hex: Option<&str>, member_hex: &str, channel_hex: &str, with: &[String], without: &[String], ) -> bool
Whether member_hex may read channel_hex’s history from before their access began,
under the same overlay as Self::is_entitled. Legacy rosters have no such bit.
Sourcepub fn effective_permissions_in(
&self,
member_hex: &str,
channel_hex: &str,
) -> Permissions
pub fn effective_permissions_in( &self, member_hex: &str, channel_hex: &str, ) -> Permissions
Effective permissions for an action TARGETING one channel: server-scope roles plus roles scoped to that channel.
⚠️ Offer-side only. The fold stays scope-agnostic in every
implementation (CORD-04 §3, and effective_permissions is what judges
inbound authority) — this narrows only what THIS client offers its own
user, never what it honors from others. Tightening the honor path would
retroactively invalidate actions shipped clients already folded.
is_authorized, judged against one channel per
effective_permissions_in. Offer-side only.
Trait Implementations§
Source§impl Clone for CommunityRoles
impl Clone for CommunityRoles
Source§impl Debug for CommunityRoles
impl Debug for CommunityRoles
Source§impl Default for CommunityRoles
impl Default for CommunityRoles
Source§impl<'de> Deserialize<'de> for CommunityRoles
impl<'de> Deserialize<'de> for CommunityRoles
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for CommunityRoles
Source§impl PartialEq for CommunityRoles
impl PartialEq for CommunityRoles
Source§impl Serialize for CommunityRoles
impl Serialize for CommunityRoles
impl StructuralPartialEq for CommunityRoles
Auto Trait Implementations§
impl Forget for CommunityRoles
impl Freeze for CommunityRoles
impl Move for CommunityRoles
impl RefUnwindSafe for CommunityRoles
impl Send for CommunityRoles
impl Sync for CommunityRoles
impl Unpin for CommunityRoles
impl UnsafeUnpin for CommunityRoles
impl UnwindSafe for CommunityRoles
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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