feat: scope agent dropdown to current site using site_scope column#946
Merged
feat: scope agent dropdown to current site using site_scope column#946
Conversation
Mirror WordPress core's multisite user scoping pattern: agent queries default to the current blog_id, returning agents with matching site_scope OR site_scope IS NULL (network-wide). This ensures each subsite's agent dropdown shows only relevant agents instead of all agents across the network. Changes: - Agents::get_all() accepts optional site_id arg for site_scope filtering - Api\Agents::handle_list() passes current blog_id for both admin and non-admin paths - shape_list_item() includes site_scope in REST API response - AgentAbilities::listAgents() filters by current site - PermissionHelper::resolve_scoped_agent_id() falls back to access grants when user owns no agent (fixes gap for shared agent access)
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
blog_id, returning only agents with matchingsite_scopeORsite_scope IS NULL(network-wide)site_scopeto REST API response so the frontend knows which site an agent belongs toresolve_scoped_agent_id()for non-admin users who don't own an agent but have explicit access grantsTest Results
Verified across all subsites via WP-CLI and REST API:
Agent test suite: 83 passed, 30 failed (same as main branch — zero regressions).
Files Changed
inc/Core/Database/Agents/Agents.php—get_all()accepts optionalsite_idarginc/Api/Agents.php—handle_list()passes current blog_id;shape_list_item()includessite_scopeinc/Abilities/AgentAbilities.php—listAgents()filters by current siteinc/Abilities/PermissionHelper.php—resolve_scoped_agent_id()checks access grants in non-admin fallback