69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package sys
|
|
|
|
import (
|
|
"context"
|
|
"hotgo/internal/library/imworkbench"
|
|
"hotgo/internal/model/input/sysin"
|
|
"hotgo/internal/service"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
type sSysImMailboxConfig struct{}
|
|
|
|
func NewSysImMailboxConfig() *sSysImMailboxConfig { return &sSysImMailboxConfig{} }
|
|
|
|
func init() {
|
|
service.RegisterSysImMailboxConfig(NewSysImMailboxConfig())
|
|
}
|
|
|
|
func (s *sSysImMailboxConfig) Get(ctx context.Context, in *sysin.ImMailboxConfigGetInp) (res *sysin.ImMailboxConfigModel, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return
|
|
}
|
|
tenant, err := resolveImAdminTenant(ctx, in.TenantId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res = &sysin.ImMailboxConfigModel{}
|
|
if err = imworkbench.DefaultClient(ctx).GetForTenant(ctx, "/internal/admin/workbench/mailbox-config", nil, tenant.Id, tenant.Code, res); err != nil {
|
|
return nil, err
|
|
}
|
|
if res != nil {
|
|
res.TenantId = tenant.Id
|
|
res.TenantName = tenant.Name
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *sSysImMailboxConfig) Update(ctx context.Context, in *sysin.ImMailboxConfigUpdateInp) (err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return
|
|
}
|
|
tenant, err := resolveImAdminTenant(ctx, in.TenantId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
requiredFields := `["subject","content"]`
|
|
if in.RequiredFields != nil && in.RequiredFields.String() != "" && in.RequiredFields.String() != "null" {
|
|
requiredFields = in.RequiredFields.String()
|
|
}
|
|
attachmentPolicy := `{"max_files":5,"purpose":"executive_mailbox"}`
|
|
if in.AttachmentPolicy != nil && in.AttachmentPolicy.String() != "" && in.AttachmentPolicy.String() != "null" {
|
|
attachmentPolicy = in.AttachmentPolicy.String()
|
|
}
|
|
if err = imworkbench.DefaultClient(ctx).PostForTenant(ctx, "/internal/admin/workbench/mailbox-config", g.Map{
|
|
"enabled": in.Enabled,
|
|
"allow_anonymous": in.AllowAnonymous,
|
|
"required_fields": requiredFields,
|
|
"max_length": in.MaxLength,
|
|
"attachment_policy": attachmentPolicy,
|
|
"notice_title": in.NoticeTitle,
|
|
"notice_content": in.NoticeContent,
|
|
}, tenant.Id, tenant.Code, nil); err != nil {
|
|
return err
|
|
}
|
|
_ = writeImAdminAudit(ctx, tenant.Id, "im_mailbox_config_update", "im_mailbox_config", 1, "success", g.Map{"enabled": in.Enabled})
|
|
return nil
|
|
}
|