Growth spike: Get latest MM version (#19366)

* tools updates

* Revert "tools updates"

This reverts commit 6293297b55803c5a263e200ebd80192899666ae9.

* new endpoint to fetch the latest release information

* adding unit tests

* fixing tests and adding check for github response

* error translations

* fixing translations

* chaning error log

* changing cache size

* empty strings for translations

* changing size to 1

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ben Cooke
2022-02-02 09:19:47 -05:00
коммит произвёл GitHub
родитель d311e1bdd2
Коммит e09345798e
7 изменённых файлов: 244 добавлений и 0 удалений

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

@@ -50,6 +50,7 @@ func (api *API) InitSystem() {
api.BaseRoutes.APIRoot.Handle("/logs", api.APIHandler(postLog)).Methods("POST")
api.BaseRoutes.APIRoot.Handle("/analytics/old", api.APISessionRequired(getAnalytics)).Methods("GET")
api.BaseRoutes.APIRoot.Handle("/latest_version", api.APISessionRequired(getLatestVersion)).Methods("GET")
api.BaseRoutes.APIRoot.Handle("/redirect_location", api.APISessionRequiredTrustRequester(getRedirectLocation)).Methods("GET")
@@ -402,6 +403,27 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func getLatestVersion(c *Context, w http.ResponseWriter, r *http.Request) {
if *c.App.Config().ExperimentalSettings.RestrictSystemAdmin {
c.Err = model.NewAppError("latestVersion", "api.restricted_system_admin", nil, "", http.StatusForbidden)
return
}
resp, err := c.App.GetLatestVersion("https://api.github.com/repos/mattermost/mattermost-server/releases/latest")
if err != nil {
c.Err = err
return
}
b, jsonErr := json.Marshal(resp)
if jsonErr != nil {
c.Logger.Warn("Unable to marshal JSON for latest version.", mlog.Err(jsonErr))
w.WriteHeader(http.StatusInternalServerError)
}
w.Write(b)
}
func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
supportedTimezones := c.App.Timezones().GetSupported()
if supportedTimezones == nil {