Rename soft_limit to can_upgrade

This commit is contained in:
Hugh Nimmo-Smith committed 2026-01-16 15:43:16 +00:00
1 parent d875af2a0a
commit a6e8610eca
6 files changed
+25 -25

No files matched your search

@@ -2182,7 +2182,7 @@ Options for each entry include:
* `msc4335_info_uri` (string): Experimental MSC4335 URI to where the user can find information about the upload limit. Optional.
* `msc4335_soft_limit` (boolean): Experimental MSC4335 value to say if the limit can be increased. Optional.
* `msc4335_can_upgrade` (boolean): Experimental MSC4335 value to say if the limit can be increased. Optional.
Example configuration:
```yaml
@@ -2192,7 +2192,7 @@ media_upload_limits:
- time_period: 1w
max_size: 500M
msc4335_info_uri: https://example.com/quota
msc4335_soft_limit: true
msc4335_can_upgrade: true
```
---
### `max_image_pixels`
+2 -2
View File
@@ -2442,7 +2442,7 @@ properties:
type: string
description: >-
Experimental MSC4335 URI to where the user can find information about the upload limit. Optional.
msc4335_soft_limit:
msc4335_can_upgrade:
type: boolean
description: >-
Experimental MSC4335 value to say if the limit can be increased. Optional.
@@ -2452,7 +2452,7 @@ properties:
- time_period: 1w
max_size: 500M
msc4335_info_uri: https://example.com/quota
msc4335_soft_limit: true
msc4335_can_upgrade: true
max_image_pixels:
$ref: "#/$defs/bytes"
description: Maximum number of pixels that will be thumbnailed.
+3 -3
View File
@@ -525,14 +525,14 @@ class MSC4335UserLimitExceededError(SynapseError):
code: int,
msg: str,
info_uri: str,
soft_limit: bool = False,
can_upgrade: bool = False,
):
additional_fields: dict[str, Union[str, bool]] = {
"org.matrix.msc4335.info_uri": info_uri,
}
if soft_limit:
additional_fields["org.matrix.msc4335.soft_limit"] = soft_limit
if can_upgrade:
additional_fields["org.matrix.msc4335.can_upgrade"] = can_upgrade
super().__init__(
code,
+7 -7
View File
@@ -137,7 +137,7 @@ class MediaUploadLimit:
msc4335_info_uri: Optional[str] = None
"""Used for experimental MSC4335 error code feature"""
msc4335_soft_limit: Optional[bool] = None
msc4335_can_upgrade: Optional[bool] = None
"""Used for experimental MSC4335 error code feature"""
@@ -309,14 +309,14 @@ class ContentRepositoryConfig(Config):
time_period_ms = self.parse_duration(limit_config["time_period"])
max_bytes = self.parse_size(limit_config["max_size"])
msc4335_info_uri = limit_config.get("msc4335_info_uri", None)
msc4335_soft_limit = limit_config.get("msc4335_soft_limit", None)
msc4335_can_upgrade = limit_config.get("msc4335_can_upgrade", None)
if (msc4335_info_uri is not None or msc4335_soft_limit is not None) and (
not (msc4335_info_uri and msc4335_soft_limit is not None)
if (msc4335_info_uri is not None or msc4335_can_upgrade is not None) and (
not (msc4335_info_uri and msc4335_can_upgrade is not None)
):
raise ConfigError(
"If any of msc4335_info_uri or msc4335_soft_limit are set, then both msc4335_info_uri and "
"msc4335_soft_limit must be set."
"If any of msc4335_info_uri or msc4335_can_upgrade are set, then both msc4335_info_uri and "
"msc4335_can_upgrade must be set."
)
self.media_upload_limits.append(
@@ -324,7 +324,7 @@ class ContentRepositoryConfig(Config):
max_bytes,
time_period_ms,
msc4335_info_uri,
msc4335_soft_limit,
msc4335_can_upgrade,
)
)
+2 -2
View File
@@ -390,13 +390,13 @@ class MediaRepository:
if (
msc4335_enabled
and limit.msc4335_info_uri
and limit.msc4335_soft_limit is not None
and limit.msc4335_can_upgrade is not None
):
raise MSC4335UserLimitExceededError(
403,
"Media upload limit exceeded",
limit.msc4335_info_uri,
limit.msc4335_soft_limit,
limit.msc4335_can_upgrade,
)
# Otherwise we use the current behaviour albeit not spec compliant
# See: https://github.com/element-hq/synapse/issues/18749
+9 -9
View File
@@ -2974,7 +2974,7 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
def test_msc4335_requires_config(self) -> None:
config_dict = default_config("test")
# msc4335_info_uri and msc4335_soft_limit are required
# msc4335_info_uri and msc4335_can_upgrade are required
with self.assertRaises(ConfigError):
HomeServerConfig().parse_config_dict(
@@ -2999,7 +2999,7 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
{
"time_period": "1d",
"max_size": "1K",
"msc4335_soft_limit": False,
"msc4335_can_upgrade": False,
}
],
**config_dict,
@@ -3015,7 +3015,7 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
{
"time_period": "1d",
"max_size": "1K",
"msc4335_soft_limit": True,
"msc4335_can_upgrade": True,
}
],
**config_dict,
@@ -3032,13 +3032,13 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
"time_period": "1d",
"max_size": "1K",
"msc4335_info_uri": "https://example.com",
"msc4335_soft_limit": False,
"msc4335_can_upgrade": False,
}
],
}
)
def test_msc4335_returns_hard_user_limit_exceeded(self) -> None:
"""Test that the MSC4335 error is returned with soft_limit False when experimental feature is enabled."""
"""Test that the MSC4335 error is returned with can_upgrade False when experimental feature is enabled."""
channel = self.upload_media(500)
self.assertEqual(channel.code, 200)
@@ -3059,13 +3059,13 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
"time_period": "1d",
"max_size": "1K",
"msc4335_info_uri": "https://example.com",
"msc4335_soft_limit": True,
"msc4335_can_upgrade": True,
}
],
}
)
def test_msc4335_returns_soft_user_limit_exceeded(self) -> None:
"""Test that the MSC4335 error is returned with soft_limit True when experimental feature is enabled."""
"""Test that the MSC4335 error is returned with can_upgrade True when experimental feature is enabled."""
channel = self.upload_media(500)
self.assertEqual(channel.code, 200)
@@ -3077,7 +3077,7 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
self.assertEqual(
channel.json_body["org.matrix.msc4335.info_uri"], "https://example.com"
)
self.assertEqual(channel.json_body["org.matrix.msc4335.soft_limit"], True)
self.assertEqual(channel.json_body["org.matrix.msc4335.can_upgrade"], True)
@override_config(
{
@@ -3294,7 +3294,7 @@ class MediaUploadLimitsModuleOverrides(unittest.HomeserverTestCase):
"time_period": "1d",
"max_size": "1K",
"msc4335_info_uri": "https://example.com",
"msc4335_soft_limit": False,
"msc4335_can_upgrade": False,
},
]
}