mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 05:53:51 +01:00
Add a flag to the synapse_review_recent_signups
script to ignore and filter appservice users. (#11675)
This commit is contained in:
parent
cefd4b87a3
commit
d8be9924ef
3 changed files with 23 additions and 8 deletions
1
changelog.d/11675.feature
Normal file
1
changelog.d/11675.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add a flag to the `synapse_review_recent_signups` script to ignore and filter appservice users.
|
|
@ -46,7 +46,9 @@ class UserInfo:
|
||||||
ips: List[str] = attr.Factory(list)
|
ips: List[str] = attr.Factory(list)
|
||||||
|
|
||||||
|
|
||||||
def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
|
def get_recent_users(
|
||||||
|
txn: LoggingTransaction, since_ms: int, exclude_app_service: bool
|
||||||
|
) -> List[UserInfo]:
|
||||||
"""Fetches recently registered users and some info on them."""
|
"""Fetches recently registered users and some info on them."""
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
|
@ -56,6 +58,9 @@ def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
|
||||||
AND deactivated = 0
|
AND deactivated = 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if exclude_app_service:
|
||||||
|
sql += " AND appservice_id IS NULL"
|
||||||
|
|
||||||
txn.execute(sql, (since_ms / 1000,))
|
txn.execute(sql, (since_ms / 1000,))
|
||||||
|
|
||||||
user_infos = [UserInfo(user_id, creation_ts) for user_id, creation_ts in txn]
|
user_infos = [UserInfo(user_id, creation_ts) for user_id, creation_ts in txn]
|
||||||
|
@ -113,7 +118,7 @@ def main() -> None:
|
||||||
"-e",
|
"-e",
|
||||||
"--exclude-emails",
|
"--exclude-emails",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Exclude users that have validated email addresses",
|
help="Exclude users that have validated email addresses.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-u",
|
"-u",
|
||||||
|
@ -121,6 +126,12 @@ def main() -> None:
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Only print user IDs that match.",
|
help="Only print user IDs that match.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-a",
|
||||||
|
"--exclude-app-service",
|
||||||
|
help="Exclude appservice users.",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
|
||||||
config = ReviewConfig()
|
config = ReviewConfig()
|
||||||
|
|
||||||
|
@ -133,6 +144,7 @@ def main() -> None:
|
||||||
|
|
||||||
since_ms = time.time() * 1000 - Config.parse_duration(config_args.since)
|
since_ms = time.time() * 1000 - Config.parse_duration(config_args.since)
|
||||||
exclude_users_with_email = config_args.exclude_emails
|
exclude_users_with_email = config_args.exclude_emails
|
||||||
|
exclude_users_with_appservice = config_args.exclude_app_service
|
||||||
include_context = not config_args.only_users
|
include_context = not config_args.only_users
|
||||||
|
|
||||||
for database_config in config.database.databases:
|
for database_config in config.database.databases:
|
||||||
|
@ -143,7 +155,7 @@ def main() -> None:
|
||||||
|
|
||||||
with make_conn(database_config, engine, "review_recent_signups") as db_conn:
|
with make_conn(database_config, engine, "review_recent_signups") as db_conn:
|
||||||
# This generates a type of Cursor, not LoggingTransaction.
|
# This generates a type of Cursor, not LoggingTransaction.
|
||||||
user_infos = get_recent_users(db_conn.cursor(), since_ms) # type: ignore[arg-type]
|
user_infos = get_recent_users(db_conn.cursor(), since_ms, exclude_users_with_appservice) # type: ignore[arg-type]
|
||||||
|
|
||||||
for user_info in user_infos:
|
for user_info in user_infos:
|
||||||
if exclude_users_with_email and user_info.emails:
|
if exclude_users_with_email and user_info.emails:
|
||||||
|
|
|
@ -979,16 +979,18 @@ class RegistrationHandler:
|
||||||
if (
|
if (
|
||||||
self.hs.config.email.email_enable_notifs
|
self.hs.config.email.email_enable_notifs
|
||||||
and self.hs.config.email.email_notif_for_new_users
|
and self.hs.config.email.email_notif_for_new_users
|
||||||
and token
|
|
||||||
):
|
):
|
||||||
# Pull the ID of the access token back out of the db
|
# Pull the ID of the access token back out of the db
|
||||||
# It would really make more sense for this to be passed
|
# It would really make more sense for this to be passed
|
||||||
# up when the access token is saved, but that's quite an
|
# up when the access token is saved, but that's quite an
|
||||||
# invasive change I'd rather do separately.
|
# invasive change I'd rather do separately.
|
||||||
|
if token:
|
||||||
user_tuple = await self.store.get_user_by_access_token(token)
|
user_tuple = await self.store.get_user_by_access_token(token)
|
||||||
# The token better still exist.
|
# The token better still exist.
|
||||||
assert user_tuple
|
assert user_tuple
|
||||||
token_id = user_tuple.token_id
|
token_id = user_tuple.token_id
|
||||||
|
else:
|
||||||
|
token_id = None
|
||||||
|
|
||||||
await self.pusher_pool.add_pusher(
|
await self.pusher_pool.add_pusher(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
|
Loading…
Reference in a new issue