[MM-63504] When changing a channel to group synced, it doesn't always clear members (#30526)
* fix issue with channel and team membership after group constraints are enabled
Этот коммит содержится в:
@@ -142,12 +142,12 @@ func (a *App) CreateDefaultMemberships(rctx request.CTX, params model.CreateDefa
|
||||
// DeleteGroupConstrainedMemberships deletes team and channel memberships of users who aren't members of the allowed
|
||||
// groups of all group-constrained teams and channels.
|
||||
func (a *App) DeleteGroupConstrainedMemberships(rctx request.CTX) error {
|
||||
err := a.deleteGroupConstrainedChannelMemberships(rctx, nil)
|
||||
err := a.DeleteGroupConstrainedChannelMemberships(rctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.deleteGroupConstrainedTeamMemberships(rctx, nil)
|
||||
err = a.DeleteGroupConstrainedTeamMemberships(rctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -155,10 +155,10 @@ func (a *App) DeleteGroupConstrainedMemberships(rctx request.CTX) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteGroupConstrainedTeamMemberships deletes team memberships of users who aren't members of the allowed
|
||||
// DeleteGroupConstrainedTeamMemberships deletes team memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained team. If a teamID is given then the procedure is scoped to the given team,
|
||||
// if teamID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedTeamMemberships(rctx request.CTX, teamID *string) error {
|
||||
func (a *App) DeleteGroupConstrainedTeamMemberships(rctx request.CTX, teamID *string) error {
|
||||
teamMembers, appErr := a.TeamMembersToRemove(teamID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -183,10 +183,10 @@ func (a *App) deleteGroupConstrainedTeamMemberships(rctx request.CTX, teamID *st
|
||||
return multiErr.ErrorOrNil()
|
||||
}
|
||||
|
||||
// deleteGroupConstrainedChannelMemberships deletes channel memberships of users who aren't members of the allowed
|
||||
// DeleteGroupConstrainedChannelMemberships deletes channel memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained channel. If a channelID is given then the procedure is scoped to the given team,
|
||||
// if channelID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedChannelMemberships(rctx request.CTX, channelID *string) error {
|
||||
func (a *App) DeleteGroupConstrainedChannelMemberships(rctx request.CTX, channelID *string) error {
|
||||
channelMembers, appErr := a.ChannelMembersToRemove(channelID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -301,16 +301,24 @@ func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncab
|
||||
if err := a.createDefaultTeamMemberships(rctx, params); err != nil {
|
||||
rctx.Logger().Warn("Error creating default team memberships", mlog.Err(err))
|
||||
}
|
||||
if err := a.deleteGroupConstrainedTeamMemberships(rctx, &syncableID); err != nil {
|
||||
rctx.Logger().Warn("Error deleting group constrained team memberships", mlog.Err(err))
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
params.ScopedChannelID = &syncableID
|
||||
if err := a.createDefaultChannelMemberships(rctx, params); err != nil {
|
||||
rctx.Logger().Warn("Error creating default channel memberships", mlog.Err(err))
|
||||
}
|
||||
if err := a.deleteGroupConstrainedChannelMemberships(rctx, &syncableID); err != nil {
|
||||
}
|
||||
}
|
||||
|
||||
// This method should be called when a syncable is unlinked from a group
|
||||
func (a *App) RemoveMembershipsFromUnlinkedSyncable(rctx request.CTX, syncableID string, syncableType model.GroupSyncableType) {
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
if err := a.DeleteGroupConstrainedTeamMemberships(rctx, &syncableID); err != nil {
|
||||
rctx.Logger().Warn("Error deleting group constrained team memberships", mlog.Err(err))
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
if err := a.DeleteGroupConstrainedChannelMemberships(rctx, &syncableID); err != nil {
|
||||
rctx.Logger().Warn("Error deleting group constrained channel memberships", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user