Update notice format
This commit is contained in:
parent
e07970165f
commit
9643a6f7f2
|
@ -80,8 +80,6 @@ class EventTypes(object):
|
||||||
ServerACL = "m.room.server_acl"
|
ServerACL = "m.room.server_acl"
|
||||||
Pinned = "m.room.pinned_events"
|
Pinned = "m.room.pinned_events"
|
||||||
|
|
||||||
ServerNoticeLimitReached = "m.server_notice.usage_limit_reached"
|
|
||||||
|
|
||||||
|
|
||||||
class RejectedReason(object):
|
class RejectedReason(object):
|
||||||
AUTH_ERROR = "auth_error"
|
AUTH_ERROR = "auth_error"
|
||||||
|
@ -106,3 +104,7 @@ DEFAULT_ROOM_VERSION = "1"
|
||||||
# vdh-test-version is a placeholder to get room versioning support working and tested
|
# vdh-test-version is a placeholder to get room versioning support working and tested
|
||||||
# until we have a working v2.
|
# until we have a working v2.
|
||||||
KNOWN_ROOM_VERSIONS = {"1", "vdh-test-version"}
|
KNOWN_ROOM_VERSIONS = {"1", "vdh-test-version"}
|
||||||
|
|
||||||
|
|
||||||
|
ServerNoticeMsgType = "m.server_notice"
|
||||||
|
ServerNoticeLimitReached = "m.server_notice.usage_limit_reached"
|
||||||
|
|
|
@ -18,7 +18,11 @@ from six import iteritems
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes
|
from synapse.api.constants import (
|
||||||
|
EventTypes,
|
||||||
|
ServerNoticeLimitReached,
|
||||||
|
ServerNoticeMsgType,
|
||||||
|
)
|
||||||
from synapse.api.errors import AuthError, ResourceLimitError, SynapseError
|
from synapse.api.errors import AuthError, ResourceLimitError, SynapseError
|
||||||
from synapse.server_notices.server_notices_manager import SERVER_NOTICE_ROOM_TAG
|
from synapse.server_notices.server_notices_manager import SERVER_NOTICE_ROOM_TAG
|
||||||
|
|
||||||
|
@ -102,11 +106,13 @@ class ResourceLimitsServerNotices(object):
|
||||||
# Add block notification
|
# Add block notification
|
||||||
content = {
|
content = {
|
||||||
'body': event_content,
|
'body': event_content,
|
||||||
|
'msgtype': ServerNoticeMsgType,
|
||||||
|
'server_notice_type': ServerNoticeLimitReached,
|
||||||
'admin_uri': self._config.admin_uri,
|
'admin_uri': self._config.admin_uri,
|
||||||
'limit_type': event_limit_type
|
'limit_type': event_limit_type
|
||||||
}
|
}
|
||||||
event = yield self._server_notices_manager.send_notice(
|
event = yield self._server_notices_manager.send_notice(
|
||||||
user_id, content, EventTypes.ServerNoticeLimitReached
|
user_id, content, EventTypes.Message,
|
||||||
)
|
)
|
||||||
|
|
||||||
content = {
|
content = {
|
||||||
|
@ -174,7 +180,9 @@ class ResourceLimitsServerNotices(object):
|
||||||
|
|
||||||
events = yield self._store.get_events(referenced_events)
|
events = yield self._store.get_events(referenced_events)
|
||||||
for event_id, event in iteritems(events):
|
for event_id, event in iteritems(events):
|
||||||
if event.type == EventTypes.ServerNoticeLimitReached:
|
if event.type != EventTypes.Message:
|
||||||
|
continue
|
||||||
|
if event.content.get("msgtype") == ServerNoticeMsgType:
|
||||||
currently_blocked = True
|
currently_blocked = True
|
||||||
# remove event in case we need to disable blocking later on.
|
# remove event in case we need to disable blocking later on.
|
||||||
if event_id in referenced_events:
|
if event_id in referenced_events:
|
||||||
|
|
|
@ -2,7 +2,7 @@ from mock import Mock
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes
|
from synapse.api.constants import EventTypes, ServerNoticeMsgType
|
||||||
from synapse.api.errors import ResourceLimitError
|
from synapse.api.errors import ResourceLimitError
|
||||||
from synapse.handlers.auth import AuthHandler
|
from synapse.handlers.auth import AuthHandler
|
||||||
from synapse.server_notices.resource_limits_server_notices import (
|
from synapse.server_notices.resource_limits_server_notices import (
|
||||||
|
@ -78,7 +78,10 @@ class TestResourceLimitsServerNotices(unittest.TestCase):
|
||||||
"""Test when user has blocked notice, but should have it removed"""
|
"""Test when user has blocked notice, but should have it removed"""
|
||||||
|
|
||||||
self._rlsn._auth.check_auth_blocking = Mock()
|
self._rlsn._auth.check_auth_blocking = Mock()
|
||||||
mock_event = Mock(type=EventTypes.ServerNoticeLimitReached)
|
mock_event = Mock(
|
||||||
|
type=EventTypes.Message,
|
||||||
|
content={"msgtype": ServerNoticeMsgType},
|
||||||
|
)
|
||||||
self._rlsn._store.get_events = Mock(return_value=defer.succeed(
|
self._rlsn._store.get_events = Mock(return_value=defer.succeed(
|
||||||
{"123": mock_event}
|
{"123": mock_event}
|
||||||
))
|
))
|
||||||
|
@ -94,7 +97,10 @@ class TestResourceLimitsServerNotices(unittest.TestCase):
|
||||||
side_effect=ResourceLimitError(403, 'foo')
|
side_effect=ResourceLimitError(403, 'foo')
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_event = Mock(type=EventTypes.ServerNoticeLimitReached)
|
mock_event = Mock(
|
||||||
|
type=EventTypes.Message,
|
||||||
|
content={"msgtype": ServerNoticeMsgType},
|
||||||
|
)
|
||||||
self._rlsn._store.get_events = Mock(return_value=defer.succeed(
|
self._rlsn._store.get_events = Mock(return_value=defer.succeed(
|
||||||
{"123": mock_event}
|
{"123": mock_event}
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue