feat: initial category permissions and rework of category crud routes

This commit is contained in:
Zomatree
2025-05-06 17:48:38 +01:00
parent f75d635c81
commit c7f09ab9d0
19 changed files with 550 additions and 58 deletions

View File

@@ -68,6 +68,26 @@ pub async fn calculate_server_permissions<P: PermissionQuery>(query: &mut P) ->
permissions
}
pub async fn calculate_category_permissions<P: PermissionQuery>(query: &mut P) -> PermissionValue {
let mut permissions = calculate_server_permissions(query).await;
permissions.apply(query.get_default_category_permissions().await);
for role_override in query.get_our_category_role_overrides().await {
permissions.apply(role_override)
}
if !permissions.has_channel_permission(ChannelPermission::ViewChannel) {
permissions.revoke_all();
}
if query.are_we_timed_out().await {
permissions.restrict(*ALLOW_IN_TIMEOUT);
}
permissions
}
/// Calculate permissions against a channel
pub async fn calculate_channel_permissions<P: PermissionQuery>(query: &mut P) -> PermissionValue {
if query.are_we_privileged().await {
@@ -109,11 +129,19 @@ pub async fn calculate_channel_permissions<P: PermissionQuery>(query: &mut P) ->
}
ChannelType::ServerChannel => {
query.set_server_from_channel().await;
query.set_category_from_channel().await;
if query.are_we_server_owner().await {
ChannelPermission::GrantAllSafe.into()
} else if query.are_we_a_member().await {
let mut permissions = calculate_server_permissions(query).await;
permissions.apply(query.get_default_category_permissions().await);
for role_override in query.get_our_category_role_overrides().await {
permissions.apply(role_override)
}
permissions.apply(query.get_default_channel_permissions().await);
for role_override in query.get_our_channel_role_overrides().await {
@@ -135,4 +163,4 @@ pub async fn calculate_channel_permissions<P: PermissionQuery>(query: &mut P) ->
}
ChannelType::Unknown => 0_u64.into(),
}
}
}

View File

@@ -51,6 +51,12 @@ pub trait PermissionQuery {
/// Get the ordered role overrides (from lowest to highest) for this member in this channel
async fn get_our_channel_role_overrides(&mut self) -> Vec<Override>;
/// Get the default category permissions
async fn get_default_category_permissions(&mut self) -> Override;
/// Get the ordered role overrides (from lowest to highest) for this member in this category
async fn get_our_category_role_overrides(&mut self) -> Vec<Override>;
/// Do we own this group or saved messages channel if it is one of those?
async fn do_we_own_the_channel(&mut self) -> bool;
@@ -64,4 +70,7 @@ pub trait PermissionQuery {
/// Set the current server as the server owning this channel
/// (this will only ever be called for server channels, use unimplemented!() for other code paths)
async fn set_server_from_channel(&mut self);
//// SEts the current category as the category the channel is in
async fn set_category_from_channel(&mut self);
}