mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Merge pull request #6420 from matrix-org/erikj/fix_find_next_generated_user_id_localpart
Fix guest registration
This commit is contained in:
commit
f085894cd1
1
changelog.d/6420.bugfix
Normal file
1
changelog.d/6420.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix broken guest registration when there are existing blocks of numeric user IDs.
|
@ -19,7 +19,6 @@ import logging
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from six import iterkeys
|
from six import iterkeys
|
||||||
from six.moves import range
|
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet.defer import Deferred
|
||||||
@ -482,12 +481,8 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||||||
"""
|
"""
|
||||||
Gets the localpart of the next generated user ID.
|
Gets the localpart of the next generated user ID.
|
||||||
|
|
||||||
Generated user IDs are integers, and we aim for them to be as small as
|
Generated user IDs are integers, so we find the largest integer user ID
|
||||||
we can. Unfortunately, it's possible some of them are already taken by
|
already taken and return that plus one.
|
||||||
existing users, and there may be gaps in the already taken range. This
|
|
||||||
function returns the start of the first allocatable gap. This is to
|
|
||||||
avoid the case of ID 1000 being pre-allocated and starting at 1001 while
|
|
||||||
0-999 are available.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _find_next_generated_user_id(txn):
|
def _find_next_generated_user_id(txn):
|
||||||
@ -497,15 +492,14 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||||||
|
|
||||||
regex = re.compile(r"^@(\d+):")
|
regex = re.compile(r"^@(\d+):")
|
||||||
|
|
||||||
found = set()
|
max_found = 0
|
||||||
|
|
||||||
for (user_id,) in txn:
|
for (user_id,) in txn:
|
||||||
match = regex.search(user_id)
|
match = regex.search(user_id)
|
||||||
if match:
|
if match:
|
||||||
found.add(int(match.group(1)))
|
max_found = max(int(match.group(1)), max_found)
|
||||||
for i in range(len(found) + 1):
|
|
||||||
if i not in found:
|
return max_found + 1
|
||||||
return i
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user