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

Commit d8be992

Browse files
authored
Add a flag to the synapse_review_recent_signups script to ignore and filter appservice users. (#11675)
1 parent cefd4b8 commit d8be992

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

changelog.d/11675.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a flag to the `synapse_review_recent_signups` script to ignore and filter appservice users.

synapse/_scripts/review_recent_signups.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class UserInfo:
4646
ips: List[str] = attr.Factory(list)
4747

4848

49-
def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
49+
def get_recent_users(
50+
txn: LoggingTransaction, since_ms: int, exclude_app_service: bool
51+
) -> List[UserInfo]:
5052
"""Fetches recently registered users and some info on them."""
5153

5254
sql = """
@@ -56,6 +58,9 @@ def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
5658
AND deactivated = 0
5759
"""
5860

61+
if exclude_app_service:
62+
sql += " AND appservice_id IS NULL"
63+
5964
txn.execute(sql, (since_ms / 1000,))
6065

6166
user_infos = [UserInfo(user_id, creation_ts) for user_id, creation_ts in txn]
@@ -113,14 +118,20 @@ def main() -> None:
113118
"-e",
114119
"--exclude-emails",
115120
action="store_true",
116-
help="Exclude users that have validated email addresses",
121+
help="Exclude users that have validated email addresses.",
117122
)
118123
parser.add_argument(
119124
"-u",
120125
"--only-users",
121126
action="store_true",
122127
help="Only print user IDs that match.",
123128
)
129+
parser.add_argument(
130+
"-a",
131+
"--exclude-app-service",
132+
help="Exclude appservice users.",
133+
action="store_true",
134+
)
124135

125136
config = ReviewConfig()
126137

@@ -133,6 +144,7 @@ def main() -> None:
133144

134145
since_ms = time.time() * 1000 - Config.parse_duration(config_args.since)
135146
exclude_users_with_email = config_args.exclude_emails
147+
exclude_users_with_appservice = config_args.exclude_app_service
136148
include_context = not config_args.only_users
137149

138150
for database_config in config.database.databases:
@@ -143,7 +155,7 @@ def main() -> None:
143155

144156
with make_conn(database_config, engine, "review_recent_signups") as db_conn:
145157
# This generates a type of Cursor, not LoggingTransaction.
146-
user_infos = get_recent_users(db_conn.cursor(), since_ms) # type: ignore[arg-type]
158+
user_infos = get_recent_users(db_conn.cursor(), since_ms, exclude_users_with_appservice) # type: ignore[arg-type]
147159

148160
for user_info in user_infos:
149161
if exclude_users_with_email and user_info.emails:

synapse/handlers/register.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -979,16 +979,18 @@ async def _register_email_threepid(
979979
if (
980980
self.hs.config.email.email_enable_notifs
981981
and self.hs.config.email.email_notif_for_new_users
982-
and token
983982
):
984983
# Pull the ID of the access token back out of the db
985984
# It would really make more sense for this to be passed
986985
# up when the access token is saved, but that's quite an
987986
# invasive change I'd rather do separately.
988-
user_tuple = await self.store.get_user_by_access_token(token)
989-
# The token better still exist.
990-
assert user_tuple
991-
token_id = user_tuple.token_id
987+
if token:
988+
user_tuple = await self.store.get_user_by_access_token(token)
989+
# The token better still exist.
990+
assert user_tuple
991+
token_id = user_tuple.token_id
992+
else:
993+
token_id = None
992994

993995
await self.pusher_pool.add_pusher(
994996
user_id=user_id,

0 commit comments

Comments
 (0)