diff --git a/src/database/key_value/acl.rs b/src/database/key_value/acl.rs index a5eadc61..019155b4 100644 --- a/src/database/key_value/acl.rs +++ b/src/database/key_value/acl.rs @@ -39,8 +39,12 @@ impl Data for KeyValueDatabase { ) } - fn remove_acl(&self, host: Host) -> crate::Result<()> { - self.acl_list.remove(host.to_string().as_bytes()) + fn remove_acl(&self, host: Host) -> crate::Result> { + 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 { diff --git a/src/service/acl/data.rs b/src/service/acl/data.rs index 0f81b23a..c9239ccf 100644 --- a/src/service/acl/data.rs +++ b/src/service/acl/data.rs @@ -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) -> crate::Result<()>; + fn remove_acl(&self, host: Host) -> crate::Result>; /// list all acls fn get_all_acls(&self) -> HashSet; diff --git a/src/service/acl/mod.rs b/src/service/acl/mod.rs index ba173df6..e86cb476 100644 --- a/src/service/acl/mod.rs +++ b/src/service/acl/mod.rs @@ -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> { self.db.remove_acl(host) } diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 684ac7dd..a127f336 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -1300,14 +1300,18 @@ impl Service { } }; - if let Err(error) = services().acl.remove_acl(host.clone()) { - 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") + 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") + } + 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 }) => {