Adds a mechanism to delete CPA values for a given user (#30330)
* Adds a mechanism to delete CPA values for a given user This requires improving the Property Value service to enable delete all values for a given target, so a new method was created that allows to delete filtering by targetType and targetID (required) and optionally for a specific groupID in case the caller wants to affect all values for a target (useful in case you remove a post for example and want to delete all values pointing to that post regardless of the feature they belong to) or only those that belong to a specific feature. * Fix property value tests * Fix after merge and update method name * Fix linter --------- Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3ab0da1648
Коммит
ca9fd45408
@@ -339,3 +339,26 @@ func (s *SqlPropertyValueStore) DeleteForField(fieldID string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlPropertyValueStore) DeleteForTarget(groupID string, targetType string, targetID string) error {
|
||||
if targetType == "" || targetID == "" {
|
||||
return store.NewErrInvalidInput("PropertyValue", "target", "type or id empty")
|
||||
}
|
||||
|
||||
builder := s.getQueryBuilder().
|
||||
Delete("PropertyValues").
|
||||
Where(sq.Eq{
|
||||
"TargetType": targetType,
|
||||
"TargetID": targetID,
|
||||
})
|
||||
|
||||
if groupID != "" {
|
||||
builder = builder.Where(sq.Eq{"GroupID": groupID})
|
||||
}
|
||||
|
||||
if _, err := s.GetMaster().ExecBuilder(builder); err != nil {
|
||||
return errors.Wrap(err, "property_value_delete_for_target_exec")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user