From 1bbd0ce0047a440b98cb9bb9260644bfab7af2c1 Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Fri, 18 Oct 2024 13:54:39 +0800 Subject: [PATCH 1/2] modify: when get op permission without project id return permission from all projects --- internal/dms/service/user.go | 17 +++++++++++++---- pkg/dms-common/api/dms/v1/user.go | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/dms/service/user.go b/internal/dms/service/user.go index 9360fd59..ae0296ab 100644 --- a/internal/dms/service/user.go +++ b/internal/dms/service/user.go @@ -384,11 +384,20 @@ func (d *DMSService) GetUserOpPermission(ctx context.Context, req *dmsCommonV1.G } permissions = append(permissions, globalPermissions...) - projectPermissions, err := d.OpPermissionVerifyUsecase.GetUserOpPermissionInProject(ctx, req.UserUid, projectUid) - if err != nil { - return nil, fmt.Errorf("get user op permission error: %v", err) + if projectUid != "" { + projectPermissions, err := d.OpPermissionVerifyUsecase.GetUserOpPermissionInProject(ctx, req.UserUid, projectUid) + if err != nil { + return nil, fmt.Errorf("get user op permission error: %v", err) + } + permissions = append(permissions, projectPermissions...) + + } else { + projectPermissions, err := d.OpPermissionVerifyUsecase.GetUserOpPermission(ctx, req.UserUid) + if err != nil { + return nil, fmt.Errorf("get user op permission error: %v", err) + } + permissions = append(permissions, projectPermissions...) } - permissions = append(permissions, projectPermissions...) var replyOpPermission = make([]dmsCommonV1.OpPermissionItem, 0, len(permissions)) for _, p := range permissions { diff --git a/pkg/dms-common/api/dms/v1/user.go b/pkg/dms-common/api/dms/v1/user.go index 6a9d1a6a..7cdb310f 100644 --- a/pkg/dms-common/api/dms/v1/user.go +++ b/pkg/dms-common/api/dms/v1/user.go @@ -108,7 +108,7 @@ type GetUserOpPermissionReq struct { type UserOpPermission struct { // uesr project uid - ProjectUid string `json:"project_uid" validate:"required"` + ProjectUid string `json:"project_uid"` } // swagger:model GetUserOpPermissionReply From 033d7a6d88f0027ed72774813061a0a18b2d1e7d Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Fri, 18 Oct 2024 13:57:54 +0800 Subject: [PATCH 2/2] docs: supplement the missing swagger --- api/swagger.json | 14 ++++++++++++++ api/swagger.yaml | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/api/swagger.json b/api/swagger.json index fdd20277..92e76152 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -1417,6 +1417,20 @@ "description": "filter project by project id list, using in condition", "name": "filter_by_project_uids", "in": "query" + }, + { + "enum": [ + "high", + "medium", + "low", + "unknown" + ], + "type": "string", + "x-go-enum-desc": "high ProjectPriorityHigh\nmedium ProjectPriorityMedium\nlow ProjectPriorityLow\nunknown ProjectPriorityUnknown", + "x-go-name": "FilterByProjectPriority", + "description": "filter project by project priority\nhigh ProjectPriorityHigh\nmedium ProjectPriorityMedium\nlow ProjectPriorityLow\nunknown ProjectPriorityUnknown", + "name": "filter_by_project_priority", + "in": "query" } ], "responses": { diff --git a/api/swagger.yaml b/api/swagger.yaml index 32f2b4c6..ca16a3c2 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -5572,6 +5572,26 @@ paths: name: filter_by_project_uids type: array x-go-name: FilterByProjectUids + - description: |- + filter project by project priority + high ProjectPriorityHigh + medium ProjectPriorityMedium + low ProjectPriorityLow + unknown ProjectPriorityUnknown + enum: + - high + - medium + - low + - unknown + in: query + name: filter_by_project_priority + type: string + x-go-enum-desc: |- + high ProjectPriorityHigh + medium ProjectPriorityMedium + low ProjectPriorityLow + unknown ProjectPriorityUnknown + x-go-name: FilterByProjectPriority responses: "200": description: ListProjectReply