feat: add scoped authorization visibility prefilter#14102
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughListing authorization now uses ChangesStructured visibility scope
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ListingRoute
participant AuthorizationService
participant DeploymentQuery
participant Database
ListingRoute->>AuthorizationService: resolve ResourceVisibilityScope
AuthorizationService-->>ListingRoute: scope or None
ListingRoute->>DeploymentQuery: pass visibility_scope
DeploymentQuery->>Database: apply scope to page and count queries
Database-->>ListingRoute: scoped results and total
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 8 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/backend/tests/unit/api/v1/test_deployment_route_handlers.py (2)
817-822: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider reducing reliance on mocks.
As per coding guidelines, backend unit tests should avoid excessive mocking and prefer real integrations. This test suite patches 6 different dependencies for a single route handler, which can obscure what is actually being tested and make the test brittle to internal refactors. Consider migrating these route handler tests to integration tests that use a real test database and the actual FastAPI router in the future.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/tests/unit/api/v1/test_deployment_route_handlers.py` around lines 817 - 822, Reduce excessive mocking in the route handler tests around the patched dependencies visible in the test setup, especially list_deployments_synced, resolve_deployment_adapter, get_deployment_mapper, and the provider-account helpers. Migrate these tests toward integration coverage using the actual FastAPI router and a real test database, preserving assertions for the route behavior while removing mocks that duplicate internal implementation details.Source: Coding guidelines
816-816: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove unnecessary
@pytest.mark.asynciodecorators.Based on learnings,
pytest-asynciois configured withasyncio_mode = 'auto'inpyproject.toml, making explicit@pytest.mark.asynciodecorators unnecessary for tests. Please remove them to follow the repository's convention.
src/backend/tests/unit/api/v1/test_deployment_route_handlers.py#L816-L816: Remove the@pytest.mark.asynciodecorator.src/backend/tests/unit/api/v1/test_deployment_route_handlers.py#L886-L886: Remove the@pytest.mark.asynciodecorator.src/backend/tests/unit/api/v1/test_deployment_route_handlers.py#L931-L931: Remove the@pytest.mark.asynciodecorator.src/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.py#L167-L167: Remove the@pytest.mark.asynciodecorator.♻️ Proposed fixes
For
src/backend/tests/unit/api/v1/test_deployment_route_handlers.py:- `@pytest.mark.asyncio` `@patch`(f"{ROUTES_MODULE}.list_deployments_synced", new_callable=AsyncMock)For
src/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.py:-@pytest.mark.asyncio `@pytest.mark.parametrize`("scope_kind", ["workspace", "project", "global"])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/tests/unit/api/v1/test_deployment_route_handlers.py` at line 816, Remove the unnecessary `@pytest.mark.asyncio` decorators from the async tests at src/backend/tests/unit/api/v1/test_deployment_route_handlers.py lines 816, 886, and 931, and from src/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.py line 167. Rely on the repository’s asyncio_mode = 'auto' configuration and leave the test implementations unchanged.Source: Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/backend/tests/unit/api/v1/test_deployment_route_handlers.py`:
- Around line 817-822: Reduce excessive mocking in the route handler tests
around the patched dependencies visible in the test setup, especially
list_deployments_synced, resolve_deployment_adapter, get_deployment_mapper, and
the provider-account helpers. Migrate these tests toward integration coverage
using the actual FastAPI router and a real test database, preserving assertions
for the route behavior while removing mocks that duplicate internal
implementation details.
- Line 816: Remove the unnecessary `@pytest.mark.asyncio` decorators from the
async tests at src/backend/tests/unit/api/v1/test_deployment_route_handlers.py
lines 816, 886, and 931, and from
src/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.py
line 167. Rely on the repository’s asyncio_mode = 'auto' configuration and leave
the test implementations unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 32368d87-8d68-4275-a759-c5d7b06d74cf
📒 Files selected for processing (13)
src/backend/base/langflow/api/v1/deployments.pysrc/backend/base/langflow/api/v1/flows.pysrc/backend/base/langflow/api/v1/mappers/deployments/helpers.pysrc/backend/base/langflow/api/v1/projects.pysrc/backend/base/langflow/services/authorization/__init__.pysrc/backend/base/langflow/services/authorization/listing.pysrc/backend/base/langflow/services/database/models/deployment/crud.pysrc/backend/tests/unit/api/v1/test_deployment_route_handlers.pysrc/backend/tests/unit/services/authorization/test_route_guard_regressions.pysrc/backend/tests/unit/services/authorization/test_visibility_scope_prefilter.pysrc/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.pysrc/lfx/src/lfx/services/authorization/__init__.pysrc/lfx/src/lfx/services/authorization/base.py
Summary
ResourceVisibilityScopeauthorization contract for concrete, workspace, project, and global grantsWhy
Enterprise scoped RBAC cannot represent a global, workspace, or project wildcard through
list_visible_resource_ids()without loading every matching resource. This seam lets registered authorization plugins return compact scopes that OSS list routes translate directly into SQL.The OSS pass-through behavior is unchanged: when no plugin supplies a prefilter, queries remain owner-scoped and retain the existing in-memory fallback.
Testing
uv run --frozen pytest -q src/backend/tests/unit/services/authorization src/backend/tests/unit/api/v1/test_deployment_route_handlers.py— 306 passeduv run --frozen pytest -q src/backend/tests/unit/services/database/test_deployment_crud_authz_prefilter.py— 7 passedRefs LE-1826
Summary by CodeRabbit