1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from 'store/store';
7 import { setBreadcrumbs } from 'store/breadcrumbs/breadcrumbs-actions';
8 import { ServiceRepository } from "services/services";
9 import { dialogActions } from 'store/dialog/dialog-actions';
10 import { snackbarActions } from 'store/snackbar/snackbar-actions';
11 import { navigateToRootProject } from 'store/navigation/navigation-action';
12 import { ApiClientAuthorization } from 'models/api-client-authorization';
13 import { bindDataExplorerActions } from 'store/data-explorer/data-explorer-action';
14 import { getResource } from 'store/resources/resources';
17 export const API_CLIENT_AUTHORIZATION_PANEL_ID = 'apiClientAuthorizationPanelId';
18 export const apiClientAuthorizationsActions = bindDataExplorerActions(API_CLIENT_AUTHORIZATION_PANEL_ID);
20 export const API_CLIENT_AUTHORIZATION_REMOVE_DIALOG = 'apiClientAuthorizationRemoveDialog';
21 export const API_CLIENT_AUTHORIZATION_ATTRIBUTES_DIALOG = 'apiClientAuthorizationAttributesDialog';
22 export const API_CLIENT_AUTHORIZATION_HELP_DIALOG = 'apiClientAuthorizationHelpDialog';
25 export const loadApiClientAuthorizationsPanel = () =>
26 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
27 const user = getState().auth.user;
28 if (user && user.isAdmin) {
30 dispatch(setBreadcrumbs([{ label: 'Api client authorizations' }]));
31 dispatch(apiClientAuthorizationsActions.REQUEST_ITEMS());
36 dispatch(navigateToRootProject);
37 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000 }));
41 export const openApiClientAuthorizationAttributesDialog = (uuid: string) =>
42 (dispatch: Dispatch, getState: () => RootState) => {
43 const { resources } = getState();
44 const apiClientAuthorization = getResource<ApiClientAuthorization>(uuid)(resources);
45 dispatch(dialogActions.OPEN_DIALOG({ id: API_CLIENT_AUTHORIZATION_ATTRIBUTES_DIALOG, data: { apiClientAuthorization } }));
48 export const openApiClientAuthorizationRemoveDialog = (uuid: string) =>
49 (dispatch: Dispatch, getState: () => RootState) => {
50 dispatch(dialogActions.OPEN_DIALOG({
51 id: API_CLIENT_AUTHORIZATION_REMOVE_DIALOG,
53 title: 'Remove api client authorization',
54 text: 'Are you sure you want to remove this api client authorization?',
55 confirmButtonLabel: 'Remove',
61 export const removeApiClientAuthorization = (uuid: string) =>
62 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
63 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
65 await services.apiClientAuthorizationService.delete(uuid);
66 dispatch(apiClientAuthorizationsActions.REQUEST_ITEMS());
67 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Api client authorization has been successfully removed.', hideDuration: 2000 }));
73 export const openApiClientAuthorizationsHelpDialog = () =>
74 (dispatch: Dispatch, getState: () => RootState) => {
75 const apiHost = getState().properties.apiHost;
76 const user = getState().auth.user;
77 const email = user ? user.email : '';
78 const apiToken = getState().auth.apiToken;
79 dispatch(dialogActions.OPEN_DIALOG({ id: API_CLIENT_AUTHORIZATION_HELP_DIALOG, data: { apiHost, apiToken, email } }));