mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-10-05 10:14:39 +08:00
Overwrite option to spam-filter update endpoint
This commit is contained in:
parent
ad30478bd8
commit
2ef4a06135
2 changed files with 14 additions and 4 deletions
|
@ -329,7 +329,11 @@ impl ConfigManager {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn update_config_resource(&self, resource_id: &str) -> trc::Result<Option<String>> {
|
||||
pub async fn update_config_resource(
|
||||
&self,
|
||||
resource_id: &str,
|
||||
overwrite: bool,
|
||||
) -> trc::Result<Option<String>> {
|
||||
let external = self
|
||||
.fetch_config_resource(resource_id)
|
||||
.await
|
||||
|
@ -345,7 +349,7 @@ impl ConfigManager {
|
|||
.await?
|
||||
.map_or(true, |v| v != external.version)
|
||||
{
|
||||
self.set(external.keys, false).await?;
|
||||
self.set(external.keys, overwrite).await?;
|
||||
|
||||
trc::event!(
|
||||
Config(trc::ConfigEvent::ImportExternal),
|
||||
|
@ -387,6 +391,7 @@ impl ConfigManager {
|
|||
external.keys.push(ConfigKey::from((key, value)));
|
||||
} else if key.starts_with("spam-filter.")
|
||||
|| key.starts_with("http-lookup.")
|
||||
|| (key.starts_with("lookup.") && !key.starts_with("lookup.default."))
|
||||
|| key.starts_with("server.asn.")
|
||||
|| key.starts_with("queue.quota.")
|
||||
|| key.starts_with("queue.throttle.")
|
||||
|
|
|
@ -98,7 +98,10 @@ impl ManageReload for Server {
|
|||
.map_err(|err| {
|
||||
trc::EventType::Server(trc::ServerEvent::ThreadError)
|
||||
.reason(err)
|
||||
.details("Failed to send settings reload event to housekeeper")
|
||||
.details(concat!(
|
||||
"Failed to send settings reload ",
|
||||
"event to housekeeper"
|
||||
))
|
||||
.caused_by(trc::location!())
|
||||
})?;
|
||||
}
|
||||
|
@ -123,12 +126,14 @@ impl ManageReload for Server {
|
|||
// Validate the access token
|
||||
access_token.assert_has_permission(Permission::SpamFilterUpdate)?;
|
||||
|
||||
let overwrite = UrlParams::new(req.uri().query()).has_key("overwrite");
|
||||
|
||||
Ok(JsonResponse::new(json!({
|
||||
"data": self
|
||||
.core
|
||||
.storage
|
||||
.config
|
||||
.update_config_resource("spam-filter")
|
||||
.update_config_resource("spam-filter", overwrite)
|
||||
.await?,
|
||||
}))
|
||||
.into_http_response())
|
||||
|
|
Loading…
Add table
Reference in a new issue