Skip to content

Commit

Permalink
feat: Tagrecorder support update team_id
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 authored and SongZhen0704 committed Jul 24, 2024
1 parent e37a88d commit 185caec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/controller/http/service/resource/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ func UpdateSubDomain(lcuuid string, db *mysql.DB, userInfo *httpcommon.UserInfo,
// dbUpdateMap["user_id"] = userID
// resourceUp["owner_user_id"] = userID
// }
if teamID, ok := subDomainUpdate["TEAM_ID"]; ok {
teamID, ok := subDomainUpdate["TEAM_ID"]
if ok {
dbUpdateMap["team_id"] = teamID
resourceUp["team_id"] = teamID
}
Expand Down Expand Up @@ -939,6 +940,15 @@ func UpdateSubDomain(lcuuid string, db *mysql.DB, userInfo *httpcommon.UserInfo,
return nil, err
}

// pub to tagrecorder
teamIDInt := int(teamID.(float64))
if teamIDInt != subDomain.TeamID {
metadata := message.NewMetadata(db.ORGID, message.MetadataSubDomainID(subDomain.ID), message.MetadataTeamID(teamIDInt))
for _, s := range tagrecorder.GetSubscriberManager().GetSubscribers("sub_domain") {
s.OnSubDomainTeamIDUpdated(metadata)
}
}

response, _ := GetSubDomains(db, []int{}, map[string]interface{}{"lcuuid": lcuuid})
return response[0], nil
}
Expand Down
13 changes: 13 additions & 0 deletions server/controller/tagrecorder/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type Subscriber interface {
pubsub.ResourceBatchDeletedSubscriber
OnDomainDeleted(md *message.Metadata)
OnSubDomainDeleted(md *message.Metadata)
OnSubDomainTeamIDUpdated(md *message.Metadata)
}

type SubscriberDataGenerator[MUPT msgconstraint.FieldsUpdatePtr[MUT], MUT msgconstraint.FieldsUpdate, MT constraint.MySQLModel, CT MySQLChModel, KT ChModelKey] interface {
Expand Down Expand Up @@ -267,3 +268,15 @@ func (s *SubscriberComponent[MUPT, MUT, MT, CT, KT]) OnSubDomainDeleted(md *mess
log.Error(err)
}
}

// Update team_id of resource by sub domain
func (s *SubscriberComponent[MUPT, MUT, MT, CT, KT]) OnSubDomainTeamIDUpdated(md *message.Metadata) {
var chModel CT
db, err := mysql.GetDB(md.ORGID)
if err != nil {
log.Errorf("get org dbinfo fail : %d", md.ORGID)
}
if err := db.Model(&chModel).Where("sub_domain_id = ?", md.SubDomainID).Update("team_id", md.TeamID).Error; err != nil {
log.Error(err)
}
}

0 comments on commit 185caec

Please sign in to comment.