github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/api4/ldap.go (about)

     1  // Copyright (c) 2015-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/vnforks/kid/v5/audit"
    10  	"github.com/vnforks/kid/v5/model"
    11  )
    12  
    13  type mixedUnlinkedGroup struct {
    14  	Id           *string `json:"mattermost_group_id"`
    15  	DisplayName  string  `json:"name"`
    16  	RemoteId     string  `json:"primary_key"`
    17  	HasSyncables *bool   `json:"has_syncables"`
    18  }
    19  
    20  func (api *API) InitLdap() {
    21  	api.BaseRoutes.LDAP.Handle("/sync", api.ApiSessionRequired(syncLdap)).Methods("POST")
    22  	api.BaseRoutes.LDAP.Handle("/test", api.ApiSessionRequired(testLdap)).Methods("POST")
    23  
    24  }
    25  
    26  func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
    27  	if c.App.License() == nil || !*c.App.License().Features.LDAP {
    28  		c.Err = model.NewAppError("Api4.syncLdap", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
    29  		return
    30  	}
    31  
    32  	auditRec := c.MakeAuditRecord("syncLdap", audit.Fail)
    33  	defer c.LogAuditRec(auditRec)
    34  
    35  	if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
    36  		c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
    37  		return
    38  	}
    39  
    40  	c.App.SyncLdap()
    41  
    42  	auditRec.Success()
    43  	ReturnStatusOK(w)
    44  }
    45  
    46  func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
    47  	if c.App.License() == nil || !*c.App.License().Features.LDAP {
    48  		c.Err = model.NewAppError("Api4.testLdap", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
    49  		return
    50  	}
    51  
    52  	if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
    53  		c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
    54  		return
    55  	}
    56  
    57  	if err := c.App.TestLdap(); err != nil {
    58  		c.Err = err
    59  		return
    60  	}
    61  
    62  	ReturnStatusOK(w)
    63  }