github.com/turgay/mattermost-server@v5.3.2-0.20181002173352-2945e8a2b0ce+incompatible/api4/ldap.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  )
    11  
    12  func (api *API) InitLdap() {
    13  	api.BaseRoutes.LDAP.Handle("/sync", api.ApiSessionRequired(syncLdap)).Methods("POST")
    14  	api.BaseRoutes.LDAP.Handle("/test", api.ApiSessionRequired(testLdap)).Methods("POST")
    15  }
    16  
    17  func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
    18  	if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
    19  		c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
    20  		return
    21  	}
    22  
    23  	c.App.SyncLdap()
    24  
    25  	ReturnStatusOK(w)
    26  }
    27  
    28  func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
    29  	if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
    30  		c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
    31  		return
    32  	}
    33  
    34  	if err := c.App.TestLdap(); err != nil {
    35  		c.Err = err
    36  		return
    37  	}
    38  
    39  	ReturnStatusOK(w)
    40  }