Files
mostlymatter/server/channels/app/properties/property_field.go
Miguel de la Cruz e51ea025db Deletes CPA values on CPA field type change (#31122)
* Deletes CPA values on CPA field type change

* Fix error method name reference

* Cleans the state when a CPA field's type is updated

* Fix types

* Fix linter

* Webapp no longer makes a decision on the change and server sents a flag in the WS message

* Fix linter

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
2025-05-27 13:38:05 +02:00

68 строки
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package properties
import (
"fmt"
"github.com/mattermost/mattermost/server/public/model"
)
func (ps *PropertyService) CreatePropertyField(field *model.PropertyField) (*model.PropertyField, error) {
return ps.fieldStore.Create(field)
}
func (ps *PropertyService) GetPropertyField(groupID, id string) (*model.PropertyField, error) {
return ps.fieldStore.Get(groupID, id)
}
func (ps *PropertyService) GetPropertyFields(groupID string, ids []string) ([]*model.PropertyField, error) {
return ps.fieldStore.GetMany(groupID, ids)
}
func (ps *PropertyService) GetPropertyFieldByName(groupID, targetID, name string) (*model.PropertyField, error) {
return ps.fieldStore.GetFieldByName(groupID, targetID, name)
}
func (ps *PropertyService) CountActivePropertyFieldsForGroup(groupID string) (int64, error) {
return ps.fieldStore.CountForGroup(groupID, false)
}
func (ps *PropertyService) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
// groupID and targetID are part of the search method signature to
// incentivize the use of the database indexes in searches
opts.GroupID = groupID
opts.TargetID = targetID
return ps.fieldStore.SearchPropertyFields(opts)
}
func (ps *PropertyService) UpdatePropertyField(groupID string, field *model.PropertyField) (*model.PropertyField, error) {
fields, err := ps.UpdatePropertyFields(groupID, []*model.PropertyField{field})
if err != nil {
return nil, err
}
return fields[0], nil
}
func (ps *PropertyService) UpdatePropertyFields(groupID string, fields []*model.PropertyField) ([]*model.PropertyField, error) {
return ps.fieldStore.Update(groupID, fields)
}
func (ps *PropertyService) DeletePropertyField(groupID, id string) error {
// if groupID is not empty, we need to check first that the field belongs to the group
if groupID != "" {
if _, err := ps.GetPropertyField(groupID, id); err != nil {
return fmt.Errorf("error getting property field %q for group %q: %w", id, groupID, err)
}
}
if err := ps.valueStore.DeleteForField(groupID, id); err != nil {
return err
}
return ps.fieldStore.Delete(groupID, id)
}