Files
team/server/channels/app/property_group.go
ff6e675783 Property System v2 Generic APIs blacklist (#36171)
* Adds version to the property group model

* Ensures that the REST API rejects v1 group calls

* Ensures field version and group version match

* Simplify property groups on app layer tests

* Add GetByID to PropertyGroupStore and enforce field/group version match on update

* Simplify bits of the code

* Fix i18n and add generic errors

* Fix PropertyGroupStore mock to return stable IDs and default zero version to V1

* Fix tests that were using nonexistent group IDs

* Fix rigidness on valid group names

* Update group not found slug

* Temporary allow to use tempaltes with v1

* Explicitly including tempaltes in the IsPSAv1 check for conflict check

* Return 404 on group not found and template explicit inclusion on patch API endpoint

* Fix CPA test that would use fields from unregistered groups

---------

Co-authored-by: Miguel de la Cruz <[email protected]>
2026-04-24 11:51:02 +02:00

35 lines
1.4 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"net/http"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
)
// RegisterPropertyGroup registers a new property group.
// If the group already exists, it returns the existing group.
func (a *App) RegisterPropertyGroup(rctx request.CTX, group *model.PropertyGroup) (*model.PropertyGroup, *model.AppError) {
registered, err := a.Srv().propertyService.RegisterPropertyGroup(group)
if err != nil {
return nil, model.NewAppError("RegisterPropertyGroup", "app.property_group.register.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return registered, nil
}
// GetPropertyGroup retrieves a property group by name.
func (a *App) GetPropertyGroup(rctx request.CTX, name string) (*model.PropertyGroup, *model.AppError) {
group, err := a.Srv().propertyService.GetPropertyGroup(name)
if err != nil {
if store.IsErrNotFound(err) {
return nil, model.NewAppError("GetPropertyGroup", "app.property_group.get.app_error", nil, "", http.StatusNotFound).Wrap(err)
}
return nil, model.NewAppError("GetPropertyGroup", "app.property_group.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return group, nil
}