feat: add nickname for adminUser (#3435)

* feat: add nickname for adminUser

* feat: add nickname for adminUser

* feat: add nickname for adminUser
This commit is contained in:
icey-yu
2025-06-25 11:33:19 +08:00
committed by GitHub
parent 6912ad6f33
commit a5ac7f2a81
16 changed files with 72 additions and 32 deletions
+5 -2
View File
@@ -356,8 +356,11 @@ type AfterConfig struct {
}
type Share struct {
Secret string `yaml:"secret"`
IMAdminUserID []string `yaml:"imAdminUserID"`
Secret string `yaml:"secret"`
IMAdminUser struct {
UserIDs []string `yaml:"userIDs"`
Nicknames []string `yaml:"nicknames"`
} `yaml:"imAdminUser"`
MultiLogin MultiLogin `yaml:"multiLogin"`
RPCMaxBodySize MaxRequestBody `yaml:"rpcMaxBodySize"`
}
+2 -2
View File
@@ -69,8 +69,8 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
grpcsrv.GrpcServerRequestValidate(),
grpcsrv.GrpcServerPanicCapture(),
)
if shareConfig != nil && len(shareConfig.IMAdminUserID) > 0 {
options = append(options, grpcServerIMAdminUserID(shareConfig.IMAdminUserID))
if shareConfig != nil && len(shareConfig.IMAdminUser.UserIDs) > 0 {
options = append(options, grpcServerIMAdminUserID(shareConfig.IMAdminUser.UserIDs))
}
var clientOptions []grpc.DialOption
if maxRequestBody != nil {
+21 -3
View File
@@ -97,16 +97,34 @@ func (u *userDatabase) InitOnce(ctx context.Context, users []*model.User) error
}
// Determine which users are missing from the database.
missingUsers := datautil.SliceAnySub(users, existingUsers, func(e *model.User) string {
var (
missing, update []*model.User
)
existMap := datautil.SliceToMap(existingUsers, func(e *model.User) string {
return e.UserID
})
orgMap := datautil.SliceToMap(users, func(e *model.User) string { return e.UserID })
for k, u1 := range orgMap {
if u2, ok := existMap[k]; !ok {
missing = append(missing, u1)
} else if u1.Nickname != u2.Nickname {
update = append(update, u1)
}
}
// Create records for missing users.
if len(missingUsers) > 0 {
if err := u.userDB.Create(ctx, missingUsers); err != nil {
if len(missing) > 0 {
if err := u.userDB.Create(ctx, missing); err != nil {
return err
}
}
if len(update) > 0 {
for i := range update {
if err := u.userDB.UpdateByMap(ctx, update[i].UserID, map[string]any{"nickname": update[i].Nickname}); err != nil {
return err
}
}
}
return nil
}