summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-06-28 20:11:33 -0400
committerCorey Hulen <corey@hulen.com>2016-06-28 16:11:33 -0800
commit6c5a8be6bfe1d6b9d8f71a6b0dc4d8cf93a03aab (patch)
tree450b4a8b0ef160e06a069165ef15b08b77bab016
parentb3b90a753166e1b2d6141cfd60b350bcd49c7253 (diff)
downloadchat-6c5a8be6bfe1d6b9d8f71a6b0dc4d8cf93a03aab.tar.gz
chat-6c5a8be6bfe1d6b9d8f71a6b0dc4d8cf93a03aab.tar.bz2
chat-6c5a8be6bfe1d6b9d8f71a6b0dc4d8cf93a03aab.zip
Implementing server side of LDAP sync now button (#3430)
-rw-r--r--api/admin.go21
-rw-r--r--api/admin_test.go9
-rw-r--r--model/client.go14
3 files changed, 44 insertions, 0 deletions
diff --git a/api/admin.go b/api/admin.go
index 8d9d92aa5..f0db5a4af 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -40,6 +40,7 @@ func InitAdmin() {
BaseRoutes.Admin.Handle("/get_brand_image", ApiAppHandlerTrustRequester(getBrandImage)).Methods("GET")
BaseRoutes.Admin.Handle("/reset_mfa", ApiAdminSystemRequired(adminResetMfa)).Methods("POST")
BaseRoutes.Admin.Handle("/reset_password", ApiAdminSystemRequired(adminResetPassword)).Methods("POST")
+ BaseRoutes.Admin.Handle("/ldap_sync_now", ApiAdminSystemRequired(ldapSyncNow)).Methods("POST")
}
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -561,3 +562,23 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
rdata["status"] = "ok"
w.Write([]byte(model.MapToJson(rdata)))
}
+
+func ldapSyncNow(c *Context, w http.ResponseWriter, r *http.Request) {
+ go func() {
+ if utils.IsLicensed && *utils.License.Features.LDAP && *utils.Cfg.LdapSettings.Enable {
+ if ldapI := einterfaces.GetLdapInterface(); ldapI != nil {
+ if err := ldapI.Syncronize(); err != nil {
+ l4g.Error("%v", err.Error())
+ } else {
+ l4g.Info(utils.T("ent.ldap.syncdone.info"))
+ }
+ } else {
+ l4g.Error("%v", model.NewLocAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "").Error())
+ }
+ }
+ }()
+
+ rdata := map[string]string{}
+ rdata["status"] = "ok"
+ w.Write([]byte(model.MapToJson(rdata)))
+}
diff --git a/api/admin_test.go b/api/admin_test.go
index 2b45fd30a..0a3048c52 100644
--- a/api/admin_test.go
+++ b/api/admin_test.go
@@ -493,3 +493,12 @@ func TestAdminResetPassword(t *testing.T) {
t.Fatal("Should have errored - not sytem admin")
}
}
+
+func TestAdminLdapSyncNow(t *testing.T) {
+ th := Setup().InitSystemAdmin()
+ Client := th.SystemAdminClient
+
+ if _, err := Client.LdapSyncNow(); err != nil {
+ t.Fatal("Returned Failure")
+ }
+}
diff --git a/model/client.go b/model/client.go
index 80ab42dc4..8ed221627 100644
--- a/model/client.go
+++ b/model/client.go
@@ -860,6 +860,20 @@ func (c *Client) GetSystemAnalytics(name string) (*Result, *AppError) {
}
}
+// Initiate immediate synchronization of LDAP users.
+// The synchronization will be performed asynchronously and this function will
+// always return OK unless you don't have permissions.
+// You must be the system administrator to use this function.
+func (c *Client) LdapSyncNow() (*Result, *AppError) {
+ if r, err := c.DoApiPost("/admin/ldap_sync_now", ""); err != nil {
+ return nil, err
+ } else {
+ defer closeBody(r)
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) CreateChannel(channel *Channel) (*Result, *AppError) {
if r, err := c.DoApiPost(c.GetTeamRoute()+"/channels/create", channel.ToJson()); err != nil {
return nil, err