File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 {
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(
Original file line number Diff line number Diff line change 11{
2+ "exportDisabledForOthers" : " Exports are turned off in this workspace for tasks of other members." ,
23 "doneCheckbox" : {
34 "label" : " Done"
45 },
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments