[MM-25651] api4/ldap: add migrateid (#14794)

* api4/ldap: add idmigrate

* api4/ldap: add migrateid to local api

* api4/ldap: improve migrate test

* api4/ldap: add licence check
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-07-14 15:59:35 +03:00
коммит произвёл GitHub
родитель e980dd7bd3
Коммит ec78168242
8 изменённых файлов: 102 добавлений и 0 удалений

Просмотреть файл

@@ -22,6 +22,7 @@ type mixedUnlinkedGroup struct {
func (api *API) InitLdap() {
api.BaseRoutes.LDAP.Handle("/sync", api.ApiSessionRequired(syncLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/test", api.ApiSessionRequired(testLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/migrateid", api.ApiSessionRequired(migrateIdLdap)).Methods("POST")
// GET /api/v4/ldap/groups?page=0&per_page=1000
api.BaseRoutes.LDAP.Handle("/groups", api.ApiSessionRequired(getLdapGroups)).Methods("GET")
@@ -259,3 +260,33 @@ func unlinkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
ReturnStatusOK(w)
}
func migrateIdLdap(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
toAttribute, ok := props["toAttribute"].(string)
if !ok || len(toAttribute) == 0 {
c.SetInvalidParam("toAttribute")
return
}
auditRec := c.MakeAuditRecord("idMigrateLdap", audit.Fail)
defer c.LogAuditRec(auditRec)
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
if c.App.Srv().License() == nil || !*c.App.Srv().License().Features.LDAP {
c.Err = model.NewAppError("Api4.idMigrateLdap", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
return
}
if err := c.App.MigrateIdLDAP(toAttribute); err != nil {
c.Err = err
return
}
auditRec.Success()
ReturnStatusOK(w)
}

Просмотреть файл

@@ -4,6 +4,7 @@
package api4
func (api *API) InitLdapLocal() {
api.BaseRoutes.LDAP.Handle("/migrateid", api.ApiLocal(migrateIdLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/sync", api.ApiLocal(syncLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/test", api.ApiLocal(testLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/groups", api.ApiLocal(getLdapGroups)).Methods("GET")

Просмотреть файл

@@ -96,3 +96,19 @@ func TestUnlinkLdapGroup(t *testing.T) {
_, resp = th.SystemAdminClient.UnlinkLdapGroup(entryUUID)
CheckNotImplementedStatus(t, resp)
}
func TestMigrateIdLdap(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
_, resp := th.Client.MigrateIdLdap("objectGUID")
CheckForbiddenStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp = client.MigrateIdLdap("")
CheckBadRequestStatus(t, resp)
_, resp = client.MigrateIdLdap("objectGUID")
CheckNotImplementedStatus(t, resp)
})
}