fix: gate the recent-activity fetch on audit:read - #69
Conversation
/api/logs/activity requires audit:read, which no default non-admin role holds, so every non-admin home load fired a guaranteed 403. Add an `enabled` option to useRecentActivity, mirroring useSystemHealth's flag for the admin-only /version probe, and gate the home call on it. Signed-off-by: Ahmad Al Tamimi <altamimi.dev@gmail.com>
|
Thanks for contributing! 🙌 No blockers; approving. LLM-assisted feedback on improvements that could be included in this PR or added as followups: Gate is correct, and the backend backs it up:
Confirmed against this branch with a delayed handler: The mini cards only destructure const controller = new AbortController();
+ setIsLoading(true);
void fetchOnce(controller.signal);Worth a comment on that line: it belongs in the effect body, not inside Please add a test asserting |
a-effort
left a comment
There was a problem hiding this comment.
No blocking changes needed. 🚀
Closes #63.
useMiniCardStatusesfetched/api/logs/activityunconditionally, so every caller withoutaudit:read(every non-admin under the default backend roles, includingteam_admin) fired a guaranteed 403 on each home load. The failure is swallowed by the mini cards, so it only showed up as 403 noise in network and server logs.This adds an
enabledoption touseRecentActivity, mirroring the flaguseSystemHealthalready has for the admin-only/versionprobe, and gates the home call onhasPermission("audit:read"). While disabled the hook makes no request and returns an empty feed; permissions load async, so the gate starts closed and the hook fetches when it opens. The gate checksaudit:readonly, notsecurity:read, since the security-events half is additive server-side.The gate lives in the hook rather than the call site so the upcoming ActivityView consumer gets it for free.