feat(permissions): implement fine-grained permission control#2145
Open
Lanfei wants to merge 3 commits intoOpenListTeam:mainfrom
Open
feat(permissions): implement fine-grained permission control#2145Lanfei wants to merge 3 commits intoOpenListTeam:mainfrom
Lanfei wants to merge 3 commits intoOpenListTeam:mainfrom
Conversation
- User.CanWrite() → User.CanCreateFilesOrFolders() - common.CanWrite() → common.CanWriteContentBypassUserPerms() - common.IsApply() → common.MetaCoversPath() Improves code readability by making function names more descriptive. The new MetaCoversPath name clearly indicates it checks if a meta rule covers a specific path. It better conveys that it's a query function rather than an action, and the applyToSubFolder parameter is more explicit than applySub. Also adds comprehensive test coverage: - 10 tests for MetaCoversPath core logic - 6 tests for CanWriteContent UserPerms - 7 tests for getReadme - 5 tests for getHeader - 6 tests for isEncrypt - 9 tests for whetherHide Total: 43 test scenarios covering all path matching and permission inheritance logic. Tests verify both normal behavior and bug fixes for Readme/Header information leakage and write permission bypass. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ite operations Add per-user read and write permission controls at the meta level to enable more granular access control beyond the existing permission flags. Key changes: - Add ReadUsers/WriteUsers fields to Meta model with sub-directory inheritance flags - Implement CanRead and CanWrite permission check functions in server/common - Filter file list results based on user read permissions - Add permission checks across all file operations (FTP, HTTP handlers, WebDAV) - Simplify error handling pattern for MetaNotFound errors throughout codebase This allows administrators to restrict specific users from accessing or modifying certain paths, providing finer control over file system permissions. Note: Batch and recursive operations (FsMove, FsCopy, FsRemove, FsRecursiveMove, FsBatchRename, FsRegexRename) currently check parent directory permissions only. Individual item permission checks are not performed for performance reasons. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…combined permission checks Add TestCanRead, TestCanWrite, TestCanAccessWithReadPermissions, and TestWritePermissionCombinations to validate the three-layer permission system including nil user/meta, sub-path inheritance, user whitelists, and root-level restrictions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0f8b0ea to
da2e92e
Compare
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.
Description / 描述
This PR implements a fine-grained, per-user read/write permission system at the meta level, allowing administrators to restrict specific users from accessing or modifying
certain paths. It also refactors existing permission check functions for clarity and adds comprehensive test coverage.
本 PR 在 meta
层面实现了细粒度的用户读/写权限系统,允许管理员限制特定用户对某些路径的访问或修改权限。同时对现有权限检查函数进行了重命名重构以提升可读性,并添加了完整的测试覆盖。
Key changes / 主要变更:
ReadUsers/WriteUsersfields to theMetamodel with sub-directory inheritance flags在
Meta模型中新增ReadUsers/WriteUsers字段,支持子目录继承标志CanReadandCanWritepermission check functions inserver/common在
server/common中实现CanRead和CanWrite权限检查函数根据用户读权限对文件列表结果进行过滤
在所有文件操作(FTP、HTTP 处理器、WebDAV)中添加权限检查
User.CanWrite()→User.CanCreateFilesOrFolders(),common.CanWrite()→common.CanWriteContentBypassUserPerms(),common.IsApply()→common.MetaCoversPath()重命名函数以提升可读性:
User.CanWrite()→User.CanCreateFilesOrFolders(),common.CanWrite()→common.CanWriteContentBypassUserPerms(),common.IsApply()→common.MetaCoversPath()Motivation and Context / 背景
The existing permission system only supports coarse-grained flags (e.g., global write permission). There was no way to restrict specific users from reading or writing to
particular paths without affecting all users. This PR addresses that gap by introducing a per-user allowlist at the meta level.
现有权限系统仅支持粗粒度的标志位(如全局写权限),无法在不影响其他用户的情况下限制特定用户对特定路径的读写访问。本 PR 通过在 meta 层面引入基于用户的白名单机制来填补这一空白。
Relates to #1328
Closes #1257
Closes #1267
Closes #346
Closes #1753
How Has This Been Tested? / 测试
TestCanRead,TestCanWrite,TestCanAccessWithReadPermissions, andTestWritePermissionCombinationsto validate the three-layer permission system新增
TestCanRead、TestCanWrite、TestCanAccessWithReadPermissions及TestWritePermissionCombinations,验证三层权限体系测试场景覆盖:nil 用户/meta、子路径继承、用户白名单及根路径限制
MetaCoversPath,CanWriteContentBypassUserPerms,getReadme,getHeader,isEncrypt, andwhetherHide为
MetaCoversPath、CanWriteContentBypassUserPerms、getReadme、getHeader、isEncrypt、whetherHide新增 43 个测试场景list_test.goandfsread_test.gofor coverage of list filtering and read handler logic新增
list_test.go和fsread_test.go,覆盖列表过滤与读取处理器逻辑Checklist / 检查清单
我已阅读 CONTRIBUTING 文档。
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已相应更新了相关仓库(若适用)。