mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
feat(notify): sort the returned contact type array
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -164,9 +165,25 @@ func (cm *SConfigManager) PerformGetTypes(ctx context.Context, userCred mcclient
|
||||
output.Types = append(output.Types, ctype)
|
||||
}
|
||||
}
|
||||
output.Types = sortContactType(output.Types)
|
||||
return output, nil
|
||||
}
|
||||
|
||||
var sortedCTypes = []string{
|
||||
api.EMAIL, api.MOBILE, api.DINGTALK, api.FEISHU, api.WORKWX, api.DINGTALK_ROBOT, api.FEISHU_ROBOT, api.WORKWX_ROBOT,
|
||||
}
|
||||
|
||||
func sortContactType(ctypes []string) []string {
|
||||
ctSet := sets.NewString(ctypes...)
|
||||
ret := make([]string, 0, len(ctypes))
|
||||
for _, ct := range sortedCTypes {
|
||||
if ctSet.Has(ct) {
|
||||
ret = append(ret, ct)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *SConfigManager) allContactType() ([]string, error) {
|
||||
q := cm.Query("type")
|
||||
allTypes := make([]struct {
|
||||
|
||||
@@ -568,8 +568,10 @@ func (rm *SReceiverManager) FetchCustomizeColumns(ctx context.Context, userCred
|
||||
rows[i].StatusStandaloneResourceDetails = sRows[i]
|
||||
rows[i].DomainizedResourceInfo = dRows[i]
|
||||
user := objs[i].(*SReceiver)
|
||||
if rows[i].EnabledContactTypes, err = user.GetEnabledContactTypes(); err != nil {
|
||||
if enabledCTs, err := user.GetEnabledContactTypes(); err != nil {
|
||||
log.Errorf("GetEnabledContactTypes: %v", err)
|
||||
} else {
|
||||
rows[i].EnabledContactTypes = sortContactType(enabledCTs)
|
||||
}
|
||||
if rows[i].VerifiedInfos, err = user.getVerifiedInfos(); err != nil {
|
||||
log.Errorf("GetVerifiedContactTypes: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user