Adds Custom Profile Attributes API endpoints license check (#29906)

* Adds Custom Profile Attributes feature license and API endpoints check

* Fix linter

* Remove the specific license feature and fallback to checking for license presence

* Add translation

* Update the checks and tests to enable endpoints only for Enterprise licenses

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Miguel de la Cruz
2025-01-23 09:50:43 +01:00
коммит произвёл GitHub
родитель 077d0872e3
Коммит 7fb6901ad1
3 изменённых файлов: 109 добавлений и 9 удалений

Просмотреть файл

@@ -25,6 +25,11 @@ func (api *API) InitCustomProfileAttributes() {
}
func listCPAFields(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.listCPAFields", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
fields, appErr := c.App.ListCPAFields()
if appErr != nil {
c.Err = appErr
@@ -42,6 +47,11 @@ func createCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.createCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
var pf *model.PropertyField
err := json.NewDecoder(r.Body).Decode(&pf)
if err != nil || pf == nil {
@@ -77,6 +87,11 @@ func patchCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.patchCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
c.RequireFieldId()
if c.Err != nil {
return
@@ -124,6 +139,11 @@ func deleteCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.deleteCPAField", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
c.RequireFieldId()
if c.Err != nil {
return
@@ -153,6 +173,11 @@ func deleteCPAField(c *Context, w http.ResponseWriter, r *http.Request) {
}
func patchCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.patchCPAValues", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
var attributeValues map[string]string
if jsonErr := json.NewDecoder(r.Body).Decode(&attributeValues); jsonErr != nil {
c.SetInvalidParamWithErr("attrs", jsonErr)
@@ -190,6 +215,11 @@ func patchCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
}
func listCPAValues(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.Channels().License() == nil || !c.App.Channels().License().IsE20OrEnterprise() {
c.Err = model.NewAppError("Api4.listCPAValues", "api.custom_profile_attributes.license_error", nil, "", http.StatusForbidden)
return
}
c.RequireUserId()
if c.Err != nil {
return