mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(notify): adjust subscribers when deleting bots and recipients
This commit is contained in:
@@ -915,9 +915,28 @@ func (r *SReceiver) Delete(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
return err
|
||||
}
|
||||
}
|
||||
r.deleteReceiverInSubscriber(ctx)
|
||||
return r.SStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (r *SReceiver) deleteReceiverInSubscriber(ctx context.Context) {
|
||||
q := SubscriberReceiverManager.Query().Equals("receiver_id", r.Id)
|
||||
srs := make([]SSubscriberReceiver, 0, 2)
|
||||
err := db.FetchModelObjects(SubscriberReceiverManager, q, &srs)
|
||||
if err != nil {
|
||||
log.Infof("unable to get SubscriberReceiver: %s", err.Error())
|
||||
}
|
||||
for i := range srs {
|
||||
sr := &srs[i]
|
||||
_, err := db.Update(sr, func() error {
|
||||
return sr.MarkDelete()
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("unable to delete subscriber receiver for receiver %q", r.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *SReceiver) IsOwner(userCred mcclient.TokenCredential) bool {
|
||||
return r.Id == userCred.GetUserId()
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
idenapi "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/apis/notify"
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -280,3 +281,22 @@ func (r *SRobot) PerformDisable(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *SRobot) PostDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
q := SubscriberManager.Query().Equals("type", notify.SUBSCRIBER_TYPE_ROBOT).Equals("identification", r.GetId())
|
||||
subscribers := make([]SSubscriber, 0, 2)
|
||||
err := db.FetchModelObjects(SubscriberManager, q, &subscribers)
|
||||
if err != nil {
|
||||
log.Errorf("unable to fetch subscribers with robot %q", r.GetId())
|
||||
return
|
||||
}
|
||||
for i := range subscribers {
|
||||
subscriber := &subscribers[i]
|
||||
_, err := db.Update(r, func() error {
|
||||
return subscriber.MarkDelete()
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("unable to delete subscriber %q because of deleting of robot %q", subscribers[i].GetId(), r.GetId())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ type SSubscriber struct {
|
||||
|
||||
TopicID string `width:"128" charset:"ascii" nullable:"false" index:"true" get:"user" list:"user"`
|
||||
Type string `width:"16" charset:"ascii" nullable:"false" index:"true" get:"user" list:"user"`
|
||||
Identification string `width:"128" charset:"ascii" nullable:"false"`
|
||||
Identification string `width:"128" charset:"ascii" nullable:"false" index:"true"`
|
||||
RoleScope string `width:"8" charset:"ascii" nullable:"false" get:"user" list:"user"`
|
||||
ResourceScope string `width:"8" charset:"ascii" nullable:"false" get:"user" list:"user"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user