* Prevent cloud limited installations from restoring teams when at or above the teams limit * Code clean up * fix i18n * Actually fix i18n * updates for govet * Update model/client4.go Co-authored-by: Vishal <vish9812@gmail.com> * [MM-44397] Restrict team creation based on subscription limits (#20282) * restrict team creation based on limits * Update api4/team.go Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * Fix tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * Add additional field to teamsusage * Fix * remove useless test * Fix error for team creation * Remove apostrophe Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Vishal <vish9812@gmail.com> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
83 строки
2.5 KiB
Go
83 строки
2.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
func (api *API) InitUsage() {
|
|
// GET /api/v4/usage/posts
|
|
api.BaseRoutes.Usage.Handle("/posts", api.APISessionRequired(getPostsUsage)).Methods("GET")
|
|
// GET /api/v4/usage/teams
|
|
api.BaseRoutes.Usage.Handle("/teams", api.APISessionRequired(getTeamsUsage)).Methods("GET")
|
|
|
|
// GET /api/v4/usage/integrations
|
|
api.BaseRoutes.Usage.Handle("/integrations", api.APISessionRequired(getIntegrationsUsage)).Methods("GET")
|
|
}
|
|
|
|
func getPostsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
count, appErr := c.App.GetPostsUsage()
|
|
if appErr != nil {
|
|
c.Err = model.NewAppError("Api4.getPostsUsage", "app.post.analytics_posts_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
json, err := json.Marshal(&model.PostsUsage{Count: count})
|
|
if err != nil {
|
|
c.Err = model.NewAppError("Api4.getPostsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Write(json)
|
|
}
|
|
|
|
func getTeamsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
teamsUsage, appErr := c.App.GetTeamsUsage()
|
|
if appErr != nil {
|
|
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
if teamsUsage == nil {
|
|
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
json, err := json.Marshal(teamsUsage)
|
|
if err != nil {
|
|
c.Err = model.NewAppError("Api4.getTeamsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
w.Write(json)
|
|
}
|
|
|
|
func getIntegrationsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
if !*c.App.Config().PluginSettings.Enable {
|
|
json, err := json.Marshal(&model.IntegrationsUsage{})
|
|
if err != nil {
|
|
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Write(json)
|
|
return
|
|
}
|
|
|
|
usage, appErr := c.App.GetIntegrationsUsage()
|
|
if appErr != nil {
|
|
c.Err = appErr
|
|
return
|
|
}
|
|
|
|
json, err := json.Marshal(usage)
|
|
if err != nil {
|
|
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Write(json)
|
|
}
|