feat(notify): sort the returned contact type array

This commit is contained in:
rainzm
2020-09-14 15:51:46 +08:00
parent acf1f12790
commit 77bbb2cfd0
2 changed files with 20 additions and 1 deletions
+17
View File
@@ -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 {
+3 -1
View File
@@ -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)