Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / user-action-set.ts
index 2edb12d9fdb1e22a2d4b8255cc6205a5cceb9147..0108ff7e50ec1a3cf164ba77019449b1039a0fb2 100644 (file)
@@ -2,36 +2,94 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ContextMenuActionSet } from "views-components/context-menu/context-menu-action-set";
-import { AdvancedIcon, ProjectIcon, AttributesIcon } from "components/icon/icon";
+import { ContextMenuActionSet } from 'views-components/context-menu/context-menu-action-set';
+import {
+    AdvancedIcon,
+    ProjectIcon,
+    AttributesIcon,
+    DeactivateUserIcon,
+    UserPanelIcon,
+    LoginAsIcon,
+    AdminMenuIcon,
+    ActiveIcon,
+} from 'components/icon/icon';
 import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
-import { openUserAttributes, openUserProjects } from "store/users/users-actions";
+import { loginAs, openUserAttributes, openUserProjects } from 'store/users/users-actions';
+import { openSetupDialog, openDeactivateDialog, openActivateDialog } from 'store/user-profile/user-profile-actions';
+import { navigateToUserProfile } from 'store/navigation/navigation-action';
+import {
+    canActivateUser,
+    canDeactivateUser,
+    canSetupUser,
+    isAdmin,
+    needsUserProfileLink,
+    isOtherUser,
+} from 'store/context-menu/context-menu-filters';
 
-export const userActionSet: ContextMenuActionSet = [[{
-    name: "Attributes",
-    icon: AttributesIcon,
-    execute: (dispatch, { uuid }) => {
-        dispatch<any>(openUserAttributes(uuid));
-    }
-}, {
-    name: "Project",
-    icon: ProjectIcon,
-    execute: (dispatch, { uuid }) => {
-        dispatch<any>(openUserProjects(uuid));
-    }
-}, {
-    name: "Advanced",
-    icon: AdvancedIcon,
-    execute: (dispatch, { uuid }) => {
-        dispatch<any>(openAdvancedTabDialog(uuid));
-    }
-}, /*
-    // Neither of the buttons on this dialog work correctly (bugs #16114 and #16124) so hide it for now.
-    {
-    name: "Manage",
-    icon: UserPanelIcon,
-    execute: (dispatch, { uuid }) => {
-        dispatch<any>(openUserManagement(uuid));
-    }
-} */
-]];
+export const userActionSet: ContextMenuActionSet = [
+    [
+        {
+            name: 'Attributes',
+            icon: AttributesIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openUserAttributes(resources[0].uuid));
+            },
+        },
+        {
+            name: 'Project',
+            icon: ProjectIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openUserProjects(resources[0].uuid));
+            },
+        },
+        {
+            name: 'API Details',
+            icon: AdvancedIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openAdvancedTabDialog(resources[0].uuid));
+            },
+        },
+        {
+            name: 'Account Settings',
+            icon: UserPanelIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(navigateToUserProfile(resources[0].uuid));
+            },
+            filters: [needsUserProfileLink],
+        },
+    ],
+    [
+        {
+            name: 'Activate User',
+            icon: ActiveIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openActivateDialog(resources[0].uuid));
+            },
+            filters: [isAdmin, canActivateUser],
+        },
+        {
+            name: 'Setup User',
+            icon: AdminMenuIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openSetupDialog(resources[0].uuid));
+            },
+            filters: [isAdmin, canSetupUser],
+        },
+        {
+            name: 'Deactivate User',
+            icon: DeactivateUserIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(openDeactivateDialog(resources[0].uuid));
+            },
+            filters: [isAdmin, canDeactivateUser],
+        },
+        {
+            name: 'Login As User',
+            icon: LoginAsIcon,
+            execute: (dispatch, resources) => {
+                dispatch<any>(loginAs(resources[0].uuid));
+            },
+            filters: [isAdmin, isOtherUser],
+        },
+    ],
+];