Skip to content

Commit da2c9ca

Browse files
authored
Merge pull request #583 from actiontech/support-564
Support 564
2 parents 00caf7a + 303ef85 commit da2c9ca

5 files changed

Lines changed: 272 additions & 9 deletions

File tree

api/swagger.json

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5707,6 +5707,58 @@
57075707
"description": "fuzzy keyword",
57085708
"name": "fuzzy_keyword",
57095709
"in": "query"
5710+
},
5711+
{
5712+
"type": "string",
5713+
"x-go-name": "FilterByEmail",
5714+
"description": "filter the user email",
5715+
"name": "filter_by_email",
5716+
"in": "query"
5717+
},
5718+
{
5719+
"type": "string",
5720+
"x-go-name": "FilterByPhone",
5721+
"description": "filter the user phone",
5722+
"name": "filter_by_phone",
5723+
"in": "query"
5724+
},
5725+
{
5726+
"enum": [
5727+
"Normal",
5728+
"Disabled"
5729+
],
5730+
"type": "string",
5731+
"x-go-enum-desc": "Normal UserStatFilterNormal\nDisabled UserStatFilterDisabled",
5732+
"x-go-name": "FilterByStat",
5733+
"description": "filter the user stat (0: normal, 1: disabled)\nNormal UserStatFilterNormal\nDisabled UserStatFilterDisabled",
5734+
"name": "filter_by_stat",
5735+
"in": "query"
5736+
},
5737+
{
5738+
"enum": [
5739+
"ldap",
5740+
"dms",
5741+
"oauth2",
5742+
"unknown"
5743+
],
5744+
"type": "string",
5745+
"x-go-enum-desc": "ldap UserAuthenticationTypeLDAP\ndms UserAuthenticationTypeDMS\noauth2 UserAuthenticationTypeOAUTH2\nunknown UserAuthenticationTypeUnknown",
5746+
"x-go-name": "FilterByAuthenticationType",
5747+
"description": "filter the user authentication type (ldap, dms, oauth2)\nldap UserAuthenticationTypeLDAP\ndms UserAuthenticationTypeDMS\noauth2 UserAuthenticationTypeOAUTH2\nunknown UserAuthenticationTypeUnknown",
5748+
"name": "filter_by_authentication_type",
5749+
"in": "query"
5750+
},
5751+
{
5752+
"enum": [
5753+
"WORKBENCH",
5754+
"MANAGEMENT"
5755+
],
5756+
"type": "string",
5757+
"x-go-enum-desc": "WORKBENCH UserSystemWorkbench\nMANAGEMENT UserSystemManagement",
5758+
"x-go-name": "FilterBySystem",
5759+
"description": "filter the user system (WORKBENCH, MANAGEMENT)\nWORKBENCH UserSystemWorkbench\nMANAGEMENT UserSystemManagement",
5760+
"name": "filter_by_system",
5761+
"in": "query"
57105762
}
57115763
],
57125764
"responses": {
@@ -9257,7 +9309,7 @@
92579309
"x-go-name": "Users"
92589310
}
92599311
},
9260-
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
9312+
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
92619313
},
92629314
"GetMemberGroupReply": {
92639315
"type": "object",
@@ -9277,7 +9329,7 @@
92779329
"x-go-name": "Message"
92789330
}
92799331
},
9280-
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
9332+
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
92819333
},
92829334
"GetOauth2ConfigurationResData": {
92839335
"type": "object",
@@ -11813,6 +11865,17 @@
1181311865
"ListMemberRoleWithOpRange": {
1181411866
"type": "object",
1181511867
"properties": {
11868+
"member_group": {
11869+
"$ref": "#/definitions/ProjectMemberGroup"
11870+
},
11871+
"op_permissions": {
11872+
"description": "member op permissions",
11873+
"type": "array",
11874+
"items": {
11875+
"$ref": "#/definitions/UidWithName"
11876+
},
11877+
"x-go-name": "OpPermissions"
11878+
},
1181611879
"op_range_type": {
1181711880
"description": "op permission range type, only support db service now\nunknown OpRangeTypeUnknown\nglobal OpRangeTypeGlobal 全局权限: 该权限只能被用户使用\nproject OpRangeTypeProject 项目权限: 该权限只能被成员使用\ndb_service OpRangeTypeDBService 项目内的数据源权限: 该权限只能被成员使用",
1181811881
"type": "string",
@@ -11837,7 +11900,7 @@
1183711900
"$ref": "#/definitions/UidWithName"
1183811901
}
1183911902
},
11840-
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
11903+
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
1184111904
},
1184211905
"ListMemberTipsItem": {
1184311906
"type": "object",

api/swagger.yaml

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ definitions:
18601860
type: array
18611861
x-go-name: Users
18621862
type: object
1863-
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
1863+
x-go-package: github.com/actiontech/dms/api/dms/service/v1
18641864
GetMemberGroupReply:
18651865
properties:
18661866
code:
@@ -1875,7 +1875,7 @@ definitions:
18751875
type: string
18761876
x-go-name: Message
18771877
type: object
1878-
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
1878+
x-go-package: github.com/actiontech/dms/api/dms/service/v1
18791879
GetOauth2ConfigurationResData:
18801880
properties:
18811881
access_token_tag:
@@ -3877,6 +3877,14 @@ definitions:
38773877
x-go-package: github.com/actiontech/dms/api/dms/service/v1
38783878
ListMemberRoleWithOpRange:
38793879
properties:
3880+
member_group:
3881+
$ref: '#/definitions/ProjectMemberGroup'
3882+
op_permissions:
3883+
description: member op permissions
3884+
items:
3885+
$ref: '#/definitions/UidWithName'
3886+
type: array
3887+
x-go-name: OpPermissions
38803888
op_range_type:
38813889
description: |-
38823890
op permission range type, only support db service now
@@ -3905,7 +3913,7 @@ definitions:
39053913
role_uid:
39063914
$ref: '#/definitions/UidWithName'
39073915
type: object
3908-
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
3916+
x-go-package: github.com/actiontech/dms/api/dms/service/v1
39093917
ListMemberTipsItem:
39103918
properties:
39113919
user_id:
@@ -10812,6 +10820,64 @@ paths:
1081210820
name: fuzzy_keyword
1081310821
type: string
1081410822
x-go-name: FuzzyKeyword
10823+
- description: filter the user email
10824+
in: query
10825+
name: filter_by_email
10826+
type: string
10827+
x-go-name: FilterByEmail
10828+
- description: filter the user phone
10829+
in: query
10830+
name: filter_by_phone
10831+
type: string
10832+
x-go-name: FilterByPhone
10833+
- description: |-
10834+
filter the user stat (0: normal, 1: disabled)
10835+
Normal UserStatFilterNormal
10836+
Disabled UserStatFilterDisabled
10837+
enum:
10838+
- Normal
10839+
- Disabled
10840+
in: query
10841+
name: filter_by_stat
10842+
type: string
10843+
x-go-enum-desc: |-
10844+
Normal UserStatFilterNormal
10845+
Disabled UserStatFilterDisabled
10846+
x-go-name: FilterByStat
10847+
- description: |-
10848+
filter the user authentication type (ldap, dms, oauth2)
10849+
ldap UserAuthenticationTypeLDAP
10850+
dms UserAuthenticationTypeDMS
10851+
oauth2 UserAuthenticationTypeOAUTH2
10852+
unknown UserAuthenticationTypeUnknown
10853+
enum:
10854+
- ldap
10855+
- dms
10856+
- oauth2
10857+
- unknown
10858+
in: query
10859+
name: filter_by_authentication_type
10860+
type: string
10861+
x-go-enum-desc: |-
10862+
ldap UserAuthenticationTypeLDAP
10863+
dms UserAuthenticationTypeDMS
10864+
oauth2 UserAuthenticationTypeOAUTH2
10865+
unknown UserAuthenticationTypeUnknown
10866+
x-go-name: FilterByAuthenticationType
10867+
- description: |-
10868+
filter the user system (WORKBENCH, MANAGEMENT)
10869+
WORKBENCH UserSystemWorkbench
10870+
MANAGEMENT UserSystemManagement
10871+
enum:
10872+
- WORKBENCH
10873+
- MANAGEMENT
10874+
in: query
10875+
name: filter_by_system
10876+
type: string
10877+
x-go-enum-desc: |-
10878+
WORKBENCH UserSystemWorkbench
10879+
MANAGEMENT UserSystemManagement
10880+
x-go-name: FilterBySystem
1081510881
responses:
1081610882
"200":
1081710883
description: ListUserReply

internal/dms/service/user.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,61 @@ func (d *DMSService) ListUsers(ctx context.Context, req *dmsCommonV1.ListUserReq
209209
})
210210
}
211211

212+
// 按邮箱过滤
213+
if req.FilterByEmail != "" {
214+
andConditions = append(andConditions, pkgConst.FilterCondition{
215+
Field: string(biz.UserFieldEmail),
216+
Operator: pkgConst.FilterOperatorContains,
217+
Value: req.FilterByEmail,
218+
})
219+
}
220+
221+
// 按手机号过滤
222+
if req.FilterByPhone != "" {
223+
andConditions = append(andConditions, pkgConst.FilterCondition{
224+
Field: string(biz.UserFieldPhone),
225+
Operator: pkgConst.FilterOperatorContains,
226+
Value: req.FilterByPhone,
227+
})
228+
}
229+
230+
// 按用户状态过滤
231+
if req.FilterByStat != "" {
232+
// 将字符串枚举转换为 uint
233+
var statValue uint
234+
switch req.FilterByStat {
235+
case dmsCommonV1.UserStatFilterNormal:
236+
statValue = 0
237+
case dmsCommonV1.UserStatFilterDisabled:
238+
statValue = 1
239+
default:
240+
return nil, fmt.Errorf("invalid user stat filter: %s", req.FilterByStat)
241+
}
242+
andConditions = append(andConditions, pkgConst.FilterCondition{
243+
Field: string(biz.UserFieldStat),
244+
Operator: pkgConst.FilterOperatorEqual,
245+
Value: statValue,
246+
})
247+
}
248+
249+
// 按认证类型过滤
250+
if req.FilterByAuthenticationType != "" {
251+
andConditions = append(andConditions, pkgConst.FilterCondition{
252+
Field: string(biz.UserFieldUserAuthenticationType),
253+
Operator: pkgConst.FilterOperatorEqual,
254+
Value: string(req.FilterByAuthenticationType),
255+
})
256+
}
257+
258+
// 按用户系统过滤
259+
if req.FilterBySystem != "" {
260+
andConditions = append(andConditions, pkgConst.FilterCondition{
261+
Field: "system",
262+
Operator: pkgConst.FilterOperatorEqual,
263+
Value: string(req.FilterBySystem),
264+
})
265+
}
266+
212267
if len(andConditions) > 0 {
213268
filterByOptions.Groups = append(filterByOptions.Groups, pkgConst.NewConditionGroup(pkgConst.FilterLogicAnd, andConditions...))
214269
}
@@ -222,6 +277,21 @@ func (d *DMSService) ListUsers(ctx context.Context, req *dmsCommonV1.ListUserReq
222277
Operator: pkgConst.FilterOperatorContains,
223278
Value: req.FuzzyKeyword,
224279
},
280+
pkgConst.FilterCondition{
281+
Field: string(biz.UserFieldUID),
282+
Operator: pkgConst.FilterOperatorContains,
283+
Value: req.FuzzyKeyword,
284+
},
285+
pkgConst.FilterCondition{
286+
Field: string(biz.UserFieldEmail),
287+
Operator: pkgConst.FilterOperatorContains,
288+
Value: req.FuzzyKeyword,
289+
},
290+
pkgConst.FilterCondition{
291+
Field: string(biz.UserFieldPhone),
292+
Operator: pkgConst.FilterOperatorContains,
293+
Value: req.FuzzyKeyword,
294+
},
225295
))
226296
}
227297

pkg/dms-common/api/dms/v1/user.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ const (
9595
UserSystemManagement UserSystem = "MANAGEMENT"
9696
)
9797

98+
// swagger:enum UserStatFilter
99+
type UserStatFilter string
100+
101+
const (
102+
UserStatFilterNormal UserStatFilter = "Normal" // normal
103+
UserStatFilterDisabled UserStatFilter = "Disabled" // disabled
104+
)
105+
98106
// swagger:model GetUserReply
99107
type GetUserReply struct {
100108
// Get user reply
@@ -389,7 +397,24 @@ type ListUserReq struct {
389397
FilterDeletedUser bool `query:"filter_del_user" json:"filter_del_user"`
390398
// fuzzy keyword
391399
// in:query
400+
// fuzzy keyword, search in name, uid, email, phone fields (OR relationship)
401+
// in:query
392402
FuzzyKeyword string `query:"fuzzy_keyword" json:"fuzzy_keyword"`
403+
// filter the user email
404+
// in:query
405+
FilterByEmail string `query:"filter_by_email" json:"filter_by_email"`
406+
// filter the user phone
407+
// in:query
408+
FilterByPhone string `query:"filter_by_phone" json:"filter_by_phone"`
409+
// filter the user stat (0: normal, 1: disabled)
410+
// in:query
411+
FilterByStat UserStatFilter `query:"filter_by_stat" json:"filter_by_stat"`
412+
// filter the user authentication type (ldap, dms, oauth2)
413+
// in:query
414+
FilterByAuthenticationType UserAuthenticationType `query:"filter_by_authentication_type" json:"filter_by_authentication_type"`
415+
// filter the user system (WORKBENCH, MANAGEMENT)
416+
// in:query
417+
FilterBySystem UserSystem `query:"filter_by_system" json:"filter_by_system"`
393418
}
394419

395420
// swagger:enum UserOrderByField

pkg/dms-common/dmsobject/user.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dmsobject
33
import (
44
"context"
55
"fmt"
6+
"net/url"
7+
"strconv"
68

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

99101
reply := &dmsV1.ListUserReply{}
100102

101-
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)
103+
// 构建查询参数
104+
params := url.Values{}
105+
params.Set("page_size", strconv.FormatUint(uint64(req.PageSize), 10))
106+
if req.PageIndex > 0 {
107+
params.Set("page_index", strconv.FormatUint(uint64(req.PageIndex), 10))
108+
}
109+
if req.OrderBy != "" {
110+
params.Set("order_by", string(req.OrderBy))
111+
}
112+
if req.FilterByName != "" {
113+
params.Set("filter_by_name", req.FilterByName)
114+
}
115+
if req.FilterByUids != "" {
116+
params.Set("filter_by_uids", req.FilterByUids)
117+
}
118+
if req.FilterDeletedUser {
119+
params.Set("filter_del_user", "true")
120+
}
121+
if req.FuzzyKeyword != "" {
122+
params.Set("fuzzy_keyword", req.FuzzyKeyword)
123+
}
124+
if req.FilterByEmail != "" {
125+
params.Set("filter_by_email", req.FilterByEmail)
126+
}
127+
if req.FilterByPhone != "" {
128+
params.Set("filter_by_phone", req.FilterByPhone)
129+
}
130+
if req.FilterByStat != "" {
131+
params.Set("filter_by_stat", string(req.FilterByStat))
132+
}
133+
if req.FilterByAuthenticationType != "" {
134+
params.Set("filter_by_authentication_type", string(req.FilterByAuthenticationType))
135+
}
136+
if req.FilterBySystem != "" {
137+
params.Set("filter_by_system", string(req.FilterBySystem))
138+
}
102139

103-
if err := pkgHttp.Get(ctx, url, header, nil, reply); err != nil {
104-
return nil, 0, fmt.Errorf("failed to list users from %v: %v", url, err)
140+
requestURL := fmt.Sprintf("%v%v?%v", dmsAddr, dmsV1.GetUsersRouter(), params.Encode())
141+
142+
if err := pkgHttp.Get(ctx, requestURL, header, nil, reply); err != nil {
143+
return nil, 0, fmt.Errorf("failed to list users from %v: %v", requestURL, err)
105144
}
106145
if reply.Code != 0 {
107146
return nil, 0, fmt.Errorf("http reply code(%v) error: %v", reply.Code, reply.Message)

0 commit comments

Comments
 (0)