Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
01021c81
Commit
01021c81
authored
6 years ago
by
Neil Johnson
Browse files
Options
Downloads
Patches
Plain Diff
wip at implementing MSC 7075
parent
885ea9c6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/server_notices/resource_limits_server_notices.py
+84
-0
84 additions, 0 deletions
synapse/server_notices/resource_limits_server_notices.py
with
84 additions
and
0 deletions
synapse/server_notices/resource_limits_server_notices.py
0 → 100644
+
84
−
0
View file @
01021c81
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
logging
from
six
import
iteritems
,
string_types
from
twisted.internet
import
defer
from
synapse.api.errors
import
SynapseError
from
synapse.api.urls
import
ConsentURIBuilder
from
synapse.config
import
ConfigError
from
synapse.types
import
get_localpart_from_id
logger
=
logging
.
getLogger
(
__name__
)
class
ResourceLimitsServerNotices
(
object
):
"""
"""
def
__init__
(
self
,
hs
):
"""
Args:
hs (synapse.server.HomeServer):
"""
self
.
_server_notices_manager
=
hs
.
get_server_notices_manager
()
self
.
_store
=
hs
.
get_datastore
()
self
.
_api
=
hs
.
get_api
()
self
.
_server_notice_content
=
hs
.
config
.
user_consent_server_notice_content
self
.
_limit_usage_by_mau
=
config
.
limit_usage_by_mau
=
False
self
.
_hs_disabled
.
config
.
hs_disabled
=
False
self
.
_notified
=
set
()
self
.
_resouce_limited
=
False
# Config checks?
@defer.inlineCallbacks
def
maybe_send_server_notice_to_user
(
self
,
user_id
):
"""
Check if we need to send a notice to this user, and does so if so
Args:
user_id (str): user to check
Returns:
Deferred
"""
if
self
.
_limit_usage_by_mau
is
False
and
self
.
_hs_disabled
is
False
:
# not enabled
return
timestamp
=
yield
self
.
store
.
user_last_seen_monthly_active
(
user_id
)
if
timestamp
is
None
:
# This user will be blocked from receiving the notice anyway
return
try
:
yield
self
.
api
.
check_auth_blocking
()
if
self
.
_resouce_limited
:
# Need to start removing notices
pass
except
AuthError
as
e
:
# Need to start notifying of blocking
if
not
self
.
_resouce_limited
:
pass
# need to send a message.
try
:
yield
self
.
_server_notices_manager
.
send_notice
(
user_id
,
content
,
)
except
SynapseError
as
e
:
logger
.
error
(
"
Error sending server notice about resource limits: %s
"
,
e
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment