summaryrefslogtreecommitdiffstats
path: root/api4/team.go
diff options
context:
space:
mode:
authorMartin Kraft <mkraft@users.noreply.github.com>2018-05-02 07:31:14 -0400
committerGitHub <noreply@github.com>2018-05-02 07:31:14 -0400
commitf4dcb4edf2aafca85c9af631131a77888da24bc7 (patch)
tree83d507f4a06d84227ffa9dc8d28b098908853305 /api4/team.go
parentd2cc0c5834d6849f2fdb1e343ed5e193b742fa2f (diff)
downloadchat-f4dcb4edf2aafca85c9af631131a77888da24bc7.tar.gz
chat-f4dcb4edf2aafca85c9af631131a77888da24bc7.tar.bz2
chat-f4dcb4edf2aafca85c9af631131a77888da24bc7.zip
MM-10182 & MM-10183: Adds channel scheme and team scheme API endpoint. (#8680)
* MM-10183: Adds channel scheme API endpoint. MM-10182: Adds team scheme API endpoint. MM-10182_3: Switch from scheme_id in path to body. * MM-10182/MM-10183: Changes path from 'schemes' to 'scheme'. * MM-10182: Fix merge error.
Diffstat (limited to 'api4/team.go')
-rw-r--r--api4/team.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/api4/team.go b/api4/team.go
index 023289579..1c2e9514e 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -20,6 +20,7 @@ const (
func (api *API) InitTeam() {
api.BaseRoutes.Teams.Handle("", api.ApiSessionRequired(createTeam)).Methods("POST")
api.BaseRoutes.Teams.Handle("", api.ApiSessionRequired(getAllTeams)).Methods("GET")
+ api.BaseRoutes.Teams.Handle("/{team_id:[A-Za-z0-9]+}/scheme", api.ApiSessionRequired(updateTeamScheme)).Methods("PUT")
api.BaseRoutes.Teams.Handle("/search", api.ApiSessionRequired(searchTeams)).Methods("POST")
api.BaseRoutes.TeamsForUser.Handle("", api.ApiSessionRequired(getTeamsForUser)).Methods("GET")
api.BaseRoutes.TeamsForUser.Handle("/unread", api.ApiSessionRequired(getTeamsUnreadForUser)).Methods("GET")
@@ -833,3 +834,53 @@ func removeTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
ReturnStatusOK(w)
}
+
+func updateTeamScheme(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireTeamId()
+ if c.Err != nil {
+ return
+ }
+
+ schemeID := model.SchemeIDFromJson(r.Body)
+ if schemeID == nil || len(*schemeID) != 26 {
+ c.SetInvalidParam("scheme_id")
+ return
+ }
+
+ if c.App.License() == nil {
+ c.Err = model.NewAppError("Api4.UpdateTeamScheme", "api.team.update_team_scheme.license.error", nil, "", http.StatusNotImplemented)
+ return
+ }
+
+ if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
+ return
+ }
+
+ scheme, err := c.App.GetScheme(*schemeID)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ if scheme.Scope != model.SCHEME_SCOPE_TEAM {
+ c.Err = model.NewAppError("Api4.UpdateTeamScheme", "api.team.update_team_scheme.scheme_scope.error", nil, "", http.StatusBadRequest)
+ return
+ }
+
+ team, err := c.App.GetTeam(c.Params.TeamId)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ team.SchemeId = &scheme.Id
+
+ _, err = c.App.UpdateTeamScheme(team)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ ReturnStatusOK(w)
+}