Skip to content

Commit 3fa0db1

Browse files
committed
feat: toast when selected-task export is refused with feature_disabled (TM-947)
1 parent 85eae26 commit 3fa0db1

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎src/components/tasks/TasksListComponent.vue‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@
524524

525525
<script lang="ts">
526526
import { currentLocale, t } from '@/i18n';
527+
import { toast } from '@/components/ui/toast';
528+
import { isExportFeatureDisabled } from '@/utils/exportErrors';
527529
import { getAssignablePersonas } from '@/actions/tmgr/personas';
528530
import { getStatuses, Status } from '@/actions/tmgr/statuses';
529531
import {
@@ -1406,7 +1408,14 @@
14061408

14071409
downloadFile(data, 'export.' + exportType);
14081410
} catch (e) {
1409-
console.error(e);
1411+
if (await isExportFeatureDisabled(e)) {
1412+
toast({
1413+
description: t('tasks.exportDisabledForOthers'),
1414+
variant: 'destructive',
1415+
});
1416+
} else {
1417+
console.error(e);
1418+
}
14101419
} finally {
14111420
this.loadingActionsForMultipleTasks =
14121421
this.loadingActionsForMultipleTasks.filter(

‎src/locales/en/tasks.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"exportDisabledForOthers": "Exports are turned off in this workspace for tasks of other members.",
23
"doneCheckbox": {
34
"label": "Done"
45
},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { isExportFeatureDisabled } from '../exportErrors';
2+
3+
const forbidden = (data: unknown) => ({ response: { status: 403, data } });
4+
const body = { error: 'feature_disabled', feature: 'exports' };
5+
6+
describe('isExportFeatureDisabled', () => {
7+
it('detects feature_disabled in a blob body', async () => {
8+
const blob = new Blob([JSON.stringify(body)], {
9+
type: 'application/json',
10+
});
11+
expect(await isExportFeatureDisabled(forbidden(blob))).toBe(true);
12+
});
13+
14+
it('detects feature_disabled in a parsed body', async () => {
15+
expect(await isExportFeatureDisabled(forbidden(body))).toBe(true);
16+
});
17+
18+
it('ignores other 403 codes, other statuses and unreadable bodies', async () => {
19+
expect(
20+
await isExportFeatureDisabled(forbidden({ error: 'forbidden' })),
21+
).toBe(false);
22+
expect(
23+
await isExportFeatureDisabled({ response: { status: 500, data: body } }),
24+
).toBe(false);
25+
expect(await isExportFeatureDisabled(forbidden(new Blob(['nope'])))).toBe(
26+
false,
27+
);
28+
expect(await isExportFeatureDisabled(new Error('x'))).toBe(false);
29+
});
30+
});

‎src/utils/exportErrors.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const isExportFeatureDisabled = async (error: any): Promise<boolean> => {
2+
const response = error?.response;
3+
if (response?.status !== 403) return false;
4+
let data = response.data;
5+
if (typeof Blob !== 'undefined' && data instanceof Blob) {
6+
try {
7+
data = JSON.parse(await data.text());
8+
} catch {
9+
return false;
10+
}
11+
}
12+
return data?.error === 'feature_disabled';
13+
};

0 commit comments

Comments
 (0)