mirror of
https://github.com/chatmail/core.git
synced 2026-09-22 13:01:21 +03:00
feat: limit the number of published relays instead of all relays
This commit is contained in:
@@ -237,9 +237,20 @@ def test_transport_limit(acfactory) -> None:
|
||||
account.add_transport_from_qr(qr)
|
||||
|
||||
second_addr = account.list_transports()[1]["addr"]
|
||||
account.delete_transport(second_addr)
|
||||
third_addr = account.list_transports()[2]["addr"]
|
||||
|
||||
# test that adding a transport after deleting one works again
|
||||
# test that adding a transport after unpublishing one works again
|
||||
account.set_transport_unpublished(second_addr)
|
||||
account.add_transport_from_qr(qr)
|
||||
with pytest.raises(JsonRpcError):
|
||||
account.add_transport_from_qr(qr)
|
||||
|
||||
# UIs are not expected to delete transports directly,
|
||||
# but we still test that adding a transport
|
||||
# after deleting one instead of unpublishing works.
|
||||
account.delete_transport(third_addr)
|
||||
account.add_transport_from_qr(qr)
|
||||
with pytest.raises(JsonRpcError):
|
||||
account.add_transport_from_qr(qr)
|
||||
|
||||
|
||||
|
||||
@@ -45,9 +45,11 @@ use crate::transport::{
|
||||
use crate::{EventType, stock_str};
|
||||
use crate::{chat, provider};
|
||||
|
||||
/// Maximum number of relays
|
||||
/// see <https://github.com/chatmail/core/issues/7608>
|
||||
pub(crate) const MAX_TRANSPORT_RELAYS: usize = 5;
|
||||
/// Maximum number of published relays.
|
||||
///
|
||||
/// See <https://github.com/chatmail/core/issues/7608>
|
||||
/// and <https://github.com/chatmail/core/issues/8421>.
|
||||
pub(crate) const MAX_PUBLISHED_RELAYS: usize = 5;
|
||||
|
||||
/// Hard-coded candidates for default relays.
|
||||
/// In the future, we want to use it during onboarding;
|
||||
@@ -336,14 +338,11 @@ impl Context {
|
||||
.await?
|
||||
&& self
|
||||
.sql
|
||||
.count("SELECT COUNT(*) FROM transports", ())
|
||||
.count("SELECT COUNT(*) FROM transports WHERE is_published", ())
|
||||
.await?
|
||||
>= MAX_TRANSPORT_RELAYS
|
||||
>= MAX_PUBLISHED_RELAYS
|
||||
{
|
||||
bail!(
|
||||
"You have reached the maximum number of relays ({}).",
|
||||
MAX_TRANSPORT_RELAYS
|
||||
)
|
||||
bail!("You have reached the maximum number of relays ({MAX_PUBLISHED_RELAYS}).")
|
||||
}
|
||||
|
||||
let provider = match configure(self, param).await {
|
||||
|
||||
Reference in New Issue
Block a user