Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chat admin config #508

Merged
merged 1 commit into from
Apr 24, 2024
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
4 changes: 1 addition & 3 deletions config/share.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ openIM:
adminUserID: imAdmin

chatAdmin:
- adminID: chatAdmin
imUserID: imAdmin
nickname: chatAdmin
- "chatAdmin"

#proxyHeader: "X-Forwarded-For"
2 changes: 1 addition & 1 deletion internal/api/admin/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Start(ctx context.Context, index int, config *Config) error {
base := util.Api{
ImUserID: config.Share.OpenIM.AdminUserID,
ProxyHeader: config.Share.ProxyHeader,
ChatAdminUserID: config.Share.ChatAdmin[0].AdminID,
ChatAdminUserID: config.Share.ChatAdmin[0],
}
adminApi := New(chatClient, adminClient, im, &base)
mwApi := chatmw.New(adminClient)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/chat/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Start(ctx context.Context, index int, config *Config) error {
base := util.Api{
ImUserID: config.Share.OpenIM.AdminUserID,
ProxyHeader: config.Share.ProxyHeader,
ChatAdminUserID: config.Share.ChatAdmin[0].AdminID,
ChatAdminUserID: config.Share.ChatAdmin[0],
}
adminApi := New(chatClient, adminClient, im, &base)
mwApi := chatmw.New(adminClient)
Expand Down
14 changes: 7 additions & 7 deletions internal/rpc/admin/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
Expires: time.Duration(config.RpcConfig.TokenPolicy.Expire) * time.Hour * 24,
Secret: config.RpcConfig.Secret,
}
if err := srv.initAdmin(ctx, config.Share.ChatAdmin); err != nil {
if err := srv.initAdmin(ctx, config.Share.ChatAdmin, config.Share.OpenIM.AdminUserID); err != nil {
return err
}
pbadmin.RegisterAdminServer(server, &srv)
Expand All @@ -72,17 +72,17 @@ type adminServer struct {
Token *tokenverify.Token
}

func (o *adminServer) initAdmin(ctx context.Context, users []config.AdminUser) error {
for _, user := range users {
if _, err := o.Database.GetAdmin(ctx, user.AdminID); err == nil {
func (o *adminServer) initAdmin(ctx context.Context, admins []string, imUserID string) error {
for _, account := range admins {
if _, err := o.Database.GetAdmin(ctx, account); err == nil {
continue
} else if !dbutil.IsDBNotFound(err) {
return err
}
sum := md5.Sum([]byte(user.AdminID))
sum := md5.Sum([]byte(account))
a := admin.Admin{
Account: user.AdminID,
UserID: user.IMUserID,
Account: account,
UserID: imUserID,
Password: hex.EncodeToString(sum[:]),
Level: constant.DefaultAdminLevel,
CreateTime: time.Now(),
Expand Down
10 changes: 2 additions & 8 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ type Share struct {
Secret string `mapstructure:"secret"`
AdminUserID string `mapstructure:"adminUserID"`
} `mapstructure:"openIM"`
ChatAdmin []AdminUser `mapstructure:"chatAdmin"`
ProxyHeader string `mapstructure:"proxyHeader"`
}

type AdminUser struct {
AdminID string `mapstructure:"adminID"`
IMUserID string `mapstructure:"imUserID"`
Nickname string `mapstructure:"nickname"`
ChatAdmin []string `mapstructure:"chatAdmin"`
ProxyHeader string `mapstructure:"proxyHeader"`
}

type RpcRegisterName struct {
Expand Down
Loading