fix: handle usermemberships on project and project grant delete (#825)

This commit is contained in:
Fabi 2020-10-13 07:46:44 +02:00 committed by GitHub
parent 010a5815f4
commit 905ee1c68a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 2 deletions

View File

@ -179,6 +179,10 @@ func (m *UserMembership) processProject(event *models.Event) (err error) {
return m.view.DeleteUserMembership(member.UserID, event.AggregateID, member.ObjectID, usr_model.MemberTypeProjectGrant, event.Sequence)
case proj_es_model.ProjectChanged:
err = m.updateProjectDisplayName(event)
case proj_es_model.ProjectRemoved:
return m.view.DeleteUserMembershipsByAggregateID(event.AggregateID, event.Sequence)
case proj_es_model.ProjectGrantRemoved:
return m.view.DeleteUserMembershipsByAggregateIDAndObjectID(event.AggregateID, member.ObjectID, event.Sequence)
default:
return m.view.ProcessedUserMembershipSequence(event.Sequence)
}

View File

@ -59,6 +59,22 @@ func (v *View) DeleteUserMembershipsByUserID(userID string, eventSequence uint64
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) DeleteUserMembershipsByAggregateID(aggregateID string, eventSequence uint64) error {
err := view.DeleteUserMembershipsByAggregateID(v.Db, userMembershipTable, aggregateID)
if err != nil {
return nil
}
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) DeleteUserMembershipsByAggregateIDAndObjectID(aggregateID, objectID string, eventSequence uint64) error {
err := view.DeleteUserMembershipsByAggregateIDAndObjectID(v.Db, userMembershipTable, aggregateID, objectID)
if err != nil {
return nil
}
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) GetLatestUserMembershipSequence() (*repository.CurrentSequence, error) {
return v.latestSequence(userMembershipTable)
}

View File

@ -167,6 +167,10 @@ func (m *UserMembership) processProject(event *models.Event) (err error) {
return m.view.DeleteUserMembership(member.UserID, event.AggregateID, member.ObjectID, usr_model.MemberTypeProjectGrant, event.Sequence)
case proj_es_model.ProjectChanged:
err = m.updateProjectDisplayName(event)
case proj_es_model.ProjectRemoved:
return m.view.DeleteUserMembershipsByAggregateID(event.AggregateID, event.Sequence)
case proj_es_model.ProjectGrantRemoved:
return m.view.DeleteUserMembershipsByAggregateIDAndObjectID(event.AggregateID, member.ObjectID, event.Sequence)
default:
return m.view.ProcessedUserMembershipSequence(event.Sequence)
}

View File

@ -55,6 +55,22 @@ func (v *View) DeleteUserMembershipsByUserID(userID string, eventSequence uint64
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) DeleteUserMembershipsByAggregateID(aggregateID string, eventSequence uint64) error {
err := view.DeleteUserMembershipsByAggregateID(v.Db, userMembershipTable, aggregateID)
if err != nil {
return nil
}
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) DeleteUserMembershipsByAggregateIDAndObjectID(aggregateID, objectID string, eventSequence uint64) error {
err := view.DeleteUserMembershipsByAggregateIDAndObjectID(v.Db, userMembershipTable, aggregateID, objectID)
if err != nil {
return nil
}
return v.ProcessedUserMembershipSequence(eventSequence)
}
func (v *View) GetLatestUserMembershipSequence() (*repository.CurrentSequence, error) {
return v.latestSequence(userMembershipTable)
}

View File

@ -87,10 +87,10 @@ func (u *UserMembershipView) AppendEvent(event *models.Event) (err error) {
err = u.setProjectMemberData(event)
case proj_es_model.ProjectGrantMemberAdded:
u.setRootData(event, model.MemberTypeProjectGrant)
err = u.setProjectMemberData(event)
err = u.setProjectGrantMemberData(event)
case proj_es_model.ProjectGrantMemberChanged,
proj_es_model.ProjectGrantMemberRemoved:
err = u.setProjectMemberData(event)
err = u.setProjectGrantMemberData(event)
}
return err
}

View File

@ -83,3 +83,16 @@ func DeleteUserMembershipsByUserID(db *gorm.DB, table, userID string) error {
delete := repository.PrepareDeleteByKey(table, model.UserMembershipSearchKey(usr_model.UserMembershipSearchKeyUserID), userID)
return delete(db)
}
func DeleteUserMembershipsByAggregateID(db *gorm.DB, table, aggregateID string) error {
delete := repository.PrepareDeleteByKey(table, model.UserMembershipSearchKey(usr_model.UserMembershipSearchKeyAggregateID), aggregateID)
return delete(db)
}
func DeleteUserMembershipsByAggregateIDAndObjectID(db *gorm.DB, table, aggregateID, objectID string) error {
delete := repository.PrepareDeleteByKeys(table,
repository.Key{Key: model.UserMembershipSearchKey(usr_model.UserMembershipSearchKeyAggregateID), Value: aggregateID},
repository.Key{Key: model.UserMembershipSearchKey(usr_model.UserMembershipSearchKeyObjectID), Value: objectID},
)
return delete(db)
}