// SPDX-License-Identifier: AGPL-3.0
import { Dispatch } from "redux";
-import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
-import { RootState } from '~/store/store';
-import { getUserUuid } from "~/common/getuser";
-import { ServiceRepository } from "~/services/services";
-import { dialogActions } from '~/store/dialog/dialog-actions';
+import { bindDataExplorerActions } from 'store/data-explorer/data-explorer-action';
+import { RootState } from 'store/store';
+import { getUserUuid } from "common/getuser";
+import { ServiceRepository } from "services/services";
+import { dialogActions } from 'store/dialog/dialog-actions';
import { startSubmit, reset } from "redux-form";
-import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
-import { UserResource } from "~/models/user";
-import { getResource } from '~/store/resources/resources';
-import { navigateTo, navigateToUsers, navigateToRootProject } from "~/store/navigation/navigation-action";
-import { authActions } from '~/store/auth/auth-action';
+import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
+import { UserResource } from "models/user";
+import { getResource } from 'store/resources/resources';
+import { navigateTo, navigateToUsers, navigateToRootProject } from "store/navigation/navigation-action";
+import { authActions } from 'store/auth/auth-action';
+import { getTokenV2 } from "models/api-client-authorization";
export const USERS_PANEL_ID = 'usersPanel';
export const USER_ATTRIBUTES_DIALOG = 'userAttributesDialog';
groupVirtualMachine: string;
}
+export interface SetupShellAccountFormDialogData {
+ email: string;
+ virtualMachineName: string;
+ groupVirtualMachine: string;
+}
+
export const openUserAttributes = (uuid: string) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
const { resources } = getState();
const data = getResource<UserResource>(uuid)(resources);
const client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid });
if (data) {
- dispatch<any>(authActions.INIT({ user: data, token: `v2/${client.uuid}/${client.apiToken}` }));
- location.reload();
+ dispatch<any>(authActions.INIT_USER({ user: data, token: getTokenV2(client) }));
+ window.location.reload();
dispatch<any>(navigateToRootProject);
}
};
export const openUserCreateDialog = () =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
const userUuid = getUserUuid(getState());
+ if (!userUuid) { return; }
const user = await services.userService.get(userUuid!);
const virtualMachines = await services.virtualMachineService.list();
dispatch(reset(USER_CREATE_FORM_NAME));
}
};
+
+export const setupUserVM = (setupData: SetupShellAccountFormDialogData) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(startSubmit(USER_CREATE_FORM_NAME));
+ try {
+ // TODO: make correct API call
+ // const setupResult = await services.userService.setup({ ...setupData });
+ dispatch(dialogActions.CLOSE_DIALOG({ id: SETUP_SHELL_ACCOUNT_DIALOG }));
+ dispatch(reset(SETUP_SHELL_ACCOUNT_DIALOG));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: "User has been added to VM.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
+ dispatch<any>(loadUsersPanel());
+ dispatch(userBindedActions.REQUEST_ITEMS());
+ } catch (e) {
+ return;
+ }
+ };
+
export const openUserPanel = () =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
const user = getState().auth.user;
export const loadUsersData = () =>
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- await services.userService.list();
+ await services.userService.list({ count: "none" });
};
export const loadUsersPanel = () =>