Adds the main Property System Architecture components (#29644)
* Adds the main Property System Architecture components This change adds the necessary migrations for the Property Groups, Fields and Values tables to be created, the store layer and a Property Service that can be used from the app layer. * Update property field type to use user instead of person * Update PropertyFields to allow for unique nondeleted fields and remove redundant indexes * Update PropertyValues to allow for unique nondeleted fields and remove redundant indexes * Use StringMap instead of the map[string]any on property fields * Add i18n strings * Revert "Use StringMap instead of the map[string]any on property fields" This reverts commit e2735ab0f8589d2524d636419ca0cb144575c4d6. * Cast JSON binary data to string and add todo note for StringMap use * Add mocks to the retrylayer tests * Cast JSON binary data to string in property value store * Check for binary parameter instead of casting to string for JSON data * Check property field type is one of the allowed ones * Avoid reusing err variable to be explicit about the returned value * Merge Property System Migrations into one file * Adds NOT NULL to timestamps at the DB level * Update stores to use tableSelectQuery instead of a slice var * Update PropertyField model translations to be more explicit and avoid repetition * Update PropertyValue model translations to be more explicit and avoid repetition * Use ExecBuilder instead of ToSql&Exec * Update property field errors to add context * Ensure PerPage is greater than zero * Update store errors to give more context * Use ExecBuilder in the property stores where possible * Add an on conflict suffix to the group register to avoid race conditions * Remove badly used translation string * Remove unused get in register group method --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d2b334e605
Коммит
ecdce71fc4
44
server/channels/app/properties/property_field.go
Обычный файл
44
server/channels/app/properties/property_field.go
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package properties
|
||||
|
||||
import (
|
||||
"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(id string) (*model.PropertyField, error) {
|
||||
return ps.fieldStore.Get(id)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) GetPropertyFields(ids []string) ([]*model.PropertyField, error) {
|
||||
return ps.fieldStore.GetMany(ids)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) SearchPropertyFields(opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
|
||||
return ps.fieldStore.SearchPropertyFields(opts)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) UpdatePropertyField(field *model.PropertyField) (*model.PropertyField, error) {
|
||||
fields, err := ps.UpdatePropertyFields([]*model.PropertyField{field})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fields[0], nil
|
||||
}
|
||||
|
||||
func (ps *PropertyService) UpdatePropertyFields(fields []*model.PropertyField) ([]*model.PropertyField, error) {
|
||||
return ps.fieldStore.Update(fields)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) DeletePropertyField(id string) error {
|
||||
if err := ps.valueStore.DeleteForField(id); err != nil {
|
||||
return err
|
||||
}
|
||||
return ps.fieldStore.Delete(id)
|
||||
}
|
||||
16
server/channels/app/properties/property_group.go
Обычный файл
16
server/channels/app/properties/property_group.go
Обычный файл
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package properties
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
func (ps *PropertyService) RegisterPropertyGroup(name string) (*model.PropertyGroup, error) {
|
||||
return ps.groupStore.Register(name)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) GetPropertyGroup(name string) (*model.PropertyGroup, error) {
|
||||
return ps.groupStore.Get(name)
|
||||
}
|
||||
41
server/channels/app/properties/property_value.go
Обычный файл
41
server/channels/app/properties/property_value.go
Обычный файл
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package properties
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
func (ps *PropertyService) CreatePropertyValue(value *model.PropertyValue) (*model.PropertyValue, error) {
|
||||
return ps.valueStore.Create(value)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) GetPropertyValue(id string) (*model.PropertyValue, error) {
|
||||
return ps.valueStore.Get(id)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) GetPropertyValues(ids []string) ([]*model.PropertyValue, error) {
|
||||
return ps.valueStore.GetMany(ids)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) SearchPropertyValues(opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
|
||||
return ps.valueStore.SearchPropertyValues(opts)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) UpdatePropertyValue(value *model.PropertyValue) (*model.PropertyValue, error) {
|
||||
values, err := ps.UpdatePropertyValues([]*model.PropertyValue{value})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return values[0], nil
|
||||
}
|
||||
|
||||
func (ps *PropertyService) UpdatePropertyValues(values []*model.PropertyValue) ([]*model.PropertyValue, error) {
|
||||
return ps.valueStore.Update(values)
|
||||
}
|
||||
|
||||
func (ps *PropertyService) DeletePropertyValue(id string) error {
|
||||
return ps.valueStore.Delete(id)
|
||||
}
|
||||
41
server/channels/app/properties/service.go
Обычный файл
41
server/channels/app/properties/service.go
Обычный файл
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package properties
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
type PropertyService struct {
|
||||
groupStore store.PropertyGroupStore
|
||||
fieldStore store.PropertyFieldStore
|
||||
valueStore store.PropertyValueStore
|
||||
}
|
||||
|
||||
type ServiceConfig struct {
|
||||
PropertyGroupStore store.PropertyGroupStore
|
||||
PropertyFieldStore store.PropertyFieldStore
|
||||
PropertyValueStore store.PropertyValueStore
|
||||
}
|
||||
|
||||
func New(c ServiceConfig) (*PropertyService, error) {
|
||||
if err := c.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PropertyService{
|
||||
groupStore: c.PropertyGroupStore,
|
||||
fieldStore: c.PropertyFieldStore,
|
||||
valueStore: c.PropertyValueStore,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) validate() error {
|
||||
if c.PropertyGroupStore == nil || c.PropertyFieldStore == nil || c.PropertyValueStore == nil {
|
||||
return errors.New("required parameters are not provided")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/timezones"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/email"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/properties"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/teams"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/users"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
@@ -136,6 +137,7 @@ type Server struct {
|
||||
telemetryService *telemetry.TelemetryService
|
||||
userService *users.UserService
|
||||
teamService *teams.TeamService
|
||||
propertyService *properties.PropertyService
|
||||
|
||||
serviceMux sync.RWMutex
|
||||
remoteClusterService remotecluster.RemoteClusterServiceIFace
|
||||
@@ -239,6 +241,15 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return nil, errors.Wrapf(err, "unable to create teams service")
|
||||
}
|
||||
|
||||
s.propertyService, err = properties.New(properties.ServiceConfig{
|
||||
PropertyGroupStore: s.Store().PropertyGroup(),
|
||||
PropertyFieldStore: s.Store().PropertyField(),
|
||||
PropertyValueStore: s.Store().PropertyValue(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to create properties service")
|
||||
}
|
||||
|
||||
// It is important to initialize the hub only after the global logger is set
|
||||
// to avoid race conditions while logging from inside the hub.
|
||||
// Step 4: Start platform
|
||||
|
||||
Ссылка в новой задаче
Block a user