Skip to content

Commit 7d50aaf

Browse files
committed
Redux Actions & States Updates for multi-group impersonation
1 parent 7d55aa7 commit 7d50aaf

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

frontend/public/actions/ui.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ export const setActiveNamespace = (namespace: string = '') => {
214214
return action(ActionType.SetActiveNamespace, { namespace });
215215
};
216216

217-
export const startImpersonate = (kind: string, name: string) => async (dispatch, getState) => {
217+
export const startImpersonate = (kind: string, name: string, groups?: string[]) => async (
218+
dispatch,
219+
getState,
220+
) => {
218221
const textEncoder = new TextEncoder();
219222

220223
const imp = getImpersonate(getState());
@@ -235,12 +238,24 @@ export const startImpersonate = (kind: string, name: string) => async (dispatch,
235238
let subprotocols;
236239
if (kind === 'User') {
237240
subprotocols = [`Impersonate-User.${encodedName}`];
238-
}
239-
if (kind === 'Group') {
241+
} else if (kind === 'Group') {
240242
subprotocols = [`Impersonate-Group.${encodedName}`];
243+
} else if (kind === 'UserWithGroups' && groups && groups.length > 0) {
244+
// User with multiple groups impersonation
245+
// Encode user subprotocol
246+
subprotocols = [`Impersonate-User.${encodedName}`];
247+
// Encode each group as a separate subprotocol
248+
groups.forEach((group) => {
249+
const encodedGroup = Base64.encode(
250+
String.fromCharCode.apply(String, textEncoder.encode(group)),
251+
)
252+
.replace(/=/g, '_')
253+
.replace(/\//g, '-');
254+
subprotocols.push(`Impersonate-Group.${encodedGroup}`);
255+
});
241256
}
242257

243-
dispatch(beginImpersonate(kind, name, subprotocols));
258+
dispatch(beginImpersonate(kind, name, subprotocols, groups));
244259
subsClient.close(false, true);
245260
dispatch(clearSSARFlags());
246261
dispatch(detectFeatures());

frontend/public/redux.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,12 @@ if (process.env.NODE_ENV !== 'production') {
5959
window.store = store;
6060
}
6161

62+
// Temporary: Expose store for testing multi-group impersonation
63+
// TODO: Remove this after testing. This SHOULD NOT BE IN MERGED in production!!!!!
64+
(window as any).store = store;
65+
66+
// Expose UI actions for testing
67+
import * as UIActions from './actions/ui';
68+
(window as any).UIActions = UIActions;
69+
6270
export default store;

0 commit comments

Comments
 (0)