fix: Fix the bug introduced by pr #4921

1. The display problem of contact and notification in notify.
2. The display problem of snat's network info.
This commit is contained in:
Rain
2020-02-11 16:49:36 +08:00
parent b463203902
commit 762fcd90cf
5 changed files with 45 additions and 16 deletions
+10 -5
View File
@@ -52,14 +52,19 @@ type NatSEntryDetails struct {
apis.StandaloneResourceDetails
// SNatSEntry
Natgateway string `json:"natgateway"`
RealName string `json:"real_name"`
Network SimpleNetwork `json:"network"`
Natgateway string `json:"natgateway"`
// RealName identifies the local name of SNAT record
RealName string `json:"real_name"`
Network SimpleNetwork `json:"network"`
}
type SimpleNetwork struct {
Id string `json:"id"`
Name string `json:"name"`
Id string `json:"id"`
Name string `json:"name"`
GuestIpStart string `json:"guest_ip_start"`
GuestIpEnd string `json:"guest_ip_end"`
GuestIp6Start string `json:"guest_ip6_start"`
GuestIp6End string `json:"guest_ip6_end"`
}
type NatgatewayDetails struct {
+1
View File
@@ -23,6 +23,7 @@ import (
type NotificationDetails struct {
apis.ModelBaseDetails
Id string `json:"id"`
Name string `json:"name"`
UserList jsonutils.JSONObject `json:"user_list"`
+6 -2
View File
@@ -323,8 +323,12 @@ func (self *SNatSEntry) getMoreDetails(ctx context.Context, userCred mcclient.To
return out
}
out.Network = api.SimpleNetwork{
Id: network.Id,
Name: network.Name,
Id: network.Id,
Name: network.Name,
GuestIpStart: network.GuestIpStart,
GuestIpEnd: network.GuestIpEnd,
GuestIp6Start: network.GuestIp6Start,
GuestIp6End: network.GuestIp6End,
}
natgateway, err := self.GetNatgateway()
if err != nil {
+1 -1
View File
@@ -209,7 +209,7 @@ func (self *SContact) getMoreDetail(ctx context.Context, userCred mcclient.Token
return out, nil
}
func (self *SContact) GetExtraDetail(ctx context.Context, userCred mcclient.TokenCredential,
func (self *SContact) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject, isList bool) (api.ContactDetails, error) {
var err error
out := api.ContactDetails{}
+27 -8
View File
@@ -111,16 +111,35 @@ func (self *SNotification) GetExtraDetails(ctx context.Context, userCred mcclien
if err != nil {
return out, err
}
userDetail := UserDetail{
Status: self.Status,
Name: self.UID,
ReceivedAt: self.ReceivedAt,
var scopeStr string
scopeStr, err = query.GetString("scope")
if err != nil {
scopeStr = "system"
}
name, err := utils.GetUsernameByID(ctx, self.UID)
if err == nil && len(name) != 0 {
out.Name = name
scope := rbacutils.TRbacScope(scopeStr)
var userDetails []UserDetail
if scope.HigherEqual(rbacutils.ScopeSystem) {
userDetails, err = NotificationManager.fetchUserDetailByClusterID(ctx, self.ClusterID)
if err != nil {
return out, errors.Wrap(err, "NotificationManager.fetchUserDetailByClusterID")
}
} else {
userDetail := UserDetail{
Status: self.Status,
Name: self.UID,
ReceivedAt: self.ReceivedAt,
}
name, err := utils.GetUsernameByID(ctx, self.UID)
if err == nil && len(name) != 0 {
userDetail.Name = name
}
userDetails = []UserDetail{userDetail}
}
out.UserList = jsonutils.Marshal([]UserDetail{userDetail})
out.Id = self.ClusterID
out.UserList = jsonutils.Marshal(userDetails)
return out, nil
}