[NAE 2424] UserRefs negative view permissions aren't resolved#442
Conversation
- negativeViewUsers resolution fix in Case and Task - added test TaskPermissionsTest with test nets view_permission_combinations.xml and view_permission_combinations_no_default.xml
- fix typo in role id
- refactored task view permission query resolution for both elastic search in ElasticViewPermissionService and for mongo in TaskSearchService - added mongo search test to TaskPermissionsTest
# Conflicts: # src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java # src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java # src/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.java
- after merge fixes
WalkthroughThis PR refactors the view permission system to treat negative view permissions as first-class entities across the domain model, permission resolution, and search backends. Case and Task now populate ChangesView Permission System Refactoring
Sequence Diagram(s)sequenceDiagram
participant Client
participant ElasticTaskService
participant ElasticViewPermissionService
Client->>ElasticTaskService: buildSingleQuery(request, user)
ElasticTaskService->>ElasticTaskService: construct BoolQueryBuilder (no role constraint preprocessing)
ElasticTaskService->>ElasticViewPermissionService: buildViewPermissionQuery
ElasticViewPermissionService->>ElasticViewPermissionService: buildPositiveViewRoleQuery (should clause)
ElasticViewPermissionService->>ElasticViewPermissionService: buildPositiveViewUser (should clause)
ElasticViewPermissionService->>ElasticViewPermissionService: buildNegativeViewUser (mustNot clause)
ElasticViewPermissionService-->>ElasticTaskService: combined permission query
ElasticTaskService-->>Client: final BoolQueryBuilder
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 4
🤖 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
`@src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java`:
- Around line 18-24: The current buildViewPermissionQuery uses a
BoolQueryBuilder roleOrPositiveUserQuery that requires either roleViewQuery or
buildPositiveViewUser to match, which excludes documents that lack both
viewRoles and viewUsers; change roleOrPositiveUserQuery to also allow documents
where both permission fields are missing by adding an additional should clause
that matches "viewRoles not exists AND viewUsers not exists" (use exists queries
for viewRoles/viewUsers and combine them with mustNot as a should option) so
minimumShouldMatch(1) still applies, and leave the existing
mustNot(buildNegativeViewUser(user)) in place; update
ElasticViewPermissionService.buildViewPermissionQuery (and any helper usage of
roleViewQuery, buildPositiveViewUser, buildNegativeViewUser) to implement this
or alternatively document and implement a migration/backfill that populates
explicit positive defaults for existing documents.
In `@src/main/java/com/netgrif/application/engine/importer/service/Importer.java`:
- Around line 1160-1161: The current guard calls
importTransition.getRoleRef().isEmpty(), getUsersRef().isEmpty(), and
getUserRef().isEmpty() directly and can NPE when any of those refs is null;
change the condition to null-safe checks (e.g., check each ref for null before
calling isEmpty or use a utility like CollectionUtils.isEmpty/Objects.nonNull)
so the early-return only triggers when a non-null collection/string is present
and non-empty; update the condition around getRoleRef(), getUsersRef(), and
getUserRef() in Importer.java to perform null checks first.
In
`@src/test/groovy/com/netgrif/application/engine/workflow/TaskPermissionsTest.groovy`:
- Around line 66-70: The static maps testUsers and correctResults are reused
across tests; modify the init() setup method to reset static state at the
beginning by clearing testUsers and correctResults (call their clear/reset) and
also reset testCase and testCaseNoDefault to null so each test starts with a
clean slate; locate these symbols (testUsers, correctResults, testCase,
testCaseNoDefault, init) and add the clears/null assignments at the top of
init().
- Around line 141-153: The test currently uses header.indexOf(...) (e.g.,
transitionIdIndex and permissionIndex) without checking for -1, which can
silently pick wrong columns; update TaskPermissionsTest.groovy to validate
indices immediately after computing them (for transitionIdIndex and each
permissionIndex derived from header.indexOf(csvColumnName)) and throw a clear
failure (IllegalStateException or assertion) if any index is -1, including the
missing header name in the error message so the test fails fast when required
CSV headers are missing.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 43c90be6-3661-4bd4-9423-0c20d7493b81
⛔ Files ignored due to path filters (2)
src/test/resources/csv/permissions - correct default disabled.csvis excluded by!**/*.csvsrc/test/resources/csv/permissions - correct.csvis excluded by!**/*.csv
📒 Files selected for processing (11)
src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.javasrc/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.javasrc/main/java/com/netgrif/application/engine/importer/service/Importer.javasrc/main/java/com/netgrif/application/engine/workflow/domain/Case.javasrc/main/java/com/netgrif/application/engine/workflow/domain/Task.javasrc/main/java/com/netgrif/application/engine/workflow/service/TaskSearchService.javasrc/main/java/com/netgrif/application/engine/workflow/service/TaskService.javasrc/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.javasrc/test/groovy/com/netgrif/application/engine/workflow/TaskPermissionsTest.groovysrc/test/resources/petriNets/view_permission_combinations.xmlsrc/test/resources/petriNets/view_permission_combinations_no_default.xml
💤 Files with no reviewable changes (1)
- src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java
- null check added to Importer
mazarijuraj
left a comment
There was a problem hiding this comment.
check manually with example app
Description
Refactor of task view permission query resolution for both elastic and mongo search
Fixes NAE-2424
How Has Been This Tested?
Test included in test file TaskPermissionsTest
Checklist:
Summary by CodeRabbit
Bug Fixes
Tests