[MM-33908] Resync LDAP Groups to Teams and Channels (#17372)
* add includeRemovedMembers flag * fix API call in client4.go * remove check for 'since' * add comments * run make app-layers * re-run CI tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3e5b0a7d7f
Коммит
9f4902e188
@@ -247,7 +247,7 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType)
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType, false)
|
||||
})
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
@@ -408,7 +408,7 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("new_syncable_type", groupSyncable.Type)
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType)
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType, false)
|
||||
})
|
||||
|
||||
b, marshalErr := json.Marshal(groupSyncable)
|
||||
@@ -462,7 +462,7 @@ func unlinkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType)
|
||||
c.App.SyncRolesAndMembership(syncableID, syncableType, false)
|
||||
})
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
@@ -47,6 +47,12 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
type LdapSyncOptions struct {
|
||||
IncludeRemovedMembers bool `json:"include_removed_members"`
|
||||
}
|
||||
var opts LdapSyncOptions
|
||||
json.NewDecoder(r.Body).Decode(&opts)
|
||||
|
||||
auditRec := c.MakeAuditRecord("syncLdap", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
@@ -55,7 +61,7 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SyncLdap()
|
||||
c.App.SyncLdap(opts.IncludeRemovedMembers)
|
||||
|
||||
auditRec.Success()
|
||||
ReturnStatusOK(w)
|
||||
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest/mock"
|
||||
)
|
||||
|
||||
var spPrivateKey = `-----BEGIN PRIVATE KEY-----
|
||||
@@ -134,13 +136,37 @@ func TestSyncLdap(t *testing.T) {
|
||||
})
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("ldap_groups"))
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp := client.SyncLdap()
|
||||
CheckNoError(t, resp)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LdapSettings.EnableSync = true
|
||||
})
|
||||
|
||||
_, resp := th.Client.SyncLdap()
|
||||
ldapMock := &mocks.LdapInterface{}
|
||||
mockCall := ldapMock.On(
|
||||
"StartSynchronizeJob",
|
||||
mock.AnythingOfType("bool"),
|
||||
mock.AnythingOfType("bool"),
|
||||
).Return(nil, nil)
|
||||
ready := make(chan bool)
|
||||
includeRemovedMembers := false
|
||||
mockCall.RunFn = func(args mock.Arguments) {
|
||||
includeRemovedMembers = args[1].(bool)
|
||||
ready <- true
|
||||
}
|
||||
th.App.Srv().Ldap = ldapMock
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp := client.SyncLdap(false)
|
||||
<-ready
|
||||
CheckNoError(t, resp)
|
||||
require.Equal(t, false, includeRemovedMembers)
|
||||
|
||||
_, resp = client.SyncLdap(true)
|
||||
<-ready
|
||||
CheckNoError(t, resp)
|
||||
require.Equal(t, true, includeRemovedMembers)
|
||||
})
|
||||
|
||||
_, resp := th.Client.SyncLdap(false)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user