2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
2017-03-14 08:43:40 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-03-14 08:43:40 -04:00
|
|
|
)
|
|
|
|
|
|
2017-09-22 12:54:27 -05:00
|
|
|
func (api *API) InitLdap() {
|
|
|
|
|
api.BaseRoutes.LDAP.Handle("/sync", api.ApiSessionRequired(syncLdap)).Methods("POST")
|
|
|
|
|
api.BaseRoutes.LDAP.Handle("/test", api.ApiSessionRequired(testLdap)).Methods("POST")
|
2017-03-14 08:43:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
2017-10-25 11:48:15 -07:00
|
|
|
if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
2017-03-14 08:43:40 -04:00
|
|
|
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 18:31:35 -05:00
|
|
|
c.App.SyncLdap()
|
2017-03-14 08:43:40 -04:00
|
|
|
|
|
|
|
|
ReturnStatusOK(w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
2017-10-25 11:48:15 -07:00
|
|
|
if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
2017-03-14 08:43:40 -04:00
|
|
|
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-19 18:31:35 -05:00
|
|
|
if err := c.App.TestLdap(); err != nil {
|
2017-03-14 08:43:40 -04:00
|
|
|
c.Err = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReturnStatusOK(w)
|
|
|
|
|
}
|