Skip to content

Commit 8e3fc8d

Browse files
authored
Allow searching for users with all roles in a tenant (#596)
1 parent 51d2100 commit 8e3fc8d

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

descope/internal/mgmt/user.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ import (
1010
"github.com/descope/go-sdk/descope/sdk"
1111
)
1212

13-
func mapToValuesObject(inputMap map[string][]string) map[string]map[string][]string {
14-
if len(inputMap) == 0 {
15-
return nil
16-
}
17-
result := make(map[string]map[string][]string)
18-
for k, v := range inputMap {
19-
result[k] = map[string][]string{
20-
"values": v,
21-
}
22-
}
23-
return result
24-
}
25-
2613
type user struct {
2714
managementBase
2815
}
@@ -988,8 +975,8 @@ func makeSearchAllRequest(options *descope.UserSearchOptions) map[string]any {
988975
"fromModifiedTime": options.FromModifiedTime,
989976
"toModifiedTime": options.ToModifiedTime,
990977
"userIds": options.UserIDs,
991-
"tenantRoleIds": mapToValuesObject(options.TenantRoleIDs),
992-
"tenantRoleNames": mapToValuesObject(options.TenantRoleNames),
978+
"tenantRoleIds": options.TenantRoleIDs,
979+
"tenantRoleNames": options.TenantRoleNames,
993980
}
994981
}
995982

descope/internal/mgmt/user_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ func TestSearchAllUsersSuccess(t *testing.T) {
776776
{Field: "nono", Desc: true},
777777
{Field: "lolo", Desc: false},
778778
},
779-
TenantRoleIDs: map[string][]string{"tenant1": {"id1", "id2"}},
780-
TenantRoleNames: map[string][]string{"tenant2": {"name1", "name2"}},
779+
TenantRoleIDs: map[string]*descope.RoleList{"tenant1": {Values: []string{"id1", "id2"}}},
780+
TenantRoleNames: map[string]*descope.RoleList{"tenant2": {Values: []string{"name1", "name2"}}},
781781
})
782782
require.NoError(t, err)
783783
require.NotNil(t, res)
@@ -808,8 +808,8 @@ func TestSearchAllTestUsersSuccess(t *testing.T) {
808808
}, response))
809809
res, _, err := m.User().SearchAllTestUsers(context.Background(), &descope.UserSearchOptions{
810810
Emails: []string{"[email protected]"},
811-
TenantRoleIDs: map[string][]string{"tenant1": {"id1", "id2"}},
812-
TenantRoleNames: map[string][]string{"tenant2": {"name1", "name2"}},
811+
TenantRoleIDs: map[string]*descope.RoleList{"tenant1": {Values: []string{"id1", "id2"}}},
812+
TenantRoleNames: map[string]*descope.RoleList{"tenant2": {Values: []string{"name1", "name2"}}},
813813
})
814814
require.NoError(t, err)
815815
require.NotNil(t, res)

descope/types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,20 @@ type UserSearchOptions struct {
879879
ToCreatedTime int64
880880
FromModifiedTime int64
881881
ToModifiedTime int64
882-
TenantRoleIDs map[string][]string
883-
TenantRoleNames map[string][]string
882+
TenantRoleIDs map[string]*RoleList
883+
TenantRoleNames map[string]*RoleList
884884
}
885885

886886
type UserSearchSort struct {
887887
Field string
888888
Desc bool
889889
}
890890

891+
type RoleList struct {
892+
Values []string `json:"values,omitempty"`
893+
And bool `json:"and,omitempty"`
894+
}
895+
891896
type UserStatus string
892897

893898
const (

0 commit comments

Comments
 (0)