fix: made it so remove acl command will say if a non-existing entry is attempted to be removed

This commit is contained in:
NinekoTheCat 2023-12-25 00:59:17 +01:00
parent d325537308
commit 580b6af894
No known key found for this signature in database
GPG key ID: 700DB3F678A4AB66
4 changed files with 20 additions and 12 deletions

View file

@ -39,8 +39,12 @@ impl Data for KeyValueDatabase {
)
}
fn remove_acl(&self, host: Host<String>) -> crate::Result<()> {
self.acl_list.remove(host.to_string().as_bytes())
fn remove_acl(&self, host: Host<String>) -> crate::Result<Option<()>> {
if self.acl_list.get(host.to_string().as_bytes())?.is_none() {
return Ok(None);
}
self.acl_list.remove(host.to_string().as_bytes())?;
Ok(Some(()))
}
fn get_all_acls(&self) -> HashSet<AclDatabaseEntry> {

View file

@ -10,7 +10,7 @@ pub trait Data: Send + Sync {
/// add a given Acl entry to the database
fn add_acl(&self, acl: AclDatabaseEntry) -> crate::Result<()>;
/// remove a given Acl entry from the database
fn remove_acl(&self, host: Host<String>) -> crate::Result<()>;
fn remove_acl(&self, host: Host<String>) -> crate::Result<Option<()>>;
/// list all acls
fn get_all_acls(&self) -> HashSet<AclDatabaseEntry>;

View file

@ -38,7 +38,7 @@ impl Service {
None => set.into_iter().collect(),
}
}
pub fn remove_acl(&self, host: Host) -> crate::Result<()> {
pub fn remove_acl(&self, host: Host) -> crate::Result<Option<()>> {
self.db.remove_acl(host)
}

View file

@ -1300,14 +1300,18 @@ impl Service {
}
};
if let Err(error) = services().acl.remove_acl(host.clone()) {
match services().acl.remove_acl(host.clone()) {
Err(error) => {
error!(
"encountered {} while trying to remove acl with host {}",
error, host
);
RoomMessageEventContent::text_plain("error, couldn't remove acl")
} else {
RoomMessageEventContent::text_plain("successfully removed ACL")
}
Ok(Some(_)) => RoomMessageEventContent::text_plain("successfully removed ACL"),
Ok(None) => RoomMessageEventContent::text_plain(
"couldn't remove acl as it doesn't exist",
),
}
}
AdminCommand::Acl(AclCommand::List { filter }) => {