Keep Google-only accounts out of the M365 scan
Graph returned 404 for /users/google:<email>/mailFolders: Google- Workspace-only accounts (id "google:<email>") reached the M365 scan. - getSelectedUsers() fell back to "every ticked checkbox in the DOM" whenever no M365 account was ticked — including Google-only rows. The fallback is now only used before the user list has loaded, and never includes google: rows. - startScan() skips the M365 part (with a log line) when M365 sources are ticked but no M365 accounts are: the server treats an empty account list as "every user in the tenant". - run_scan: _resolve_manual_users -> _resolve_scan_users, which now also drops google: ids (reported as a phase message). Covers scheduled scans and profiles that already contain Google-only accounts. Never widens to all users. Tests: 3 new in tests/test_manual_users.py; the run_scan one fails on the old engine with exactly the reported Graph call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b60c4a5c47
commit
b5476228ba
8 files changed
+99
-19
No files matched your search
+1
-1
@@ -91,7 +91,7 @@ Never revert to `!!window._googleConnected` / `_fileSources.length > 0` — thos
|
||||
- The profile editor's "+ Tilføj konto" looks the email up via `/api/users/lookup` and stores `{id: <directory id>, displayName, email, manual: true}`. It falls back to `"manual:<email>"` only when the lookup fails. Checkboxes with `data-manual` save as objects; everything else saves as plain id strings.
|
||||
- `_applyProfile()` → `_addProfileManualUsers()` pushes manual accounts into `S._allUsers` (`manual: true`, `platform: 'm365'`). Legacy `manual:<email>` entries are looked up and the pending ID is rewritten to the resolved one. Without this the account can never be ticked in the sidebar, so it's never scanned.
|
||||
- `_userListFinal()` keys off `S._m365UsersLoaded`, not `S._allUsers.length`, because manual users can be pushed before the directory loads.
|
||||
- Server side, `scan_engine._resolve_manual_users()` resolves any remaining `manual:<email>` (e.g. from scheduled scans) via `conn.lookup_user()`. It skips and reports failures and never widens to "all users".
|
||||
- Server side, `scan_engine._resolve_scan_users()` resolves any remaining `manual:<email>` (e.g. from scheduled scans) via `conn.lookup_user()`, and drops `google:<email>` (Google-only accounts, which Graph 404s on). It skips and reports failures and never widens to "all users".
|
||||
- **Pending profile users wait for the Google merge** — `_applyPendingProfileUsers()` keeps `window._pendingProfileUserIds` until every ID is matched or `_userListFinal()` (users loaded, and Google either not connected or `S._googleUsersMerged`). `_mergeGoogleUsers()` re-applies in its `finally`. A saved `google:<email>` also matches an M365 user merged to `platform: 'both'` via `u.googleEmail`. Do not clear the pending IDs unconditionally — Google-only users would stay unticked.
|
||||
- **Date presets** — stored as `years * 365` (integer days). Do not use `* 365.25`.
|
||||
- **`copyTokenLink` is async** — called from `onclick` as fire-and-forget. Do not make it synchronous.
|
||||
|
||||
+9
-3
@@ -569,7 +569,13 @@ function startScan(resume) {
|
||||
document.getElementById('resumeBanner').style.display = 'none';
|
||||
document.getElementById('logPanel').innerHTML = '<div class="log-line log-live" id="logLive" style="display:none"></div>';
|
||||
try { sessionStorage.removeItem(_LOG_SESSION_KEY); } catch(e) {}
|
||||
S._m365ScanRunning = sources.length > 0;
|
||||
// The M365 scan needs explicit accounts — the server treats an empty list as
|
||||
// "every user in the tenant". With only Google accounts ticked, skip it.
|
||||
const runM365 = sources.length > 0 && user_ids.length > 0;
|
||||
if (sources.length && !runM365) {
|
||||
log(t('m365_no_m365_accounts', 'No Microsoft 365 accounts selected — skipping the Microsoft 365 sources.'), 'warn');
|
||||
}
|
||||
S._m365ScanRunning = runM365;
|
||||
S._googleScanRunning = googleSources.length > 0;
|
||||
S._fileScanRunning = fileSources.length > 0;
|
||||
S._srcPct = { m365: 0, google: 0, file: 0 };
|
||||
@@ -613,8 +619,8 @@ function startScan(resume) {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
// Fire M365 scan if any M365 sources are selected
|
||||
if (sources.length > 0) {
|
||||
// Fire M365 scan if any M365 sources and accounts are selected
|
||||
if (runM365) {
|
||||
fetch('/api/scan/start', {
|
||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({sources, user_ids, options, resume: !!resume,
|
||||
|
||||
+11
-4
@@ -461,10 +461,17 @@ function getSelectedUsers() {
|
||||
{ id: u.id, displayName: u.displayName, userRole: u.userRole || 'other' },
|
||||
u.manual ? { manual: true, email: u.email || '' } : {}));
|
||||
}
|
||||
// Fallback to DOM if S._allUsers not yet populated
|
||||
return Array.from(document.querySelectorAll('.account-check:checked')).map(cb => ({
|
||||
id: cb.dataset.id, displayName: cb.dataset.name, userRole: cb.dataset.role || 'other'
|
||||
}));
|
||||
// Once the user list is loaded it is authoritative: no ticked M365 users means
|
||||
// none. (Falling back to the DOM here collected every ticked checkbox —
|
||||
// including Google-only "google:<email>" rows — and sent them to the M365
|
||||
// scan, where Graph 404s on them.)
|
||||
if (S._allUsers.length) return [];
|
||||
// Fallback to DOM only while S._allUsers is not yet populated
|
||||
return Array.from(document.querySelectorAll('.account-check:checked'))
|
||||
.filter(cb => !String(cb.dataset.id || '').startsWith('google:'))
|
||||
.map(cb => ({
|
||||
id: cb.dataset.id, displayName: cb.dataset.name, userRole: cb.dataset.role || 'other'
|
||||
}));
|
||||
}
|
||||
|
||||
// ── Window exports (HTML handlers + cross-module calls) ─────────────────────
|
||||
|
||||
Reference in new issue
Block a user