Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge commit 'a973bcb8a' into anoa/dinsic_release_1_18_x
Browse files Browse the repository at this point in the history
* commit 'a973bcb8a':
  Add some tiny type annotations (#7870)
  Remove obsolete comment.
  Ensure that calls to `json.dumps` are compatible with the standard library json. (#7836)
  Avoid brand new rooms in `delete_old_current_state_events` (#7854)
  Allow accounts to be re-activated from the admin APIs. (#7847)
  Fix tests
  Fix typo
  Newsfile
  Use get_users_in_room rather than state handler in typing for speed
  Fix client reader sharding tests (#7853)
  Convert E2E key and room key handlers to async/await. (#7851)
  Return the proper 403 Forbidden error during errors with JWT logins. (#7844)
  remove `retry_on_integrity_error` wrapper for persist_events (#7848)
  • Loading branch information
anoadragon453 committed Aug 4, 2020
2 parents dd65904 + a973bcb commit d9e25be
Show file tree
Hide file tree
Showing 39 changed files with 1,029 additions and 691 deletions.
1 change: 1 addition & 0 deletions changelog.d/7836.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that calls to `json.dumps` are compatible with the standard library json.
1 change: 1 addition & 0 deletions changelog.d/7844.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Errors which occur while using the non-standard JWT login now return the proper error: `403 Forbidden` with an error code of `M_FORBIDDEN`.
1 change: 1 addition & 0 deletions changelog.d/7847.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the ability to re-activate an account from the admin API.
1 change: 1 addition & 0 deletions changelog.d/7848.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant `retry_on_integrity_error` wrapper for event persistence code.
1 change: 1 addition & 0 deletions changelog.d/7851.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert E2E keys and room keys handlers to async/await.
1 change: 1 addition & 0 deletions changelog.d/7853.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for handling registration requests across multiple client reader workers.
1 change: 1 addition & 0 deletions changelog.d/7854.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.10.0 which could cause a "no create event in auth events" error during room creation.
1 change: 1 addition & 0 deletions changelog.d/7856.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Small performance improvement in typing processing.
1 change: 1 addition & 0 deletions changelog.d/7870.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add some type annotations to `HomeServer` and `BaseHandler`.
6 changes: 5 additions & 1 deletion docs/admin_api/user_admin_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ Body parameters:

- ``admin``, optional, defaults to ``false``.

- ``deactivated``, optional, defaults to ``false``.
- ``deactivated``, optional. If unspecified, deactivation state will be left
unchanged on existing accounts and set to ``false`` for new accounts.

If the user already exists then optional parameters default to the current value.

In order to re-activate an account ``deactivated`` must be set to ``false``. If
users do not login via single-sign-on, a new ``password`` must be provided.

List Accounts
=============

Expand Down
5 changes: 1 addition & 4 deletions docs/jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ The `token` field should include the JSON web token with the following claims:
Providing the audience claim when not configured will cause validation to fail.

In the case that the token is not valid, the homeserver must respond with
`401 Unauthorized` and an error code of `M_UNAUTHORIZED`.

(Note that this differs from the token based logins which return a
`403 Forbidden` and an error code of `M_FORBIDDEN` if an error occurs.)
`403 Forbidden` and an error code of `M_FORBIDDEN`.

As with other login types, there are additional fields (e.g. `device_id` and
`initial_device_display_name`) which can be included in the above request.
Expand Down
4 changes: 3 additions & 1 deletion synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
# limitations under the License.

"""Contains exceptions and error codes."""
import json

import logging
import typing
from http import HTTPStatus
from typing import Dict, List, Optional, Union

from canonicaljson import json

from twisted.web import http

if typing.TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# 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 json
import logging
from typing import Any, Callable, Dict, List, Match, Optional, Tuple, Union

from canonicaljson import json
from prometheus_client import Counter, Histogram

from twisted.internet import defer
Expand Down
2 changes: 0 additions & 2 deletions synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ async def send_new_transaction(
# all the edus in that transaction. This needs to be done since there is
# no active span here, so if the edus were not received by the remote the
# span would have no causality and it would be forgotten.
# The span_contexts is a generator so that it won't be evaluated if
# opentracing is disabled. (Yay speed!)

span_contexts = []
keep_destination = whitelisted_homeserver(destination)
Expand Down
10 changes: 4 additions & 6 deletions synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from twisted.internet import defer

import synapse.state
import synapse.storage
import synapse.types
from synapse.api.constants import EventTypes, Membership
from synapse.api.ratelimiting import Ratelimiter
Expand All @@ -28,21 +30,17 @@
class BaseHandler(object):
"""
Common base class for the event handlers.
Attributes:
store (synapse.storage.DataStore):
state_handler (synapse.state.StateHandler):
"""

def __init__(self, hs):
"""
Args:
hs (synapse.server.HomeServer):
"""
self.store = hs.get_datastore()
self.store = hs.get_datastore() # type: synapse.storage.DataStore
self.auth = hs.get_auth()
self.notifier = hs.get_notifier()
self.state_handler = hs.get_state_handler()
self.state_handler = hs.get_state_handler() # type: synapse.state.StateHandler
self.distributor = hs.get_distributor()
self.clock = hs.get_clock()
self.hs = hs
Expand Down
48 changes: 28 additions & 20 deletions synapse/handlers/deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from typing import Optional

from synapse.api.errors import SynapseError
from synapse.metrics.background_process_metrics import run_as_background_process
Expand Down Expand Up @@ -46,19 +47,20 @@ def __init__(self, hs):

self._account_validity_enabled = hs.config.account_validity.enabled

async def deactivate_account(self, user_id, erase_data, id_server=None):
async def deactivate_account(
self, user_id: str, erase_data: bool, id_server: Optional[str] = None
) -> bool:
"""Deactivate a user's account
Args:
user_id (str): ID of user to be deactivated
erase_data (bool): whether to GDPR-erase the user's data
id_server (str|None): Use the given identity server when unbinding
user_id: ID of user to be deactivated
erase_data: whether to GDPR-erase the user's data
id_server: Use the given identity server when unbinding
any threepids. If None then will attempt to unbind using the
identity server specified when binding (if known).
Returns:
Deferred[bool]: True if identity server supports removing
threepids, otherwise False.
True if identity server supports removing threepids, otherwise False.
"""
# FIXME: Theoretically there is a race here wherein user resets
# password using threepid.
Expand Down Expand Up @@ -138,11 +140,11 @@ async def deactivate_account(self, user_id, erase_data, id_server=None):

return identity_server_supports_unbinding

async def _reject_pending_invites_for_user(self, user_id):
async def _reject_pending_invites_for_user(self, user_id: str):
"""Reject pending invites addressed to a given user ID.
Args:
user_id (str): The user ID to reject pending invites for.
user_id: The user ID to reject pending invites for.
"""
user = UserID.from_string(user_id)
pending_invites = await self.store.get_invited_rooms_for_local_user(user_id)
Expand Down Expand Up @@ -170,22 +172,16 @@ async def _reject_pending_invites_for_user(self, user_id):
room.room_id,
)

def _start_user_parting(self):
def _start_user_parting(self) -> None:
"""
Start the process that goes through the table of users
pending deactivation, if it isn't already running.
Returns:
None
"""
if not self._user_parter_running:
run_as_background_process("user_parter_loop", self._user_parter_loop)

async def _user_parter_loop(self):
async def _user_parter_loop(self) -> None:
"""Loop that parts deactivated users from rooms
Returns:
None
"""
self._user_parter_running = True
logger.info("Starting user parter")
Expand All @@ -202,11 +198,8 @@ async def _user_parter_loop(self):
finally:
self._user_parter_running = False

async def _part_user(self, user_id):
async def _part_user(self, user_id: str) -> None:
"""Causes the given user_id to leave all the rooms they're joined to
Returns:
None
"""
user = UserID.from_string(user_id)

Expand All @@ -228,3 +221,18 @@ async def _part_user(self, user_id):
user_id,
room_id,
)

async def activate_account(self, user_id: str) -> None:
"""
Activate an account that was previously deactivated.
This simply marks the user as activate in the database and does not
attempt to rejoin rooms, re-add threepids, etc.
The user will also need a password hash set to actually login.
Args:
user_id: ID of user to be deactivated
"""
# Mark the user as activate.
await self.store.set_user_deactivated_status(user_id, False)
Loading

0 comments on commit d9e25be

Please sign in to comment.