struct Visibility {
source: ChannelOverwrites,
target: ChannelOverwrites,
read_source: Permissions,
read_target: Permissions,
everyone_role_id: Id<RoleMarker>,
role_perms: HashMap<Id<RoleMarker>, Permissions>,
reachable: HashSet<RoleGrant>,
}Expand description
Decides whether everyone who can read the source channel could also read the target channel.
Members are split by whether either channel carries an overwrite for them personally:
- Without one, a member’s access depends only on which roles they hold.
Self::roles_preserve_visibilitychecks every combination of roles a member could hold — not just each role on its own, since Discord merges a member’s role overwrites before applying them. - With one, the member is looked up and judged on their actual roles by
Self::member_preserves_visibility.Self::members_to_verifylists only those whose personal overwrite could make a difference.
Fields§
§source: ChannelOverwrites§target: ChannelOverwrites§read_source: PermissionsWhat a member needs in the source, from read_source_requirement.
read_target: PermissionsWhat a member needs in the target, from read_target_requirement.
everyone_role_id: Id<RoleMarker>§role_perms: HashMap<Id<RoleMarker>, Permissions>§reachable: HashSet<RoleGrant>Every grant a member without personal overwrites can hold.
Implementations§
Source§impl Visibility
impl Visibility
fn new( source_overwrites: &[PermissionOverwrite], target_overwrites: &[PermissionOverwrite], read_source: Permissions, read_target: Permissions, role_perms: HashMap<Id<RoleMarker>, Permissions>, everyone_role_id: Id<RoleMarker>, ) -> Self
Sourcefn everyone_grant(&self) -> RoleGrant
fn everyone_grant(&self) -> RoleGrant
The grant of @everyone, which every member holds. Its overwrite is
applied separately, so it contributes base permissions only.
fn role_grant(&self, role_id: Id<RoleMarker>) -> RoleGrant
Sourcefn base_of(&self, role_id: Id<RoleMarker>) -> Permissions
fn base_of(&self, role_id: Id<RoleMarker>) -> Permissions
Masked to the base permissions that can change the outcome of
channel_permissions, so that equivalent roles collapse into one
RoleGrant and Self::reachable_grants stays small.
Sourcefn reachable_grants(&self) -> HashSet<RoleGrant>
fn reachable_grants(&self) -> HashSet<RoleGrant>
Closes @everyone’s grant under union with every other role’s grant.
Why not enumerate role subsets: that is exponential in the number of roles, while the masked grants have only a few bits, so the closure stays small no matter how many roles the guild has.
Roles named only by an overwrite are included too: a role created after the role cache was filled still restricts whoever holds it.
fn source_permissions( &self, grant: RoleGrant, member: (Permissions, Permissions), ) -> Permissions
fn target_permissions( &self, grant: RoleGrant, member: (Permissions, Permissions), ) -> Permissions
Sourcefn leaks(
&self,
grant: RoleGrant,
source_member: (Permissions, Permissions),
target_member: (Permissions, Permissions),
) -> bool
fn leaks( &self, grant: RoleGrant, source_member: (Permissions, Permissions), target_member: (Permissions, Permissions), ) -> bool
Whether a member with grant and the given personal overwrites can read
the source but not the target.
Sourcefn roles_preserve_visibility(&self) -> bool
fn roles_preserve_visibility(&self) -> bool
Whether no combination of roles lets a member read the source but not the target, for members without personal overwrites.
Sourcefn members_to_verify(&self) -> Vec<Id<UserMarker>>
fn members_to_verify(&self) -> Vec<Id<UserMarker>>
Members whose personal overwrites could let them read the source but not the target, sorted by id.
A member is listed only when some role combination, together with their personal overwrites, leaks; for anyone else the outcome is the same whatever roles they actually hold, so looking them up is wasted.
Sourcefn member_preserves_visibility(
&self,
user: Id<UserMarker>,
roles: &[Id<RoleMarker>],
) -> bool
fn member_preserves_visibility( &self, user: Id<UserMarker>, roles: &[Id<RoleMarker>], ) -> bool
Whether user, holding roles, cannot read the source without also being
able to read the target.