mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
feature: webhook support notification of user update (#14912)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -74,6 +74,10 @@ func doMonitorEventList(s *mcclient.ClientSession, args *EventListOptions) error
|
||||
return DoEventList(modules.MonitorLogs, s, args)
|
||||
}
|
||||
|
||||
func doNotifyEventList(s *mcclient.ClientSession, args *EventListOptions) error {
|
||||
return DoEventList(modules.NotifyLogs, s, args)
|
||||
}
|
||||
|
||||
func DoEventList(man modulebase.ResourceManager, s *mcclient.ClientSession, args *EventListOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Type) > 0 {
|
||||
@@ -262,4 +266,9 @@ func init() {
|
||||
nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"migrationalert"}}
|
||||
return doMonitorEventList(s, &nargs)
|
||||
})
|
||||
|
||||
R(&TypeEventListOptions{}, "notification-event", "Show operation event logs of a notification", func(s *mcclient.ClientSession, args *TypeEventListOptions) error {
|
||||
nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"notification"}}
|
||||
return doNotifyEventList(s, &nargs)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ type ReceiveDetail struct {
|
||||
ReceiverId string `json:"receiver_id"`
|
||||
ReceiverName string `json:"receiver_name"`
|
||||
Contact string `json:"contact"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
SendAt time.Time `json:"sendAt"`
|
||||
SendBy string `json:"send_by"`
|
||||
Status string `json:"status"`
|
||||
|
||||
@@ -2111,3 +2111,11 @@ func (manager *SDBInstanceManager) GetExpiredModels(advanceDay int) ([]IBillingM
|
||||
func (self *SDBInstance) GetExpiredAt() time.Time {
|
||||
return self.ExpiredAt
|
||||
}
|
||||
|
||||
func (db *SDBInstance) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
db.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: db,
|
||||
Action: notifyclient.ActionUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -652,3 +652,11 @@ func (self *SElasticSearch) GetDetailsAccessInfo(ctx context.Context, userCred m
|
||||
}
|
||||
return iEs.GetAccessInfo()
|
||||
}
|
||||
|
||||
func (es *SElasticSearch) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
es.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: es,
|
||||
Action: notifyclient.ActionUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1884,6 +1884,10 @@ func (self *SGuest) PostUpdate(ctx context.Context, userCred mcclient.TokenCrede
|
||||
log.Errorf("unable to set sshport for guest %s", self.GetId())
|
||||
}
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: self,
|
||||
Action: notifyclient.ActionUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
func (manager *SGuestManager) checkCreateQuota(
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/keystone/options"
|
||||
@@ -778,6 +779,10 @@ func (user *SUser) PostUpdate(ctx context.Context, userCred mcclient.TokenCreden
|
||||
log.Errorf("unable to clear failed auth: %v", err)
|
||||
}
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: user,
|
||||
Action: notifyclient.ActionUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
func (user *SUser) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
||||
|
||||
@@ -34,6 +34,7 @@ var (
|
||||
CloudeventLogs modulebase.ResourceManager
|
||||
ComputeLogs modulebase.ResourceManager
|
||||
MonitorLogs modulebase.ResourceManager
|
||||
NotifyLogs modulebase.ResourceManager
|
||||
)
|
||||
|
||||
func (this *LogsManager) Get(session *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
@@ -47,6 +48,10 @@ func (this *LogsManager) Get(session *mcclient.ClientSession, id string, params
|
||||
return IdentityLogs.Get(session, id, params)
|
||||
case apis.SERVICE_TYPE_CLOUDEVENT:
|
||||
return CloudeventLogs.Get(session, id, params)
|
||||
case apis.SERVICE_TYPE_MONITOR:
|
||||
return MonitorLogs.Get(session, id, params)
|
||||
case apis.SERVICE_TYPE_NOTIFY:
|
||||
return NotifyLogs.Get(session, id, params)
|
||||
default:
|
||||
return ComputeLogs.Get(session, id, params)
|
||||
}
|
||||
@@ -63,6 +68,10 @@ func (this *LogsManager) PerformClassAction(session *mcclient.ClientSession, act
|
||||
return IdentityLogs.PerformClassAction(session, action, params)
|
||||
case apis.SERVICE_TYPE_CLOUDEVENT:
|
||||
return CloudeventLogs.PerformClassAction(session, action, params)
|
||||
case apis.SERVICE_TYPE_MONITOR:
|
||||
return MonitorLogs.PerformClassAction(session, action, params)
|
||||
case apis.SERVICE_TYPE_NOTIFY:
|
||||
return NotifyLogs.PerformClassAction(session, action, params)
|
||||
default:
|
||||
return ComputeLogs.PerformClassAction(session, action, params)
|
||||
}
|
||||
@@ -88,6 +97,9 @@ func init() {
|
||||
MonitorLogs = NewMonitorV2Manager("event", "events",
|
||||
[]string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"},
|
||||
[]string{})
|
||||
NotifyLogs = NewNotifyv2Manager("event", "events",
|
||||
[]string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"},
|
||||
[]string{})
|
||||
|
||||
Logs = LogsManager{ComputeLogs}
|
||||
Register(&Logs)
|
||||
|
||||
@@ -62,7 +62,7 @@ func init() {
|
||||
Notification = modules.NewNotifyv2Manager(
|
||||
"notification",
|
||||
"notifications",
|
||||
[]string{"Title", "Content", "ContactType", "Priority", "Receiver_Details"},
|
||||
[]string{"ID", "Name", "Contact_Type", "Title", "Content", "Priority", "Status", "Received_At", "Receiver_Type"},
|
||||
[]string{},
|
||||
)
|
||||
modules.Register(&Notification)
|
||||
|
||||
@@ -521,7 +521,7 @@ func (n *SNotification) ReceiverNotificationsNotOK() ([]SReceiverNotification, e
|
||||
|
||||
func (n *SNotification) ReceiveDetails(userCred mcclient.TokenCredential, scope string) ([]api.ReceiveDetail, error) {
|
||||
RQ := ReceiverManager.Query("id", "name")
|
||||
q := ReceiverNotificationManager.Query("receiver_id", "notification_id", "contact", "send_at", "send_by", "status", "failed_reason").Equals("notification_id", n.Id)
|
||||
q := ReceiverNotificationManager.Query("receiver_id", "notification_id", "receiver_type", "contact", "send_at", "send_by", "status", "failed_reason").Equals("notification_id", n.Id)
|
||||
s := rbacutils.TRbacScope(scope)
|
||||
|
||||
switch s {
|
||||
|
||||
@@ -367,11 +367,11 @@ func (s *SSubscriber) CustomizeDelete(ctx context.Context, userCred mcclient.Tok
|
||||
return err
|
||||
}
|
||||
if s.Scope == string(rbacutils.ScopeSystem) {
|
||||
if db.IsAdminAllowDelete(ctx, userCred, s) {
|
||||
if !db.IsAdminAllowDelete(ctx, userCred, s) {
|
||||
return httperrors.NewForbiddenError("")
|
||||
}
|
||||
} else {
|
||||
if db.IsDomainAllowDelete(ctx, userCred, s) {
|
||||
if !db.IsDomainAllowDelete(ctx, userCred, s) {
|
||||
return httperrors.NewForbiddenError("")
|
||||
}
|
||||
if s.DomainId != userCred.GetProjectDomainId() {
|
||||
|
||||
@@ -187,6 +187,7 @@ func (sm *STopicManager) InitializeData() error {
|
||||
notify.TOPIC_RESOURCE_SERVER,
|
||||
notify.TOPIC_RESOURCE_DBINSTANCE,
|
||||
notify.TOPIC_RESOURCE_ELASTICCACHE,
|
||||
notify.TOPIC_RESOURCE_USER,
|
||||
)
|
||||
t.addAction(notify.ActionUpdate)
|
||||
t.addAction(notify.ActionRebuildRoot)
|
||||
|
||||
@@ -155,6 +155,7 @@ func (self *NotificationSendTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
apis.TEMPLATE_LANG_EN: receiversEn,
|
||||
} {
|
||||
if len(receivers) == 0 {
|
||||
log.Warningf("no receiver to send, skip ...")
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user