Skip to content

fix: add api hasViewPermissions#3072

Closed
Jarvis1105 wants to merge 2 commits intomainfrom
fix_create_workflow
Closed

fix: add api hasViewPermissions#3072
Jarvis1105 wants to merge 2 commits intomainfrom
fix_create_workflow

Conversation

@Jarvis1105
Copy link
Copy Markdown
Contributor

@Jarvis1105 Jarvis1105 commented Jun 30, 2025

User description

link https://github.com/actiontech/sqle-ee/pull/2411

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2387

描述你的变更

修复当只有创建工单权限,创建工单报错: you have no permission to get rule templates in project

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 新增hasViewPermissions用于多权限判断

  • 添加UserPermission中HasSomsPermissions方法


Changes diagram

flowchart LR
  A["sqle/api/controller/v1/rule.go: 新增hasViewPermissions接口"]
  B["sqle/dms/permission.go: 添加HasSomsPermissions方法"]
  A -- "调用" --> B
Loading

Changes walkthrough 📝

Relevant files
Bug fix
rule.go
添加批量权限判断API接口                                                                                       

sqle/api/controller/v1/rule.go

  • 新增hasViewPermissions函数处理多权限判断
  • 加强项目查看权限校验逻辑
+12/-0   
permission.go
增加批量权限校验方法                                                                                             

sqle/dms/permission.go

  • 新增HasSomsPermissions方法实现权限批量校验
  • 遍历多个权限类型判断匹配成功
+11/-0   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @actiontech-bot actiontech-bot requested review from BugsGuru and removed request for BugsGuru June 30, 2025 04:12
    @github-actions
    Copy link
    Copy Markdown

    github-actions Bot commented Jun 30, 2025

    PR Code Suggestions ✨

    Latest suggestions up to 5304cbe
    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    修正参数类型不匹配

    请检查传递给 HasOneOfPermission 的参数类型是否正确,因为该方法期望的是 []v1.OpPermissionType 而目前输入类型为
    []dmsv1.OpPermissionType。需要确保两者类型一致或者进行适当的类型转换,避免引发编译错误或运行时错误。

    sqle/api/controller/v1/rule.go [1269-1279]

    -func hasViewPermissions(userId, projectUid string, permissionTypes []dmsv1.OpPermissionType) (bool, error) {
    +func hasViewPermissions(userId, projectUid string, permissionTypes []v1.OpPermissionType) (bool, error) {
     	up, err := dms.NewUserPermission(userId, projectUid)
     	if err != nil {
     		return false, fmt.Errorf("get permissions failed: %v", err)
     	}
     	canManage := up.CanViewProject() || up.HasOneOfPermission(permissionTypes)
     	if canManage {
     		return true, nil
     	}
     	return false, nil
     }
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies a type mismatch where HasOneOfPermission expects []v1.OpPermissionType while the current code supplies []dmsv1.OpPermissionType. Changing the parameter type in the function signature is important for avoiding compile errors, and as a type checking suggestion, the score is capped at 8.

    Medium

    Previous suggestions

    Suggestions up to commit 4cbad82
    CategorySuggestion                                                                                                                                    Impact
    General
    简化返回逻辑

    建议将返回值的判断逻辑进行简化,直接使用返回布尔变量。这样可以提高代码的简洁性和可读性,并减少冗余判断逻辑。

    sqle/api/controller/v1/rule.go [1269-1279]

     func hasViewPermissions(userId, projectUid string, permissionTypes []dmsv1.OpPermissionType) (bool, error) {
     	up, err := dms.NewUserPermission(userId, projectUid)
     	if err != nil {
     		return false, fmt.Errorf("get permissions failed: %v", err)
     	}
     	canManage := up.CanViewProject() || up.HasSomsPermissions(permissionTypes)
    -	if canManage {
    -		return true, nil
    -	}
    -	return false, nil
    +	return canManage, nil
     }
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion simplifies the return logic by directly returning the boolean variable, which improves clarity and conciseness. It accurately matches the corresponding lines in the PR diff.

    Medium

    Comment thread sqle/dms/permission.go
    for _, userOpPermission := range p.opPermissionItem {
    for _, permissionType := range opPermissionTypes {
    if userOpPermission.OpPermissionType == permissionType {
    return true
    Copy link
    Copy Markdown
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    HasSomsPermissions方法名应该有拼写错误

    这里逻辑是用户只要有其中一个权限就返回true了,是否是预期的

    Copy link
    Copy Markdown
    Contributor Author

    @Jarvis1105 Jarvis1105 Jun 30, 2025

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    符合预期,拼写问题需要修复。

    @actiontech-bot actiontech-bot requested review from BugsGuru and removed request for BugsGuru June 30, 2025 05:58
    @Jarvis1105 Jarvis1105 closed this Jul 1, 2025
    @Jarvis1105 Jarvis1105 deleted the fix_create_workflow branch July 1, 2025 03:09
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants