Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5707,6 +5707,58 @@
"description": "fuzzy keyword",
"name": "fuzzy_keyword",
"in": "query"
},
{
"type": "string",
"x-go-name": "FilterByEmail",
"description": "filter the user email",
"name": "filter_by_email",
"in": "query"
},
{
"type": "string",
"x-go-name": "FilterByPhone",
"description": "filter the user phone",
"name": "filter_by_phone",
"in": "query"
},
{
"enum": [
"Normal",
"Disabled"
],
"type": "string",
"x-go-enum-desc": "Normal UserStatFilterNormal\nDisabled UserStatFilterDisabled",
"x-go-name": "FilterByStat",
"description": "filter the user stat (0: normal, 1: disabled)\nNormal UserStatFilterNormal\nDisabled UserStatFilterDisabled",
"name": "filter_by_stat",
"in": "query"
},
{
"enum": [
"ldap",
"dms",
"oauth2",
"unknown"
],
"type": "string",
"x-go-enum-desc": "ldap UserAuthenticationTypeLDAP\ndms UserAuthenticationTypeDMS\noauth2 UserAuthenticationTypeOAUTH2\nunknown UserAuthenticationTypeUnknown",
"x-go-name": "FilterByAuthenticationType",
"description": "filter the user authentication type (ldap, dms, oauth2)\nldap UserAuthenticationTypeLDAP\ndms UserAuthenticationTypeDMS\noauth2 UserAuthenticationTypeOAUTH2\nunknown UserAuthenticationTypeUnknown",
"name": "filter_by_authentication_type",
"in": "query"
},
{
"enum": [
"WORKBENCH",
"MANAGEMENT"
],
"type": "string",
"x-go-enum-desc": "WORKBENCH UserSystemWorkbench\nMANAGEMENT UserSystemManagement",
"x-go-name": "FilterBySystem",
"description": "filter the user system (WORKBENCH, MANAGEMENT)\nWORKBENCH UserSystemWorkbench\nMANAGEMENT UserSystemManagement",
"name": "filter_by_system",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -9257,7 +9309,7 @@
"x-go-name": "Users"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"GetMemberGroupReply": {
"type": "object",
Expand All @@ -9277,7 +9329,7 @@
"x-go-name": "Message"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"GetOauth2ConfigurationResData": {
"type": "object",
Expand Down Expand Up @@ -11813,6 +11865,17 @@
"ListMemberRoleWithOpRange": {
"type": "object",
"properties": {
"member_group": {
"$ref": "#/definitions/ProjectMemberGroup"
},
"op_permissions": {
"description": "member op permissions",
"type": "array",
"items": {
"$ref": "#/definitions/UidWithName"
},
"x-go-name": "OpPermissions"
},
"op_range_type": {
"description": "op permission range type, only support db service now\nunknown OpRangeTypeUnknown\nglobal OpRangeTypeGlobal 全局权限: 该权限只能被用户使用\nproject OpRangeTypeProject 项目权限: 该权限只能被成员使用\ndb_service OpRangeTypeDBService 项目内的数据源权限: 该权限只能被成员使用",
"type": "string",
Expand All @@ -11837,7 +11900,7 @@
"$ref": "#/definitions/UidWithName"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"ListMemberTipsItem": {
"type": "object",
Expand Down
72 changes: 69 additions & 3 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ definitions:
type: array
x-go-name: Users
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
x-go-package: github.com/actiontech/dms/api/dms/service/v1
GetMemberGroupReply:
properties:
code:
Expand All @@ -1875,7 +1875,7 @@ definitions:
type: string
x-go-name: Message
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
x-go-package: github.com/actiontech/dms/api/dms/service/v1
GetOauth2ConfigurationResData:
properties:
access_token_tag:
Expand Down Expand Up @@ -3877,6 +3877,14 @@ definitions:
x-go-package: github.com/actiontech/dms/api/dms/service/v1
ListMemberRoleWithOpRange:
properties:
member_group:
$ref: '#/definitions/ProjectMemberGroup'
op_permissions:
description: member op permissions
items:
$ref: '#/definitions/UidWithName'
type: array
x-go-name: OpPermissions
op_range_type:
description: |-
op permission range type, only support db service now
Expand Down Expand Up @@ -3905,7 +3913,7 @@ definitions:
role_uid:
$ref: '#/definitions/UidWithName'
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
x-go-package: github.com/actiontech/dms/api/dms/service/v1
ListMemberTipsItem:
properties:
user_id:
Expand Down Expand Up @@ -10812,6 +10820,64 @@ paths:
name: fuzzy_keyword
type: string
x-go-name: FuzzyKeyword
- description: filter the user email
in: query
name: filter_by_email
type: string
x-go-name: FilterByEmail
- description: filter the user phone
in: query
name: filter_by_phone
type: string
x-go-name: FilterByPhone
- description: |-
filter the user stat (0: normal, 1: disabled)
Normal UserStatFilterNormal
Disabled UserStatFilterDisabled
enum:
- Normal
- Disabled
in: query
name: filter_by_stat
type: string
x-go-enum-desc: |-
Normal UserStatFilterNormal
Disabled UserStatFilterDisabled
x-go-name: FilterByStat
- description: |-
filter the user authentication type (ldap, dms, oauth2)
ldap UserAuthenticationTypeLDAP
dms UserAuthenticationTypeDMS
oauth2 UserAuthenticationTypeOAUTH2
unknown UserAuthenticationTypeUnknown
enum:
- ldap
- dms
- oauth2
- unknown
in: query
name: filter_by_authentication_type
type: string
x-go-enum-desc: |-
ldap UserAuthenticationTypeLDAP
dms UserAuthenticationTypeDMS
oauth2 UserAuthenticationTypeOAUTH2
unknown UserAuthenticationTypeUnknown
x-go-name: FilterByAuthenticationType
- description: |-
filter the user system (WORKBENCH, MANAGEMENT)
WORKBENCH UserSystemWorkbench
MANAGEMENT UserSystemManagement
enum:
- WORKBENCH
- MANAGEMENT
in: query
name: filter_by_system
type: string
x-go-enum-desc: |-
WORKBENCH UserSystemWorkbench
MANAGEMENT UserSystemManagement
x-go-name: FilterBySystem
responses:
"200":
description: ListUserReply
Expand Down
70 changes: 70 additions & 0 deletions internal/dms/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,61 @@ func (d *DMSService) ListUsers(ctx context.Context, req *dmsCommonV1.ListUserReq
})
}

// 按邮箱过滤
if req.FilterByEmail != "" {
andConditions = append(andConditions, pkgConst.FilterCondition{
Field: string(biz.UserFieldEmail),
Operator: pkgConst.FilterOperatorContains,
Value: req.FilterByEmail,
})
}

// 按手机号过滤
if req.FilterByPhone != "" {
andConditions = append(andConditions, pkgConst.FilterCondition{
Field: string(biz.UserFieldPhone),
Operator: pkgConst.FilterOperatorContains,
Value: req.FilterByPhone,
})
}

// 按用户状态过滤
if req.FilterByStat != "" {
// 将字符串枚举转换为 uint
var statValue uint
switch req.FilterByStat {
case dmsCommonV1.UserStatFilterNormal:
statValue = 0
case dmsCommonV1.UserStatFilterDisabled:
statValue = 1
default:
return nil, fmt.Errorf("invalid user stat filter: %s", req.FilterByStat)
}
andConditions = append(andConditions, pkgConst.FilterCondition{
Field: string(biz.UserFieldStat),
Operator: pkgConst.FilterOperatorEqual,
Value: statValue,
})
}

// 按认证类型过滤
if req.FilterByAuthenticationType != "" {
andConditions = append(andConditions, pkgConst.FilterCondition{
Field: string(biz.UserFieldUserAuthenticationType),
Operator: pkgConst.FilterOperatorEqual,
Value: string(req.FilterByAuthenticationType),
})
}

// 按用户系统过滤
if req.FilterBySystem != "" {
andConditions = append(andConditions, pkgConst.FilterCondition{
Field: "system",
Operator: pkgConst.FilterOperatorEqual,
Value: string(req.FilterBySystem),
})
}

if len(andConditions) > 0 {
filterByOptions.Groups = append(filterByOptions.Groups, pkgConst.NewConditionGroup(pkgConst.FilterLogicAnd, andConditions...))
}
Expand All @@ -222,6 +277,21 @@ func (d *DMSService) ListUsers(ctx context.Context, req *dmsCommonV1.ListUserReq
Operator: pkgConst.FilterOperatorContains,
Value: req.FuzzyKeyword,
},
pkgConst.FilterCondition{
Field: string(biz.UserFieldUID),
Operator: pkgConst.FilterOperatorContains,
Value: req.FuzzyKeyword,
},
pkgConst.FilterCondition{
Field: string(biz.UserFieldEmail),
Operator: pkgConst.FilterOperatorContains,
Value: req.FuzzyKeyword,
},
pkgConst.FilterCondition{
Field: string(biz.UserFieldPhone),
Operator: pkgConst.FilterOperatorContains,
Value: req.FuzzyKeyword,
},
))
}

Expand Down
25 changes: 25 additions & 0 deletions pkg/dms-common/api/dms/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ const (
UserSystemManagement UserSystem = "MANAGEMENT"
)

// swagger:enum UserStatFilter
type UserStatFilter string

const (
UserStatFilterNormal UserStatFilter = "Normal" // normal
UserStatFilterDisabled UserStatFilter = "Disabled" // disabled
)

// swagger:model GetUserReply
type GetUserReply struct {
// Get user reply
Expand Down Expand Up @@ -389,7 +397,24 @@ type ListUserReq struct {
FilterDeletedUser bool `query:"filter_del_user" json:"filter_del_user"`
// fuzzy keyword
// in:query
// fuzzy keyword, search in name, uid, email, phone fields (OR relationship)
// in:query
FuzzyKeyword string `query:"fuzzy_keyword" json:"fuzzy_keyword"`
// filter the user email
// in:query
FilterByEmail string `query:"filter_by_email" json:"filter_by_email"`
// filter the user phone
// in:query
FilterByPhone string `query:"filter_by_phone" json:"filter_by_phone"`
// filter the user stat (0: normal, 1: disabled)
// in:query
FilterByStat UserStatFilter `query:"filter_by_stat" json:"filter_by_stat"`
// filter the user authentication type (ldap, dms, oauth2)
// in:query
FilterByAuthenticationType UserAuthenticationType `query:"filter_by_authentication_type" json:"filter_by_authentication_type"`
// filter the user system (WORKBENCH, MANAGEMENT)
// in:query
FilterBySystem UserSystem `query:"filter_by_system" json:"filter_by_system"`
}

// swagger:enum UserOrderByField
Expand Down
45 changes: 42 additions & 3 deletions pkg/dms-common/dmsobject/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dmsobject
import (
"context"
"fmt"
"net/url"
"strconv"

dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
pkgHttp "github.com/actiontech/dms/pkg/dms-common/pkg/http"
Expand Down Expand Up @@ -98,10 +100,47 @@ func ListUsers(ctx context.Context, dmsAddr string, req dmsV1.ListUserReq) (ret

reply := &dmsV1.ListUserReply{}

url := fmt.Sprintf("%v%v?page_size=%v&page_index=%v&filter_del_user=%v&filter_by_uids=%v", dmsAddr, dmsV1.GetUsersRouter(), req.PageSize, req.PageIndex, req.FilterDeletedUser, req.FilterByUids)
// 构建查询参数
params := url.Values{}
params.Set("page_size", strconv.FormatUint(uint64(req.PageSize), 10))
if req.PageIndex > 0 {
params.Set("page_index", strconv.FormatUint(uint64(req.PageIndex), 10))
}
if req.OrderBy != "" {
params.Set("order_by", string(req.OrderBy))
}
if req.FilterByName != "" {
params.Set("filter_by_name", req.FilterByName)
}
if req.FilterByUids != "" {
params.Set("filter_by_uids", req.FilterByUids)
}
if req.FilterDeletedUser {
params.Set("filter_del_user", "true")
}
if req.FuzzyKeyword != "" {
params.Set("fuzzy_keyword", req.FuzzyKeyword)
}
if req.FilterByEmail != "" {
params.Set("filter_by_email", req.FilterByEmail)
}
if req.FilterByPhone != "" {
params.Set("filter_by_phone", req.FilterByPhone)
}
if req.FilterByStat != "" {
params.Set("filter_by_stat", string(req.FilterByStat))
}
if req.FilterByAuthenticationType != "" {
params.Set("filter_by_authentication_type", string(req.FilterByAuthenticationType))
}
if req.FilterBySystem != "" {
params.Set("filter_by_system", string(req.FilterBySystem))
}

if err := pkgHttp.Get(ctx, url, header, nil, reply); err != nil {
return nil, 0, fmt.Errorf("failed to list users from %v: %v", url, err)
requestURL := fmt.Sprintf("%v%v?%v", dmsAddr, dmsV1.GetUsersRouter(), params.Encode())

if err := pkgHttp.Get(ctx, requestURL, header, nil, reply); err != nil {
return nil, 0, fmt.Errorf("failed to list users from %v: %v", requestURL, err)
}
if reply.Code != 0 {
return nil, 0, fmt.Errorf("http reply code(%v) error: %v", reply.Code, reply.Message)
Expand Down