Fix unique milestone names perms#2842
Conversation
|
Warning Review limit reached
More reviews will be available in 1 minute and 8 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR extends the unique milestone names endpoint with optional filtering by user relation and process model identifier. The backend adds service layer methods to filter instances by user involvement and compute distinct milestone names. The frontend provides helper utilities to construct query-parameterized URIs and merge selected values into option lists, then integrates them into the filter component with permission-gated fetching. ChangesUnique Milestone Names Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py (1)
687-704: ⚡ Quick winDrop
selectinload(...)forwith_entities(...)queries
get_basic_query()’sselectinload(ProcessInstanceModel.process_initiator)doesn’t generally cause a runtime error whenunique_milestone_names()narrows the query to a scalar column viawith_entities(ProcessInstanceModel.last_milestone_bpmn_name). However, the eager-load option can’t be applied meaningfully once the result is no longer ORM entities, so the option is effectively a no-op. Consider disabling/omitting eager-loads for this specific path for clarity/efficiency.🤖 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 `@spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py` around lines 687 - 704, The query returned by cls.get_basic_query(filters) still carries the selectinload(ProcessInstanceModel.process_initiator) option which becomes a no-op for scalar queries; before calling .with_entities(ProcessInstanceModel.last_milestone_bpmn_name) in unique_milestone_names (or the method containing this snippet), explicitly disable eager loads on process_instance_query (e.g. call process_instance_query = process_instance_query.enable_eagerloads(False) or otherwise strip/avoid the selectinload option) so the query no longer retains the selectinload and the resulting scalar query is clear and efficient.
🤖 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.
Inline comments:
In
`@spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py`:
- Around line 663-669: The logic that sets should_scope_to_requesting_user
wrongfully treats users with model-scoped permissions as basic users; update the
check in the block using should_scope_to_requesting_user, with_relation_to_me,
and AuthorizationService.user_has_permission so that if process_model_identifier
is present you first ask AuthorizationService.user_has_permission(user=g.user,
permission="read",
target_uri=f"/process-instances/{process_model_identifier}/*") (or equivalent
model-scoped target) and only fall back to the global "/process-instances" check
when no model identifier is given or model-scoped read is denied; keep the
existing append to filters for with_relation_to_me when the combined result
requires scoping.
In
`@spiffworkflow-frontend/src/components/ProcessInstanceListTableWithFilters.tsx`:
- Around line 513-537: The effect that fetches milestone names (useEffect) can
have overlapping responses overwrite state; modify the
HttpService.makeCallToBackend call in this effect to ignore stale responses by
attaching a request-scoped guard (e.g. a locally generated requestId or capture
of uniqueMilestoneNamesPath) and only calling setLastMilestones if the guard
still matches current scope when the successCallback runs; implement the guard
inside the successCallback (or via AbortController if supported) and reference
useEffect, HttpService.makeCallToBackend, uniqueMilestoneNamesPath, and
setLastMilestones to locate the change.
---
Nitpick comments:
In
`@spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py`:
- Around line 687-704: The query returned by cls.get_basic_query(filters) still
carries the selectinload(ProcessInstanceModel.process_initiator) option which
becomes a no-op for scalar queries; before calling
.with_entities(ProcessInstanceModel.last_milestone_bpmn_name) in
unique_milestone_names (or the method containing this snippet), explicitly
disable eager loads on process_instance_query (e.g. call process_instance_query
= process_instance_query.enable_eagerloads(False) or otherwise strip/avoid the
selectinload option) so the query no longer retains the selectinload and the
resulting scalar query is clear and efficient.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fa238093-1cac-41a1-98e2-08988f811547
📒 Files selected for processing (10)
spiffworkflow-backend/src/spiffworkflow_backend/api.ymlspiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.pyspiffworkflow-backend/src/spiffworkflow_backend/services/authorization_service.pyspiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.pyspiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_instances_controller.pyspiffworkflow-backend/tests/spiffworkflow_backend/unit/test_authorization_service.pyspiffworkflow-frontend/src/components/ProcessInstanceListTableWithFilters.tsxspiffworkflow-frontend/src/helpers.test.tsxspiffworkflow-frontend/src/helpers.tsxspiffworkflow-frontend/src/hooks/UriListForPermissions.tsx
This fixes unique milestone api call for basic permissions.