Conversation
…wnership guards Add server-side user scoping to all pipeline, flow, and job REST endpoints so each user sees only their own data in WP-Admin by default. New PermissionHelper methods: - resolve_scoped_user_id(): non-admins always get their own user_id; admins see all by default, or filter by ?user_id=X - owns_resource(): checks if acting user owns a resource (by user_id on the record), allows admins and single-agent mode (user_id 0) Pipeline REST API: - GET scoped by user_id (passed to GetPipelinesAbility) - POST stamps user_id from acting_user_id() - PATCH/DELETE verify ownership before executing - Memory-file GET/PUT verify ownership Flow REST API: - GET scoped by user_id (passed to GetFlowsAbility) - POST stamps user_id from acting_user_id() - PATCH/DELETE/duplicate verify ownership before executing - Memory-file GET/PUT verify ownership Jobs REST API: - GET scoped by user_id (passed to GetJobsAbility) DB and Abilities layers already supported user_id — this PR wires the REST endpoints to actually use it. Closes #573
Homeboy Results —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds server-side user scoping to all pipeline, flow, and job REST endpoints so each user sees only their own data in WP-Admin. Admins see everything by default with an optional
?user_id=Xfilter.?user_id=Xfor a specific useruser_id=0resources remain accessible to anyone with the capability (backward compatible)What Changed
inc/Abilities/PermissionHelper.phpresolve_scoped_user_id()andowns_resource()methodsinc/Api/Pipelines/Pipelines.phpinc/Api/Flows/Flows.phpinc/Api/Jobs.phpHow It Works
Query Scoping (GET endpoints)
The resolved user_id is passed to the existing abilities (
GetPipelinesAbility,GetFlowsAbility,GetJobsAbility) which already acceptuser_idand pass it to the DB layer. No DB or abilities changes needed.Ownership Guards (mutation endpoints)
React Frontend
No React changes in this PR. The frontend doesn't need to send
user_id— the server auto-injects scoping from the authenticated user. A future PR can add an admin user-filter dropdown, but the scoping works transparently without it.Test Results
Architecture Note
The existing pattern from
Api/AgentFiles.phpwas the model — it already hadresolve_scoped_user_id()and ownership checks. This PR extends the same pattern to pipelines, flows, and jobs using a centralizedPermissionHelperinstead of per-class methods.Closes #573