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
83
server/public/model/property_field.go
Обычный файл
83
server/public/model/property_field.go
Обычный файл
@@ -0,0 +1,83 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import "net/http"
|
||||
|
||||
type PropertyFieldType string
|
||||
|
||||
const (
|
||||
PropertyFieldTypeText PropertyFieldType = "text"
|
||||
PropertyFieldTypeSelect PropertyFieldType = "select"
|
||||
PropertyFieldTypeMultiselect PropertyFieldType = "multiselect"
|
||||
PropertyFieldTypeDate PropertyFieldType = "date"
|
||||
PropertyFieldTypeUser PropertyFieldType = "user"
|
||||
PropertyFieldTypeMultiuser PropertyFieldType = "multiuser"
|
||||
)
|
||||
|
||||
type PropertyField struct {
|
||||
ID string `json:"id"`
|
||||
GroupID string `json:"group_id"`
|
||||
Name string `json:"name"`
|
||||
Type PropertyFieldType `json:"type"`
|
||||
Attrs map[string]any `json:"attrs"`
|
||||
TargetID string `json:"target_id"`
|
||||
TargetType string `json:"target_type"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
}
|
||||
|
||||
func (pf *PropertyField) PreSave() {
|
||||
if pf.ID == "" {
|
||||
pf.ID = NewId()
|
||||
}
|
||||
|
||||
if pf.CreateAt == 0 {
|
||||
pf.CreateAt = GetMillis()
|
||||
}
|
||||
pf.UpdateAt = pf.CreateAt
|
||||
}
|
||||
|
||||
func (pf *PropertyField) IsValid() error {
|
||||
if !IsValidId(pf.ID) {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "id", "Reason": "invalid id"}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidId(pf.GroupID) {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "group_id", "Reason": "invalid id"}, "id="+pf.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pf.Name == "" {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "name", "Reason": "value cannot be empty"}, "id="+pf.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !(pf.Type == PropertyFieldTypeText ||
|
||||
pf.Type == PropertyFieldTypeSelect ||
|
||||
pf.Type == PropertyFieldTypeMultiselect ||
|
||||
pf.Type == PropertyFieldTypeDate ||
|
||||
pf.Type == PropertyFieldTypeUser ||
|
||||
pf.Type == PropertyFieldTypeMultiuser) {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "type", "Reason": "unknown value"}, "id="+pf.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pf.CreateAt == 0 {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "create_at", "Reason": "value cannot be zero"}, "id="+pf.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pf.UpdateAt == 0 {
|
||||
return NewAppError("PropertyField.IsValid", "model.property_field.is_valid.app_error", map[string]any{"FieldName": "update_at", "Reason": "value cannot be zero"}, "id="+pf.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type PropertyFieldSearchOpts struct {
|
||||
GroupID string
|
||||
TargetType string
|
||||
TargetID string
|
||||
IncludeDeleted bool
|
||||
Page int
|
||||
PerPage int
|
||||
}
|
||||
15
server/public/model/property_group.go
Обычный файл
15
server/public/model/property_group.go
Обычный файл
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
type PropertyGroup struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (pg *PropertyGroup) PreSave() {
|
||||
if pg.ID == "" {
|
||||
pg.ID = NewId()
|
||||
}
|
||||
}
|
||||
71
server/public/model/property_value.go
Обычный файл
71
server/public/model/property_value.go
Обычный файл
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import "net/http"
|
||||
|
||||
type PropertyValue struct {
|
||||
ID string `json:"id"`
|
||||
TargetID string `json:"target_id"`
|
||||
TargetType string `json:"target_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
FieldID string `json:"field_id"`
|
||||
Value string `json:"value"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
}
|
||||
|
||||
func (pv *PropertyValue) PreSave() {
|
||||
if pv.ID == "" {
|
||||
pv.ID = NewId()
|
||||
}
|
||||
|
||||
if pv.CreateAt == 0 {
|
||||
pv.CreateAt = GetMillis()
|
||||
}
|
||||
pv.UpdateAt = pv.CreateAt
|
||||
}
|
||||
|
||||
func (pv *PropertyValue) IsValid() error {
|
||||
if !IsValidId(pv.ID) {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "id", "Reason": "invalid id"}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidId(pv.TargetID) {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "target_id", "Reason": "invalid id"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pv.TargetType == "" {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "target_type", "Reason": "value cannot be empty"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidId(pv.GroupID) {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "group_id", "Reason": "invalid id"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if !IsValidId(pv.FieldID) {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "field_id", "Reason": "invalid id"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pv.CreateAt == 0 {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "create_at", "Reason": "value cannot be zero"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if pv.UpdateAt == 0 {
|
||||
return NewAppError("PropertyValue.IsValid", "model.property_value.is_valid.app_error", map[string]any{"FieldName": "update_at", "Reason": "value cannot be zero"}, "id="+pv.ID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type PropertyValueSearchOpts struct {
|
||||
GroupID string
|
||||
TargetType string
|
||||
TargetID string
|
||||
FieldID string
|
||||
IncludeDeleted bool
|
||||
Page int
|
||||
PerPage int
|
||||
}
|
||||
Ссылка в новой задаче
Block a user