[MM-63772] Add LDAP setting to re-add removed members (#30787)

Этот коммит содержится в:
Ben Schumacher
2025-05-20 11:15:25 +02:00
коммит произвёл GitHub
родитель 5021fc72c6
Коммит c2d08b7540
22 изменённых файлов: 143 добавлений и 101 удалений

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

@@ -97,7 +97,7 @@ type Client interface {
PatchConfig(context.Context, *model.Config) (*model.Config, *model.Response, error)
ReloadConfig(ctx context.Context) (*model.Response, error)
MigrateConfig(ctx context.Context, from, to string) (*model.Response, error)
SyncLdap(ctx context.Context, includeRemovedMembers bool) (*model.Response, error)
SyncLdap(ctx context.Context, reAddRemovedMembers *bool) (*model.Response, error)
MigrateIdLdap(ctx context.Context, toAttribute string) (*model.Response, error)
GetUsers(ctx context.Context, page, perPage int, etag string) ([]*model.User, *model.Response, error)
UpdateUserActive(ctx context.Context, userID string, activate bool) (*model.Response, error)

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

@@ -20,12 +20,22 @@ var LdapCmd = &cobra.Command{
Short: "LDAP related utilities",
}
var LdapSyncCmd = &cobra.Command{
Use: "sync",
Short: "Synchronize now",
Long: "Synchronize all LDAP users and groups now.",
Example: " ldap sync",
RunE: withClient(ldapSyncCmdF),
func newLDAPSyncCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sync",
Short: "Synchronize now",
Long: "Synchronize all LDAP users and groups now.",
Example: " ldap sync",
RunE: withClient(ldapSyncCmdF),
}
cmd.Flags().Bool("include-removed-members", false, "Include members who left or were removed from a group-synced team/channel")
err := cmd.Flags().MarkDeprecated("include-removed-members", "This flag is deprecated and will be removed in a future version. Use LdapSettings.ReAddRemovedMembers instead.")
if err != nil {
panic(err)
}
return cmd
}
var LdapIDMigrate = &cobra.Command{
@@ -68,7 +78,7 @@ var LdapJobShowCmd = &cobra.Command{
}
func init() {
LdapSyncCmd.Flags().Bool("include-removed-members", false, "Include members who left or were removed from a group-synced team/channel")
ldapSyncCmd := newLDAPSyncCmd()
LdapJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of import jobs")
LdapJobListCmd.Flags().Int("per-page", 200, "Number of import jobs to be fetched")
@@ -80,7 +90,7 @@ func init() {
)
LdapCmd.AddCommand(
LdapSyncCmd,
ldapSyncCmd,
LdapIDMigrate,
LdapJobCmd,
)
@@ -90,9 +100,14 @@ func init() {
func ldapSyncCmdF(c client.Client, cmd *cobra.Command, args []string) error {
printer.SetSingle(true)
includeRemovedMembers, _ := cmd.Flags().GetBool("include-removed-members")
resp, err := c.SyncLdap(context.TODO(), includeRemovedMembers)
var resp *model.Response
var err error
if cmd.Flags().Changed("include-removed-members") {
reAddRemovedMembers, _ := cmd.Flags().GetBool("include-removed-members")
resp, err = c.SyncLdap(context.TODO(), &reAddRemovedMembers)
} else {
resp, err = c.SyncLdap(context.TODO(), nil)
}
if err != nil {
return err
}

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

@@ -22,7 +22,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.client.
EXPECT().
SyncLdap(context.TODO(), false).
SyncLdap(context.TODO(), nil).
Return(&model.Response{StatusCode: http.StatusOK}, nil).
Times(1)
@@ -39,7 +39,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.client.
EXPECT().
SyncLdap(context.TODO(), false).
SyncLdap(context.TODO(), nil).
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
Times(1)
@@ -56,7 +56,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.client.
EXPECT().
SyncLdap(context.TODO(), false).
SyncLdap(context.TODO(), nil).
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
Times(1)
@@ -67,18 +67,20 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.Require().Len(printer.GetErrorLines(), 0)
})
s.Run("Sync with includeRemoveMembers", func() {
s.Run("Sync with deprecated includeRemoveMembers", func() {
printer.Clean()
cmd := &cobra.Command{}
cmd.Flags().Bool("include-removed-members", true, "")
cmd := newLDAPSyncCmd()
err := cmd.ParseFlags([]string{"--include-removed-members"})
s.Require().Nil(err)
s.client.
EXPECT().
SyncLdap(context.TODO(), true).
SyncLdap(context.TODO(), model.NewPointer(true)).
Return(&model.Response{StatusCode: http.StatusOK}, nil).
Times(1)
err := ldapSyncCmdF(s.client, cmd, []string{})
err = ldapSyncCmdF(s.client, cmd, []string{})
s.Require().Nil(err)
})
}

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

@@ -27,8 +27,7 @@ Options
::
-h, --help help for sync
--include-removed-members Include members who left or were removed from a group-synced team/channel
-h, --help help for sync
Options inherited from parent commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

@@ -2074,7 +2074,7 @@ func (mr *MockClientMockRecorder) SoftDeleteTeam(arg0, arg1 interface{}) *gomock
}
// SyncLdap mocks base method.
func (m *MockClient) SyncLdap(arg0 context.Context, arg1 bool) (*model.Response, error) {
func (m *MockClient) SyncLdap(arg0 context.Context, arg1 *bool) (*model.Response, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SyncLdap", arg0, arg1)
ret0, _ := ret[0].(*model.Response)