Skip to content

Commit

Permalink
Remove deprecated permissions methods (#3042)
Browse files Browse the repository at this point in the history
This follows up on #3037, and also removes the now unnecessary Option
around the GuildChannel param.
  • Loading branch information
GnomedDev authored Nov 16, 2024
1 parent efb5820 commit 6c67796
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 122 deletions.
18 changes: 0 additions & 18 deletions src/model/guild/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,6 @@ impl Member {
self.guild_id.disconnect_member(http, self.user.id).await
}

/// Returns the guild-level permissions for the member.
///
/// # Errors
///
/// Returns a [`ModelError::GuildNotFound`] if the guild the member's in could not be
/// found in the cache.
///
/// And/or returns [`ModelError::ItemMissing`] if the "default channel" of the guild is not
/// found.
#[cfg(feature = "cache")]
#[deprecated = "Use Guild::member_permissions_in, as this doesn't consider permission overwrites"]
pub fn permissions(&self, cache: &Cache) -> Result<Permissions> {
let guild = cache.guild(self.guild_id).ok_or(ModelError::GuildNotFound)?;

#[expect(deprecated)]
Ok(guild.member_permissions(self))
}

/// Removes a [`Role`] from the member.
///
/// **Note**: Requires the [Manage Roles] permission.
Expand Down
82 changes: 20 additions & 62 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,51 +802,11 @@ impl Guild {
members
}

/// Calculate a [`Member`]'s permissions in the guild.
#[must_use]
#[deprecated = "Use Guild::member_permissions_in, as this doesn't consider permission overwrites"]
pub fn member_permissions(&self, member: &Member) -> Permissions {
Self::user_permissions_in_(
None,
member.user.id,
&member.roles,
self.id,
&self.roles,
self.owner_id,
)
}

/// Calculate a [`PartialMember`]'s permissions in the guild.
///
/// # Panics
///
/// Panics if the passed [`UserId`] does not match the [`PartialMember`] id, if user is Some.
#[must_use]
#[deprecated = "Use Guild::partial_member_permissions_in, as this doesn't consider permission overwrites"]
pub fn partial_member_permissions(
&self,
member_id: UserId,
member: &PartialMember,
) -> Permissions {
if let Some(user) = &member.user {
assert_eq!(user.id, member_id, "User::id does not match provided PartialMember");
}

Self::user_permissions_in_(
None,
member_id,
&member.roles,
self.id,
&self.roles,
self.owner_id,
)
}

/// Calculate a [`Member`]'s permissions in a given channel in the guild.
#[must_use]
pub fn user_permissions_in(&self, channel: &GuildChannel, member: &Member) -> Permissions {
Self::user_permissions_in_(
Some(channel),
channel,
member.user.id,
&member.roles,
self.id,
Expand All @@ -872,7 +832,7 @@ impl Guild {
}

Self::user_permissions_in_(
Some(channel),
channel,
member_id,
&member.roles,
self.id,
Expand All @@ -883,7 +843,7 @@ impl Guild {

/// Helper function that can also be used from [`PartialGuild`].
pub(crate) fn user_permissions_in_(
channel: Option<&GuildChannel>,
channel: &GuildChannel,
member_user_id: UserId,
member_roles: &[RoleId],
guild_id: GuildId,
Expand All @@ -897,25 +857,23 @@ impl Guild {
let mut member_allow_overwrites = Permissions::empty();
let mut member_deny_overwrites = Permissions::empty();

if let Some(channel) = channel {
for overwrite in &channel.permission_overwrites {
match overwrite.kind {
PermissionOverwriteType::Member(user_id) => {
if member_user_id == user_id {
member_allow_overwrites = overwrite.allow;
member_deny_overwrites = overwrite.deny;
}
},
PermissionOverwriteType::Role(role_id) => {
if role_id.get() == guild_id.get() {
everyone_allow_overwrites = overwrite.allow;
everyone_deny_overwrites = overwrite.deny;
} else if member_roles.contains(&role_id) {
roles_allow_overwrites.push(overwrite.allow);
roles_deny_overwrites.push(overwrite.deny);
}
},
}
for overwrite in &channel.permission_overwrites {
match overwrite.kind {
PermissionOverwriteType::Member(user_id) => {
if member_user_id == user_id {
member_allow_overwrites = overwrite.allow;
member_deny_overwrites = overwrite.deny;
}
},
PermissionOverwriteType::Role(role_id) => {
if role_id.get() == guild_id.get() {
everyone_allow_overwrites = overwrite.allow;
everyone_deny_overwrites = overwrite.deny;
} else if member_roles.contains(&role_id) {
roles_allow_overwrites.push(overwrite.allow);
roles_deny_overwrites.push(overwrite.deny);
}
},
}
}

Expand Down
44 changes: 2 additions & 42 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,46 +183,6 @@ impl PartialGuild {
guild_id.to_partial_guild(cache_http).await
}

/// Calculate a [`Member`]'s permissions in the guild.
#[must_use]
#[deprecated = "Use PartialGuild::member_permissions_in, as this doesn't consider permission overwrites"]
pub fn member_permissions(&self, member: &Member) -> Permissions {
Guild::user_permissions_in_(
None,
member.user.id,
&member.roles,
self.id,
&self.roles,
self.owner_id,
)
}

/// Calculate a [`PartialMember`]'s permissions in the guild.
///
/// # Panics
///
/// Panics if the passed [`UserId`] does not match the [`PartialMember`] id, if user is Some.
#[must_use]
#[deprecated = "Use PartialGuild::partial_member_permissions_in, as this doesn't consider permission overwrites"]
pub fn partial_member_permissions(
&self,
member_id: UserId,
member: &PartialMember,
) -> Permissions {
if let Some(user) = &member.user {
assert_eq!(user.id, member_id, "User::id does not match provided PartialMember");
}

Guild::user_permissions_in_(
None,
member_id,
&member.roles,
self.id,
&self.roles,
self.owner_id,
)
}

/// Gets the highest role a [`Member`] of this Guild has.
///
/// Returns None if the member has no roles or the member from this guild.
Expand Down Expand Up @@ -266,7 +226,7 @@ impl PartialGuild {
}

Guild::user_permissions_in_(
Some(channel),
channel,
member_id,
&member.roles,
self.id,
Expand All @@ -291,7 +251,7 @@ impl PartialGuild {
#[must_use]
pub fn user_permissions_in(&self, channel: &GuildChannel, member: &Member) -> Permissions {
Guild::user_permissions_in_(
Some(channel),
channel,
member.user.id,
&member.roles,
self.id,
Expand Down

0 comments on commit 6c67796

Please sign in to comment.