[MM-37108] Fix possible nil dereference in team edition (#17933)
* Fix possible nil dereference * Fix translation * Switch to StatusForbidden Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
186475db3b
Коммит
75d6480393
@@ -181,6 +181,11 @@ func requestTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Srv().LicenseManager == nil {
|
||||
c.Err = model.NewAppError("requestTrialLicense", "api.license.upgrade_needed.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
canStartTrialLicense, err := c.App.Srv().LicenseManager.CanStartTrial()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("requestTrialLicense", "api.license.request-trial.can-start-trial.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -278,6 +283,11 @@ func requestRenewalLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getPrevTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.App.Srv().LicenseManager == nil {
|
||||
c.Err = model.NewAppError("getPrevTrialLicense", "api.license.upgrade_needed.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
license, err := c.App.Srv().LicenseManager.GetPrevTrial()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -229,4 +229,12 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
require.Equal(t, "api.license.add_license.unique_users.app_error", resp.Error.Id)
|
||||
require.False(t, ok)
|
||||
})
|
||||
|
||||
th.App.Srv().LicenseManager = nil
|
||||
t.Run("trial license should fail if LicenseManager is nil", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.RequestTrialLicense(1)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok)
|
||||
require.Equal(t, "api.license.upgrade_needed.app_error", resp.Error.Id)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2000,6 +2000,10 @@
|
||||
"id": "api.license.request_trial_license.no-site-url.app_error",
|
||||
"translation": "Unable to request a trial license. Please configure a Site URL in the web server section of the Mattermost System Console."
|
||||
},
|
||||
{
|
||||
"id": "api.license.upgrade_needed.app_error",
|
||||
"translation": "Feature requires an upgrade to Enterprise Edition."
|
||||
},
|
||||
{
|
||||
"id": "api.marshal_error",
|
||||
"translation": "marshal error"
|
||||
|
||||
Ссылка в новой задаче
Block a user