mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-10-07 02:55:45 +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
|
let external = self
|
||||||
.fetch_config_resource(resource_id)
|
.fetch_config_resource(resource_id)
|
||||||
.await
|
.await
|
||||||
|
@ -345,7 +349,7 @@ impl ConfigManager {
|
||||||
.await?
|
.await?
|
||||||
.map_or(true, |v| v != external.version)
|
.map_or(true, |v| v != external.version)
|
||||||
{
|
{
|
||||||
self.set(external.keys, false).await?;
|
self.set(external.keys, overwrite).await?;
|
||||||
|
|
||||||
trc::event!(
|
trc::event!(
|
||||||
Config(trc::ConfigEvent::ImportExternal),
|
Config(trc::ConfigEvent::ImportExternal),
|
||||||
|
@ -387,6 +391,7 @@ impl ConfigManager {
|
||||||
external.keys.push(ConfigKey::from((key, value)));
|
external.keys.push(ConfigKey::from((key, value)));
|
||||||
} else if key.starts_with("spam-filter.")
|
} else if key.starts_with("spam-filter.")
|
||||||
|| key.starts_with("http-lookup.")
|
|| key.starts_with("http-lookup.")
|
||||||
|
|| (key.starts_with("lookup.") && !key.starts_with("lookup.default."))
|
||||||
|| key.starts_with("server.asn.")
|
|| key.starts_with("server.asn.")
|
||||||
|| key.starts_with("queue.quota.")
|
|| key.starts_with("queue.quota.")
|
||||||
|| key.starts_with("queue.throttle.")
|
|| key.starts_with("queue.throttle.")
|
||||||
|
|
|
@ -98,7 +98,10 @@ impl ManageReload for Server {
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
trc::EventType::Server(trc::ServerEvent::ThreadError)
|
trc::EventType::Server(trc::ServerEvent::ThreadError)
|
||||||
.reason(err)
|
.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!())
|
.caused_by(trc::location!())
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
@ -123,12 +126,14 @@ impl ManageReload for Server {
|
||||||
// Validate the access token
|
// Validate the access token
|
||||||
access_token.assert_has_permission(Permission::SpamFilterUpdate)?;
|
access_token.assert_has_permission(Permission::SpamFilterUpdate)?;
|
||||||
|
|
||||||
|
let overwrite = UrlParams::new(req.uri().query()).has_key("overwrite");
|
||||||
|
|
||||||
Ok(JsonResponse::new(json!({
|
Ok(JsonResponse::new(json!({
|
||||||
"data": self
|
"data": self
|
||||||
.core
|
.core
|
||||||
.storage
|
.storage
|
||||||
.config
|
.config
|
||||||
.update_config_resource("spam-filter")
|
.update_config_resource("spam-filter", overwrite)
|
||||||
.await?,
|
.await?,
|
||||||
}))
|
}))
|
||||||
.into_http_response())
|
.into_http_response())
|
||||||
|
|
Loading…
Add table
Reference in a new issue