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
This commit is contained in:
Alejandro García Montoro 2024-12-05 16:46:04 +01:00 committed by GitHub
parent 82c1f7bf09
commit 6b648199f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)