2022-08-10 14:20:42 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2022-09-13 12:18:40 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2022-08-10 14:20:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *API) registerLimitsRoutes(r *mux.Router) {
|
|
|
|
// limits
|
|
|
|
r.HandleFunc("/limits", a.sessionRequired(a.handleCloudLimits)).Methods("GET")
|
|
|
|
r.HandleFunc("/teams/{teamID}/notifyadminupgrade", a.sessionRequired(a.handleNotifyAdminUpgrade)).Methods(http.MethodPost)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) handleCloudLimits(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// swagger:operation GET /limits cloudLimits
|
|
|
|
//
|
|
|
|
// Fetches the cloud limits of the server.
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// security:
|
|
|
|
// - BearerAuth: []
|
|
|
|
// responses:
|
|
|
|
// '200':
|
|
|
|
// description: success
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/BoardsCloudLimits"
|
|
|
|
// default:
|
|
|
|
// description: internal error
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/ErrorResponse"
|
|
|
|
|
|
|
|
boardsCloudLimits, err := a.app.GetBoardsCloudLimits()
|
|
|
|
if err != nil {
|
2022-09-13 12:18:40 +02:00
|
|
|
a.errorResponse(w, r, err)
|
2022-08-10 14:20:42 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(boardsCloudLimits)
|
|
|
|
if err != nil {
|
2022-09-13 12:18:40 +02:00
|
|
|
a.errorResponse(w, r, err)
|
2022-08-10 14:20:42 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonBytesResponse(w, http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) handleNotifyAdminUpgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// swagger:operation GET /api/v2/teams/{teamID}/notifyadminupgrade handleNotifyAdminUpgrade
|
|
|
|
//
|
|
|
|
// Notifies admins for upgrade request.
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
2022-09-07 16:32:53 +02:00
|
|
|
// parameters:
|
|
|
|
// - name: teamID
|
|
|
|
// in: path
|
|
|
|
// description: Team ID
|
|
|
|
// required: true
|
|
|
|
// type: string
|
2022-08-10 14:20:42 +02:00
|
|
|
// security:
|
|
|
|
// - BearerAuth: []
|
|
|
|
// responses:
|
|
|
|
// '200':
|
|
|
|
// description: success
|
|
|
|
// default:
|
|
|
|
// description: internal error
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/ErrorResponse"
|
|
|
|
|
|
|
|
if !a.MattermostAuth {
|
2022-09-13 12:18:40 +02:00
|
|
|
a.errorResponse(w, r, model.NewErrNotImplemented("not permitted in standalone mode"))
|
2022-08-10 14:20:42 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
teamID := vars["teamID"]
|
|
|
|
|
|
|
|
if err := a.app.NotifyPortalAdminsUpgradeRequest(teamID); err != nil {
|
|
|
|
jsonStringResponse(w, http.StatusOK, "{}")
|
|
|
|
}
|
|
|
|
}
|