Draft
[Membership] Make role DataScope the single source of truth for row-level access#99
Conversation
Co-authored-by: nnhy <506367+nnhy@users.noreply.github.com>
Co-authored-by: nnhy <506367+nnhy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix DataScope validation issue in XCode
[Membership] Make role DataScope the single source of truth for row-level access
Aug 27, 2026
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.
DataScopecould not drive row-level permissions:Role.Validrewrote "全部"(0) on every save,DataScopeInterceptor.OnValidswallowed access failures and returnedtrue, andUser/Department/Logwere not wired intoGetFilter. This makes the roleDataScopefield the authoritative row-permission source, which XCode must own since Cube cannot patch these across assemblies.Validation (P0)
角色.Biz.cs— DefaultDataScopefromTypeonly on Insert when the field is not dirty. On Update or explicit assignment,0means "全部" and is left untouched.DataScopeModule.cs—OnValidnow returnsfalse(after writing the audit log) when an access check throws, instead of returningtrue. No-context still skips validation.Entity wiring (P0)
User— registerDataScopeInterceptor.Department— implementIDepartmentScope(DepartmentId→ID) +IDataScopeFieldProvider+ interceptor.Log— implementIUserScope(→CreateUserID),GetUserField() => _.CreateUserID+ interceptor.Filter semantics (P1)
IDepartmentScope(one row per department): 仅本人 filtersID = current departmentinstead of the always-falseEqual(-1); other scopes reuseBuildDepartmentFilter.CanAccess(IDepartmentScope)mirrors this.IDataScope(User) 仅本人-by-UserId semantics are unchanged.IUserScope(no department column, e.g.Log): non-全部 staysuserField = currentUser, so 本部门/自定义 do not widen to colleagues' rows.Cache (P1)
DataScopeContext— cache key is nowuserId+deptId+scopeso a department change takes effect immediately;ClearCache(userId)removes both old and new keys by prefix (best-effort).Menu default (P2)
菜单.Biz.cs— new/unconfigured menus keepDataScope = -1(use role default) rather than persisting0and overriding the role to "全部".Example
Adds 7 acceptance tests in
DataScopeTests.cscovering the criteria above, and corrects one existing test that relied on the swallowed-exception behavior.