MM-61992: Verify license.Features.Users is not nil (#29417)

* Verify license.Features.Users is not nil

* Move check before DB call to avoid it if possible

* Add more context to the error
Этот коммит содержится в:
Alejandro García Montoro
2024-12-05 16:46:04 +01:00
коммит произвёл GitHub
родитель 82c1f7bf09
Коммит 6b648199f0

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

@@ -126,6 +126,14 @@ func (ps *PlatformService) SaveLicense(licenseBytes []byte) (*model.License, *mo
return nil, model.NewAppError("addLicense", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
}
if license.Features == nil {
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("license.Features is nil"))
}
if license.Features.Users == nil {
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(errors.New("license.Features.Users is nil"))
}
uniqueUserCount, err := ps.Store.User().Count(model.UserCountOptions{})
if err != nil {
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, "", http.StatusBadRequest).Wrap(err)