Skip to content

Commit 4d6f440

Browse files
committed
fix: botfilter for user sync
1 parent 87cf85b commit 4d6f440

5 files changed

Lines changed: 38 additions & 9 deletions

File tree

‎docs/tools/user-sync.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ only core identity plus email.
5555

5656
1. Enumerate MediaWiki accounts, skipping bots and privileged groups
5757
(`bot`, `sysop`, `bureaucrat`, `interface-admin`) and MediaWiki reserved
58-
system usernames.
58+
system usernames. Accounts whose username is an exact ORCID iD are exempt
59+
from the group filter (so a person's own admin account is synced); other
60+
accounts, such as `<orcid>@bot`, are still excluded by their groups.
5961
2. Enrich ORCID users from `https://pub.orcid.org/v3.0/<id>`: names and email
6062
always; researcher URLs and affiliations only when their flag is enabled.
6163
3. Map each account to a proposed `User` item with a deterministic id

‎pyproject.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ workflow = [
8686
]
8787
tutorial = ["osw[dataimport]"]
8888
all = ["osw[dataimport,DB,UI,S3,wikitext]"]
89+
examples = [
90+
"python-dotenv>=1.2.4",
91+
]
8992

9093
[build-system]
9194
requires = ["hatchling"]

‎src/osw/tools/user_sync/sources.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ def enumerate_mw_users(
105105
106106
Args:
107107
site: An object exposing ``api("query", ...)`` (an mwclient Site).
108-
excluded_groups: Accounts in any of these groups are skipped (bots, admins).
108+
excluded_groups: Accounts in any of these groups are skipped (bots, admins),
109+
unless the username is an exact ORCID iD (a person's own account).
110+
Bot accounts derived from an ORCID (e.g. ``<orcid>@bot``) are not exact
111+
ORCID iDs and stay excluded.
109112
excluded_usernames: Exact usernames to skip (reserved system accounts).
110113
include_orcid: If False, skip ORCID-username accounts.
111114
include_non_orcid: If False, keep only ORCID-username accounts.
@@ -119,7 +122,7 @@ def enumerate_mw_users(
119122
user = MwUser.from_api(raw)
120123
if user.name in excluded_names:
121124
continue
122-
if excluded.intersection(user.groups):
125+
if not user.is_orcid and excluded.intersection(user.groups):
123126
continue
124127
if not include_non_orcid and not user.is_orcid:
125128
continue

‎tests/tools/test_user_sync_sources.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ def test_enumerate_excludes_privileged_groups_and_reserved_names():
110110
assert [u.name for u in users] == ["0000-0002-6374-9831"]
111111

112112

113+
def test_enumerate_keeps_orcid_accounts_despite_excluded_groups():
114+
site = FakeSite([
115+
_page([
116+
{"name": "0000-0001-7620-1245", "groups": ["user", "bot", "sysop"]},
117+
{"name": "0000-0001-7620-1245@importer", "groups": ["user", "bot"]},
118+
{"name": "SomeBot", "groups": ["user", "bot"]},
119+
{"name": "Admin", "groups": ["user", "sysop"]},
120+
])
121+
])
122+
users = enumerate_mw_users(site, excluded_groups=("bot", "sysop"))
123+
assert [u.name for u in users] == ["0000-0001-7620-1245"]
124+
125+
113126
def test_enumerate_mw_only_skips_orcid():
114127
site = FakeSite([
115128
_page([

‎uv.lock‎

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)