Skip to main content

CommunityRoles

Struct CommunityRoles 

Source
pub struct CommunityRoles {
    pub roles: Vec<Role>,
    pub grants: Vec<MemberGrant>,
}
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>

Implementations§

Source§

impl CommunityRoles

Source

pub fn role(&self, role_id: &str) -> Option<&Role>

Look up a role definition by id.

Source

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).

Source

pub fn effective_permissions(&self, member_hex: &str) -> Permissions

Effective permissions for a member = union of their granted roles’ bits.

Source

pub fn has_permission(&self, member_hex: &str, bits: u64) -> bool

True iff the member’s effective permissions include every bit in bits.

Source

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.

Source

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).

Source

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.

Source

pub fn is_authorized( &self, actor_hex: &str, owner_hex: Option<&str>, permission: u64, ) -> bool

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.

Source

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.

Source

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).

Source

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, …).

Source

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.)

Source

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.

Source

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.

Source

pub fn channel_role_ids(&self, channel_hex: &str) -> Vec<String>

[channel_roles], by id.

Source

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.

Source

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.

Source

pub fn is_authorized_in( &self, actor_hex: &str, owner_hex: Option<&str>, channel_hex: &str, permission: u64, ) -> bool

is_authorized, judged against one channel per effective_permissions_in. Offer-side only.

Trait Implementations§

Source§

impl Clone for CommunityRoles

Source§

fn clone(&self) -> CommunityRoles

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
Source§

impl Debug for CommunityRoles

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CommunityRoles

Source§

fn default() -> CommunityRoles

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CommunityRoles

Source§

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

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

impl Eq for CommunityRoles

Source§

impl PartialEq for CommunityRoles

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for CommunityRoles

Source§

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

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

impl StructuralPartialEq for CommunityRoles

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
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
Source§

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

Source§

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

Source§

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

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

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

Source§

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

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

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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