Skip to content

Commit

Permalink
Switch to font awesome icon instances, validate config condition in jest
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 21, 2023
1 parent c6648fb commit ea40538
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 47 deletions.
6 changes: 3 additions & 3 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,9 +1485,9 @@ export interface paths {
/** Remove the object from user's favorites */
delete: operations["remove_favorite_api_users__user_id__favorites__object_type___object_id__delete"];
};
"/api/users/{user_id}/recalculate": {
"/api/users/{user_id}/recalculate_disk_usage": {
/** Triggers a recalculation of the current user disk usage. */
put: operations["recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_put"];
put: operations["recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_disk_usage_put"];
};
"/api/users/{user_id}/send_activation_email": {
/** Sends activation email to user. */
Expand Down Expand Up @@ -17846,7 +17846,7 @@ export interface operations {
};
};
};
recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_put: {
recalculate_disk_usage_by_user_id_api_users__user_id__recalculate_disk_usage_put: {
/** Triggers a recalculation of the current user disk usage. */
parameters: {
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
Expand Down
29 changes: 23 additions & 6 deletions client/src/components/Grid/GridList.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import { createTestingPinia } from "@pinia/testing";
import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { PiniaVuePlugin } from "pinia";
import { getLocalVue } from "tests/jest/helpers";
import { useRouter } from "vue-router/composables";

import { useConfig } from "@/composables/config";
import Filtering from "@/utils/filtering";

import MountTarget from "./GridList.vue";

const localVue = getLocalVue();

jest.useFakeTimers();
jest.mock("vue-router/composables");

jest.mock("composables/config");
useConfig.mockReturnValue({
config: {
value: {
disabled: false,
enabled: true,
},
},
isConfigLoaded: true,
});

jest.mock("vue-router/composables");
useRouter.mockImplementation(() => "router");

const localVue = getLocalVue();
localVue.use(PiniaVuePlugin);

const testGrid = {
actions: [
{
Expand Down Expand Up @@ -42,19 +57,19 @@ const testGrid = {
{
title: "operation-title-1",
icon: "operation-icon-1",
condition: () => true,
condition: (_, config) => config.value.enabled,
handler: jest.fn(),
},
{
title: "operation-title-2",
icon: "operation-icon-2",
condition: () => false,
condition: (_, config) => config.value.disabled,
handler: jest.fn(),
},
{
title: "operation-title-3",
icon: "operation-icon-3",
condition: () => true,
condition: (_, config) => config.value.enabled,
handler: () => ({
status: "success",
message: "Operation-3 has been executed.",
Expand Down Expand Up @@ -83,9 +98,11 @@ const testGrid = {
};

function createTarget(propsData) {
const pinia = createTestingPinia({ stubActions: false });
return mount(MountTarget, {
localVue,
propsData,
pinia,
stubs: {
Icon: true,
},
Expand Down
82 changes: 46 additions & 36 deletions client/src/components/Grid/configs/adminUsers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import {
faBolt,
faCalculator,
faEnvelope,
faKey,
faMask,
faTrash,
faTrashRestore,
faUnlock,
faUser,
faUsers,
} from "@fortawesome/free-solid-svg-icons";
import axios from "axios";
import type Router from "vue-router";

import { createApiKey, deleteUser, recalculateDiskUsageByUserId, sendActivationEmail, undeleteUser, updateUser } from "@/api/users";
import { createApiKey, deleteUser, recalculateDiskUsageByUserId, sendActivationEmail, undeleteUser } from "@/api/users";
import type { ConfigType } from "@/composables/config";
import Filtering, { contains, equals, toBool, type ValidFilter } from "@/utils/filtering";
import { withPrefix } from "@/utils/redirect";
Expand Down Expand Up @@ -30,8 +42,8 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
...d,
deleted: d.deleted === "True",
purged: d.purged === "True",
}
})
};
});
return [data.rows, data.total_row_count];
}

Expand All @@ -47,31 +59,31 @@ const fields = [
operations: [
{
title: "Manage Information",
icon: "user",
icon: faUser,
condition: (data: UserEntry) => !data.deleted,
handler: (data: UserEntry, router: Router) => {
router.push(`/user/information?id=${data.id}`);
},
},
{
title: "Manage Roles and Groups",
icon: "users",
icon: faUsers,
condition: (data: UserEntry) => !data.deleted,
handler: (data: UserEntry, router: Router) => {
router.push(`/admin/form/manage_roles_and_groups_for_user?id=${data.id}`);
},
},
{
title: "Reset Password",
icon: "unlock",
icon: faUnlock,
condition: (data: UserEntry) => !data.deleted,
handler: (data: UserEntry, router: Router) => {
router.push(`/admin/form/reset_user_password?id=${data.id}`);
},
},
{
title: "Recalculate Disk Usage",
icon: "calculator",
icon: faCalculator,
condition: (data: UserEntry) => !data.deleted,
handler: async (data: UserEntry) => {
try {
Expand All @@ -90,9 +102,30 @@ const fields = [
}
},
},
{
title: "Activate",
icon: faBolt,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.user_activation_on && !data.deleted;
},
handler: async (data: UserEntry) => {
try {
//await updateUser({ user_id: String(data.id), active });
return {
status: "success",
message: `'${data.username}' has been activated.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to activate '${data.username}': ${errorMessageAsString(e)}.`,
};
}
},
},
{
title: "Send Activation Email",
icon: "calculator",
icon: faEnvelope,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.user_activation_on && !data.deleted;
},
Expand All @@ -115,7 +148,7 @@ const fields = [
},
{
title: "Generate New API Key",
icon: "key",
icon: faKey,
condition: (data: UserEntry) => !data.deleted,
handler: async (data: UserEntry) => {
try {
Expand All @@ -136,7 +169,7 @@ const fields = [
},
{
title: "Impersonate User",
icon: "user",
icon: faMask,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_impersonation && !data.deleted;
},
Expand All @@ -146,7 +179,7 @@ const fields = [
},
{
title: "Delete",
icon: "trash",
icon: faTrash,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_deletion && !data.deleted;
},
Expand All @@ -167,7 +200,7 @@ const fields = [
},
{
title: "Purge",
icon: "trash",
icon: faTrash,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_deletion && data.deleted && !data.purged;
},
Expand All @@ -188,7 +221,7 @@ const fields = [
},
{
title: "Restore",
icon: "trash-restore",
icon: faTrashRestore,
condition: (data: UserEntry, config: ConfigType) => {
return config.value.allow_user_deletion && data.deleted && !data.purged;
},
Expand All @@ -207,29 +240,6 @@ const fields = [
}
},
},
{
title: "Activate",
icon: "user",
condition: (data: UserEntry, config: ConfigType) => {
return config.value.user_activation_on && !data.deleted;
},
handler: async (data: UserEntry) => {
try {
//await updateUser({ user_id: String(data.id), active: true });
return {
status: "success",
message: `'${data.username}' has been activated.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to activate '${data.username}': ${errorMessageAsString(
e
)}.`,
};
}
},
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Grid/configs/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import type Router from "vue-router";

import Filtering from "@/utils/filtering";
import type { ConfigType } from "@/composables/config";
import Filtering from "@/utils/filtering";

export interface Action {
title: string;
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/managers/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def _config_is_truthy(item, key, **context):
),
"object_store_allows_id_selection": lambda item, key, **context: object_store.object_store_allows_id_selection(),
"object_store_ids_allowing_selection": lambda item, key, **context: object_store.object_store_ids_allowing_selection(),
"user_activation_on": _use_config,
"user_library_import_dir_available": lambda item, key, **context: bool(item.get("user_library_import_dir")),
"welcome_directory": _use_config,
"themes": _use_config,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def send_activation_email(
if not user:
raise exceptions.ObjectNotFound("User not found for given id.")
if not self.service.user_manager.send_activation_email(trans, user.email, user.username):
raise exceptions.MessageError("Unable to send activation email.")
raise exceptions.MessageException("Unable to send activation email.")


class UserAPIController(BaseGalaxyAPIController, UsesTagsMixin, BaseUIController, UsesFormDefinitionsMixin):
Expand Down

0 comments on commit ea40538

Please sign in to comment.