[MM-64630] Fix an issue where multiple channels can't be removed from policies (#32164)
* Fix an issue where multiple channels can't be removed from policies * actually fix the issue * use hardcoded limit * simplify removal
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d8758f8984
Коммит
0809ce7a62
@@ -183,6 +183,7 @@ func (a *App) UnassignPoliciesFromChannels(rctx request.CTX, policyID string, ch
|
||||
cps, _, err := a.Srv().Store().AccessControlPolicy().SearchPolicies(rctx, model.AccessControlPolicySearch{
|
||||
Type: model.AccessControlPolicyTypeChannel,
|
||||
ParentID: policyID,
|
||||
Limit: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
return model.NewAppError("UnassignPoliciesFromChannels", "app.pap.unassign_access_control_policy_from_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -341,7 +341,7 @@ func TestAssignAccessControlPolicyToChannels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnAssignPoliciesFromChannels(t *testing.T) {
|
||||
func TestUnassignPoliciesFromChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
|
||||
@@ -142,7 +142,6 @@ exports[`components/admin_console/access_control/policy_details/PolicyDetails sh
|
||||
channelsToAdd={Object {}}
|
||||
channelsToRemove={Object {}}
|
||||
onRemoveCallback={[Function]}
|
||||
onUndoRemoveCallback={[Function]}
|
||||
policyId="policy1"
|
||||
/>
|
||||
</CardBody>
|
||||
@@ -346,7 +345,6 @@ exports[`components/admin_console/access_control/policy_details/PolicyDetails sh
|
||||
channelsToAdd={Object {}}
|
||||
channelsToRemove={Object {}}
|
||||
onRemoveCallback={[Function]}
|
||||
onUndoRemoveCallback={[Function]}
|
||||
policyId=""
|
||||
/>
|
||||
</CardBody>
|
||||
|
||||
@@ -30,7 +30,6 @@ type Props = {
|
||||
filters: ChannelSearchOpts;
|
||||
policyId?: string;
|
||||
onRemoveCallback: (channel: ChannelWithTeamData) => void;
|
||||
onUndoRemoveCallback: (channel: ChannelWithTeamData) => void;
|
||||
channelsToRemove: Record<string, ChannelWithTeamData>;
|
||||
channelsToAdd: Record<string, ChannelWithTeamData>;
|
||||
actions: {
|
||||
@@ -196,16 +195,9 @@ export default class ChannelList extends React.PureComponent<Props, State> {
|
||||
};
|
||||
|
||||
private removeChannel = (channel: ChannelWithTeamData) => {
|
||||
const {channelsToRemove, onRemoveCallback, onUndoRemoveCallback} = this.props;
|
||||
const {onRemoveCallback} = this.props;
|
||||
const {page} = this.state;
|
||||
|
||||
// Toggle between adding and removing the channel
|
||||
if (channelsToRemove[channel.id] === channel) {
|
||||
// If the channel is already marked for removal, undo it
|
||||
onUndoRemoveCallback(channel);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the channel is not marked for removal, mark it
|
||||
onRemoveCallback(channel);
|
||||
|
||||
|
||||
@@ -279,38 +279,31 @@ function PolicyDetails({
|
||||
}
|
||||
};
|
||||
|
||||
const handleChannelChanges = (channels: ChannelWithTeamData[], isAdding: boolean) => {
|
||||
const addToNewChannels = (channels: ChannelWithTeamData[]) => {
|
||||
setChannelChanges((prev) => {
|
||||
const newChanges = cloneDeep(prev);
|
||||
|
||||
channels.forEach((channel) => {
|
||||
if (isAdding) {
|
||||
if (newChanges.removed[channel.id]) {
|
||||
delete newChanges.removed[channel.id];
|
||||
newChanges.removedCount--;
|
||||
} else {
|
||||
newChanges.added[channel.id] = channel;
|
||||
}
|
||||
} else if (newChanges.added[channel.id]) {
|
||||
delete newChanges.added[channel.id];
|
||||
} else if (!newChanges.removed[channel.id]) {
|
||||
newChanges.removedCount++;
|
||||
newChanges.removed[channel.id] = channel;
|
||||
channels.forEach((channel: ChannelWithTeamData) => {
|
||||
if (newChanges.removed[channel.id]?.id === channel.id) {
|
||||
delete newChanges.removed[channel.id];
|
||||
newChanges.removedCount--;
|
||||
} else {
|
||||
newChanges.added[channel.id] = channel;
|
||||
}
|
||||
});
|
||||
|
||||
return newChanges;
|
||||
});
|
||||
setSaveNeeded(true);
|
||||
actions.setNavigationBlocked(true);
|
||||
};
|
||||
|
||||
const handleUndoRemove = (channel: ChannelWithTeamData) => {
|
||||
const addToRemovedChannels = (channel: ChannelWithTeamData) => {
|
||||
setChannelChanges((prev) => {
|
||||
const newChanges = cloneDeep(prev);
|
||||
if (newChanges.removed[channel.id]) {
|
||||
delete newChanges.removed[channel.id];
|
||||
newChanges.removedCount--;
|
||||
if (newChanges.added[channel.id]?.id === channel.id) {
|
||||
delete newChanges.added[channel.id];
|
||||
} else if (newChanges.removed[channel.id]?.id !== channel.id) {
|
||||
newChanges.removedCount++;
|
||||
newChanges.removed[channel.id] = channel;
|
||||
}
|
||||
return newChanges;
|
||||
});
|
||||
@@ -518,8 +511,7 @@ function PolicyDetails({
|
||||
</Card.Header>
|
||||
<Card.Body expanded={true}>
|
||||
<ChannelList
|
||||
onRemoveCallback={(channel) => handleChannelChanges([channel], false)}
|
||||
onUndoRemoveCallback={handleUndoRemove}
|
||||
onRemoveCallback={(channel) => addToRemovedChannels(channel)}
|
||||
channelsToRemove={channelChanges.removed}
|
||||
channelsToAdd={channelChanges.added}
|
||||
policyId={policyId}
|
||||
@@ -575,7 +567,7 @@ function PolicyDetails({
|
||||
{addChannelOpen && (
|
||||
<ChannelSelectorModal
|
||||
onModalDismissed={() => setAddChannelOpen(false)}
|
||||
onChannelsSelected={(channels) => handleChannelChanges(channels, true)}
|
||||
onChannelsSelected={(channels) => addToNewChannels(channels)}
|
||||
groupID={''}
|
||||
alreadySelected={Object.values(channelChanges.added).map((channel) => channel.id)}
|
||||
excludeAccessControlPolicyEnforced={true}
|
||||
|
||||
Ссылка в новой задаче
Block a user