Skip to content

Commit

Permalink
Fix removing service-account from group
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Apr 11, 2024
1 parent 8a2d65c commit bd41bef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
8 changes: 2 additions & 6 deletions src/helpers/group/group-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ export async function addServiceAccountsToGroup(groupId, serviceAccounts) {
});
}

export async function removeServiceAccountsFromGroup(groupId, serviceAccounts) {
return await groupApi.deletePrincipalFromGroup(groupId, '', {
query: {
'service-accounts': serviceAccounts.map(({ clientID }) => `service-account-${clientID}`).join(','),
},
});
export async function removeServiceAccountsFromGroup(groupId, serviceAccountsIds) {
return await groupApi.deletePrincipalFromGroup(groupId, undefined, serviceAccountsIds.map((clientID) => `service-account-${clientID}`).join(','));
}

export async function fetchAccountsForGroup(groupId, options = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/service-account/service-account-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ServiceAccountPayloadItem {

export interface ServiceAccount {
uuid: string;
clientId: string;
clientID: string;
name: string;
description: string;
createdBy: string;
Expand All @@ -28,7 +28,7 @@ export interface ServiceAccount {
}

export interface ServiceAccountsPayload {
data: ServiceAccount[];
data: (ServiceAccount & { clientId: string })[];
status: string;
}

Expand Down
12 changes: 6 additions & 6 deletions src/redux/actions/group-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,25 @@ export const addServiceAccountsToGroup = (groupId, serviceAccounts) => {
};
};

export const removeServiceAccountFromGroup = (groupId, serviceAccounts) => {
export const removeServiceAccountFromGroup = (groupId, serviceAccountsIds) => {
const cache = createIntlCache();
const intl = createIntl({ locale, messages: providerMessages }, cache);
return {
type: ActionTypes.REMOVE_SERVICE_ACCOUNTS_FROM_GROUP,
payload: GroupHelper.removeServiceAccountsFromGroup(groupId, serviceAccounts),
payload: GroupHelper.removeServiceAccountsFromGroup(groupId, serviceAccountsIds),
meta: {
notifications: {
fulfilled: {
variant: 'success',
title: intl.formatMessage(messages.removeGroupServiceAccountsSuccessTitle, { count: serviceAccounts.length }),
title: intl.formatMessage(messages.removeGroupServiceAccountsSuccessTitle, { count: serviceAccountsIds.length }),
dismissDelay: 8000,
description: intl.formatMessage(messages.removeGroupServiceAccountsSuccessDescription, { count: serviceAccounts.length }),
description: intl.formatMessage(messages.removeGroupServiceAccountsSuccessDescription, { count: serviceAccountsIds.length }),
},
rejected: {
variant: 'danger',
title: intl.formatMessage(messages.removeGroupServiceAccountsErrorTitle, { count: serviceAccounts.length }),
title: intl.formatMessage(messages.removeGroupServiceAccountsErrorTitle, { count: serviceAccountsIds.length }),
dismissDelay: 8000,
description: intl.formatMessage(messages.removeGroupServiceAccountsErrorDescription, { count: serviceAccounts.length }),
description: intl.formatMessage(messages.removeGroupServiceAccountsErrorDescription, { count: serviceAccountsIds.length }),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/service-account-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const setServiceAccounts = (state: ServiceAccountsState, { payload, meta }: { pa
...state,
limit: meta.limit,
offset: meta.offset,
serviceAccounts: payload.data,
serviceAccounts: payload.data.map((item) => ({ ...item, clientID: item.clientId })),
status: payload.status,
isLoading: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const createRows = (data: ServiceAccount[], checkedRows: ServiceAccount[]) =>
cells: [
curr.name,
curr.description,
curr.clientId,
curr.clientID,
curr.createdBy,
<Fragment key={`${curr.name}-modified`}>
<DateFormat date={curr.createdAt} type={getDateFormat(curr.createdAt)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { useSearchParams } from 'react-router-dom';
import { ButtonVariant } from '@patternfly/react-core';
import WarningModal from '@patternfly/react-component-groups/dist/dynamic/WarningModal';
import { ServiceAccount } from '../../../helpers/service-account/service-account-helper';
import { removeServiceAccountFromGroup } from '../../../redux/actions/group-actions';
import messages from '../../../Messages';

Expand All @@ -19,16 +20,18 @@ type RBACStore = {
uuid: string;
name: string;
serviceAccounts?: {
data: { name: string }[];
data: ServiceAccount[];
};
};
};
};

const RemoveServiceAccountFromGroup: React.FunctionComponent<AddGroupServiceAccountsProps> = ({ postMethod }: AddGroupServiceAccountsProps) => {
const group = useSelector<RBACStore, { name: string; uuid: string }>(({ groupReducer: { selectedGroup } }) => selectedGroup);
const group = useSelector<RBACStore, { name: string; uuid: string; serviceAccounts?: { data: ServiceAccount[] } }>(
({ groupReducer: { selectedGroup } }) => selectedGroup
);
const [params] = useSearchParams();
const selectedServiceAccounts = useSelector<RBACStore, { name: string }[]>(({ groupReducer: { selectedGroup } }) =>
const selectedServiceAccounts = useSelector<RBACStore, ServiceAccount[]>(({ groupReducer: { selectedGroup } }) =>
(selectedGroup?.serviceAccounts?.data || []).filter(({ name }) => params.getAll('name').includes(name))
);
const accountsCount = useMemo(() => params.getAll('name').length, [params]);
Expand All @@ -44,7 +47,10 @@ const RemoveServiceAccountFromGroup: React.FunctionComponent<AddGroupServiceAcco
confirmButtonVariant={ButtonVariant.danger}
onClose={() => postMethod()}
onConfirm={() => {
const action = removeServiceAccountFromGroup(group.uuid, selectedServiceAccounts);
const action = removeServiceAccountFromGroup(
group.uuid,
selectedServiceAccounts.map((serviceAccount) => serviceAccount.clientID)
);
dispatch(action);
postMethod(action.payload);
}}
Expand Down

0 comments on commit bd41bef

Please sign in to comment.