mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-08 05:02:12 -04:00
Only count real users when checking for auto-creation of auto-join room
Previously if the first registered user was a "support" or "bot" user, when the first real user registers, the auto-join rooms were not created. Fix to exclude non-real (ie users with a special user type) users when counting how many users there are to determine whether we should auto-create a room. Signed-off-by: Jason Robinson <jasonr@matrix.org>
This commit is contained in:
parent
55d5b3af88
commit
be618e0551
4 changed files with 71 additions and 10 deletions
|
@ -322,6 +322,21 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||
|
||||
return None
|
||||
|
||||
@cachedInlineCallbacks()
|
||||
def is_real_user(self, user_id):
|
||||
"""Determines if the user is a real user, ie does not have a 'user_type'.
|
||||
|
||||
Args:
|
||||
user_id (str): user id to test
|
||||
|
||||
Returns:
|
||||
Deferred[bool]: True if user 'user_type' is null or empty string
|
||||
"""
|
||||
res = yield self.runInteraction(
|
||||
"is_real_user", self.is_real_user_txn, user_id
|
||||
)
|
||||
return res
|
||||
|
||||
@cachedInlineCallbacks()
|
||||
def is_support_user(self, user_id):
|
||||
"""Determines if the user is of type UserTypes.SUPPORT
|
||||
|
@ -337,6 +352,16 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||
)
|
||||
return res
|
||||
|
||||
def is_real_user_txn(self, txn, user_id):
|
||||
res = self._simple_select_one_onecol_txn(
|
||||
txn=txn,
|
||||
table="users",
|
||||
keyvalues={"name": user_id},
|
||||
retcol="user_type",
|
||||
allow_none=True,
|
||||
)
|
||||
return True if res is None or res == "" else False
|
||||
|
||||
def is_support_user_txn(self, txn, user_id):
|
||||
res = self._simple_select_one_onecol_txn(
|
||||
txn=txn,
|
||||
|
@ -421,6 +446,20 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||
ret = yield self.runInteraction("count_users", _count_users)
|
||||
return ret
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def count_real_users(self):
|
||||
"""Counts all users without a special user_type registered on the homeserver."""
|
||||
|
||||
def _count_users(txn):
|
||||
txn.execute("SELECT COUNT(*) AS users FROM users where user_type is null or user_type = ''")
|
||||
rows = self.cursor_to_dict(txn)
|
||||
if rows:
|
||||
return rows[0]["users"]
|
||||
return 0
|
||||
|
||||
ret = yield self.runInteraction("count_real_users", _count_users)
|
||||
return ret
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def find_next_generated_user_id_localpart(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue