Initialize groups panel store and view component
[arvados-workbench2.git] / src / store / workbench / workbench-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from 'redux';
6 import { RootState } from "~/store/store";
7 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
8 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
9 import { loadFavoritePanel } from '~/store/favorite-panel/favorite-panel-action';
10 import { openProjectPanel, projectPanelActions, setIsProjectPanelTrashed } from '~/store/project-panel/project-panel-action';
11 import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects } from '~/store/side-panel-tree/side-panel-tree-actions';
12 import { loadResource, updateResources } from '~/store/resources/resources-actions';
13 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
14 import { projectPanelColumns } from '~/views/project-panel/project-panel';
15 import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel';
16 import { matchRootRoute } from '~/routes/routes';
17 import { setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs, setTrashBreadcrumbs, setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
18 import { navigateToProject } from '~/store/navigation/navigation-action';
19 import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
20 import { ServiceRepository } from '~/services/services';
21 import { getResource } from '~/store/resources/resources';
22 import { getProjectPanelCurrentUuid } from '~/store/project-panel/project-panel-action';
23 import * as projectCreateActions from '~/store/projects/project-create-actions';
24 import * as projectMoveActions from '~/store/projects/project-move-actions';
25 import * as projectUpdateActions from '~/store/projects/project-update-actions';
26 import * as collectionCreateActions from '~/store/collections/collection-create-actions';
27 import * as collectionCopyActions from '~/store/collections/collection-copy-actions';
28 import * as collectionUpdateActions from '~/store/collections/collection-update-actions';
29 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
30 import * as processesActions from '~/store/processes/processes-actions';
31 import * as processMoveActions from '~/store/processes/process-move-actions';
32 import * as processUpdateActions from '~/store/processes/process-update-actions';
33 import * as processCopyActions from '~/store/processes/process-copy-actions';
34 import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
35 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
36 import { initProcessLogsPanel } from '~/store/process-logs-panel/process-logs-panel-actions';
37 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
38 import { sharedWithMePanelActions } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
39 import { loadSharedWithMePanel } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
40 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
41 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
42 import { loadSshKeysPanel } from '~/store/auth/auth-action';
43 import { loadMyAccountPanel } from '~/store/my-account/my-account-panel-actions';
44 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
45 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
46 import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
47 import { ResourceKind, extractUuidKind } from '~/models/resource';
48 import { FilterBuilder } from '~/services/api/filter-builder';
49 import { GroupContentsResource } from '~/services/groups-service/groups-service';
50 import { unionize, ofType, UnionOf, MatchCases } from '~/common/unionize';
51 import { loadRunProcessPanel } from '~/store/run-process-panel/run-process-panel-actions';
52 import { loadCollectionFiles } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
53 import { SnackbarKind } from '~/store/snackbar/snackbar-actions';
54 import { collectionPanelActions } from "~/store/collection-panel/collection-panel-action";
55 import { CollectionResource } from "~/models/collection";
56 import { searchResultsPanelActions, loadSearchResultsPanel } from '~/store/search-results-panel/search-results-panel-actions';
57 import { searchResultsPanelColumns } from '~/views/search-results-panel/search-results-panel-view';
58 import { loadVirtualMachinesPanel } from '~/store/virtual-machines/virtual-machines-actions';
59 import { loadRepositoriesPanel } from '~/store/repositories/repositories-actions';
60 import { loadKeepServicesPanel } from '~/store/keep-services/keep-services-actions';
61 import { loadUsersPanel, userBindedActions } from '~/store/users/users-actions';
62 import { userPanelColumns } from '~/views/user-panel/user-panel';
63 import { loadComputeNodesPanel } from '~/store/compute-nodes/compute-nodes-actions';
64 import { loadApiClientAuthorizationsPanel } from '~/store/api-client-authorizations/api-client-authorizations-actions';
65 import * as groupPanelActions from '~/store/groups-panel/groups-panel-actions';
66 import { groupsPanelColumns } from '~/views/groups-panel/groups-panel';
67
68 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
69
70 export const isWorkbenchLoading = (state: RootState) => {
71     const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
72     return progress ? progress.working : false;
73 };
74
75 const handleFirstTimeLoad = (action: any) =>
76     async (dispatch: Dispatch<any>, getState: () => RootState) => {
77         try {
78             await dispatch(action);
79         } finally {
80             if (isWorkbenchLoading(getState())) {
81                 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
82             }
83         }
84     };
85
86 export const loadWorkbench = () =>
87     async (dispatch: Dispatch, getState: () => RootState) => {
88         dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
89         const { auth, router } = getState();
90         const { user } = auth;
91         if (user) {
92             const userResource = await dispatch<any>(loadResource(user.uuid));
93             if (userResource) {
94                 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
95                 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
96                 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
97                 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
98                 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
99                 dispatch(searchResultsPanelActions.SET_COLUMNS({ columns: searchResultsPanelColumns }));
100                 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
101                 dispatch(groupPanelActions.GroupsPanelActions.SET_COLUMNS({ columns: groupsPanelColumns }));
102                 dispatch<any>(initSidePanelTree());
103                 if (router.location) {
104                     const match = matchRootRoute(router.location.pathname);
105                     if (match) {
106                         dispatch(navigateToProject(userResource.uuid));
107                     }
108                 }
109             } else {
110                 dispatch(userIsNotAuthenticated);
111             }
112         } else {
113             dispatch(userIsNotAuthenticated);
114         }
115     };
116
117 export const loadFavorites = () =>
118     handleFirstTimeLoad(
119         (dispatch: Dispatch) => {
120             dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
121             dispatch<any>(loadFavoritePanel());
122             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
123         });
124
125 export const loadTrash = () =>
126     handleFirstTimeLoad(
127         (dispatch: Dispatch) => {
128             dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
129             dispatch<any>(loadTrashPanel());
130             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
131         });
132
133 export const loadProject = (uuid: string) =>
134     handleFirstTimeLoad(
135         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
136             const userUuid = services.authService.getUuid();
137             dispatch(setIsProjectPanelTrashed(false));
138             if (userUuid) {
139                 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
140                     // Load another users home projects
141                     dispatch(finishLoadingProject(uuid));
142                 } else if (userUuid !== uuid) {
143                     const match = await loadGroupContentsResource({ uuid, userUuid, services });
144                     match({
145                         OWNED: async project => {
146                             await dispatch(activateSidePanelTreeItem(uuid));
147                             dispatch<any>(setSidePanelBreadcrumbs(uuid));
148                             dispatch(finishLoadingProject(project));
149                         },
150                         SHARED: project => {
151                             dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
152                             dispatch(activateSidePanelTreeItem(uuid));
153                             dispatch(finishLoadingProject(project));
154                         },
155                         TRASHED: project => {
156                             dispatch<any>(setTrashBreadcrumbs(uuid));
157                             dispatch(setIsProjectPanelTrashed(true));
158                             dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
159                             dispatch(finishLoadingProject(project));
160                         }
161                     });
162                 } else {
163                     await dispatch(activateSidePanelTreeItem(userUuid));
164                     dispatch<any>(setSidePanelBreadcrumbs(userUuid));
165                     dispatch(finishLoadingProject(userUuid));
166                 }
167             }
168         });
169
170 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
171     async (dispatch: Dispatch) => {
172         const newProject = await dispatch<any>(projectCreateActions.createProject(data));
173         if (newProject) {
174             dispatch(snackbarActions.OPEN_SNACKBAR({
175                 message: "Project has been successfully created.",
176                 hideDuration: 2000
177             }));
178             await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
179             dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
180         }
181     };
182
183 export const moveProject = (data: MoveToFormDialogData) =>
184     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
185         try {
186             const oldProject = getResource(data.uuid)(getState().resources);
187             const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
188             const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
189             if (movedProject) {
190                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
191                 if (oldProject) {
192                     await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
193                 }
194                 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
195             }
196         } catch (e) {
197             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
198         }
199     };
200
201 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
202     async (dispatch: Dispatch) => {
203         const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
204         if (updatedProject) {
205             dispatch(snackbarActions.OPEN_SNACKBAR({
206                 message: "Project has been successfully updated.",
207                 hideDuration: 2000
208             }));
209             await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
210             dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
211         }
212     };
213
214 export const loadCollection = (uuid: string) =>
215     handleFirstTimeLoad(
216         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
217             const userUuid = services.authService.getUuid();
218             if (userUuid) {
219                 const match = await loadGroupContentsResource({ uuid, userUuid, services });
220                 match({
221                     OWNED: async collection => {
222                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
223                         dispatch(updateResources([collection]));
224                         await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
225                         dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
226                         dispatch(loadCollectionFiles(collection.uuid));
227                     },
228                     SHARED: collection => {
229                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
230                         dispatch(updateResources([collection]));
231                         dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
232                         dispatch(activateSidePanelTreeItem(collection.ownerUuid));
233                         dispatch(loadCollectionFiles(collection.uuid));
234                     },
235                     TRASHED: collection => {
236                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
237                         dispatch(updateResources([collection]));
238                         dispatch(setTrashBreadcrumbs(''));
239                         dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
240                         dispatch(loadCollectionFiles(collection.uuid));
241                     },
242
243                 });
244             }
245         });
246
247 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
248     async (dispatch: Dispatch) => {
249         const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
250         if (collection) {
251             dispatch(snackbarActions.OPEN_SNACKBAR({
252                 message: "Collection has been successfully created.",
253                 hideDuration: 2000
254             }));
255             dispatch<any>(updateResources([collection]));
256             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
257         }
258     };
259
260 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
261     async (dispatch: Dispatch) => {
262         const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
263         if (collection) {
264             dispatch(snackbarActions.OPEN_SNACKBAR({
265                 message: "Collection has been successfully updated.",
266                 hideDuration: 2000
267             }));
268             dispatch<any>(updateResources([collection]));
269             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
270         }
271     };
272
273 export const copyCollection = (data: CopyFormDialogData) =>
274     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
275         try {
276             const copyToProject = getResource(data.ownerUuid)(getState().resources);
277             const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
278             if (copyToProject && collection) {
279                 dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
280                 dispatch(snackbarActions.OPEN_SNACKBAR({
281                     message: 'Collection has been copied.',
282                     hideDuration: 3000,
283                     kind: SnackbarKind.SUCCESS,
284                     link: collection.ownerUuid
285                 }));
286             }
287         } catch (e) {
288             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
289         }
290     };
291
292 export const moveCollection = (data: MoveToFormDialogData) =>
293     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
294         try {
295             const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
296             dispatch<any>(updateResources([collection]));
297             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
298             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
299         } catch (e) {
300             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
301         }
302     };
303
304 export const loadProcess = (uuid: string) =>
305     handleFirstTimeLoad(
306         async (dispatch: Dispatch, getState: () => RootState) => {
307             dispatch<any>(loadProcessPanel(uuid));
308             const process = await dispatch<any>(processesActions.loadProcess(uuid));
309             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
310             dispatch<any>(setProcessBreadcrumbs(uuid));
311             dispatch(loadDetailsPanel(uuid));
312         });
313
314 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
315     async (dispatch: Dispatch) => {
316         try {
317             const process = await dispatch<any>(processUpdateActions.updateProcess(data));
318             if (process) {
319                 dispatch(snackbarActions.OPEN_SNACKBAR({
320                     message: "Process has been successfully updated.",
321                     hideDuration: 2000
322                 }));
323                 dispatch<any>(updateResources([process]));
324                 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
325             }
326         } catch (e) {
327             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
328         }
329     };
330
331 export const moveProcess = (data: MoveToFormDialogData) =>
332     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
333         try {
334             const process = await dispatch<any>(processMoveActions.moveProcess(data));
335             dispatch<any>(updateResources([process]));
336             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
337             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
338         } catch (e) {
339             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
340         }
341     };
342
343 export const copyProcess = (data: CopyFormDialogData) =>
344     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
345         try {
346             const process = await dispatch<any>(processCopyActions.copyProcess(data));
347             dispatch<any>(updateResources([process]));
348             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
349             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
350         } catch (e) {
351             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
352         }
353     };
354
355 export const loadProcessLog = (uuid: string) =>
356     handleFirstTimeLoad(
357         async (dispatch: Dispatch) => {
358             const process = await dispatch<any>(processesActions.loadProcess(uuid));
359             dispatch<any>(setProcessBreadcrumbs(uuid));
360             dispatch<any>(initProcessLogsPanel(uuid));
361             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
362         });
363
364 export const resourceIsNotLoaded = (uuid: string) =>
365     snackbarActions.OPEN_SNACKBAR({
366         message: `Resource identified by ${uuid} is not loaded.`
367     });
368
369 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
370     message: 'User is not authenticated'
371 });
372
373 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
374     message: 'Could not load user'
375 });
376
377 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
378     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
379         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
380         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
381             dispatch<any>(loadProject(currentProjectPanelUuid));
382         }
383     };
384
385 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
386     dispatch<any>(loadSharedWithMePanel());
387     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
388     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
389 });
390
391 export const loadRunProcess = handleFirstTimeLoad(
392     async (dispatch: Dispatch) => {
393         await dispatch<any>(loadRunProcessPanel());
394     }
395 );
396
397 export const loadWorkflow = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
398     dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.WORKFLOWS));
399     await dispatch(loadWorkflowPanel());
400     dispatch(setSidePanelBreadcrumbs(SidePanelTreeCategory.WORKFLOWS));
401 });
402
403 export const loadSearchResults = handleFirstTimeLoad(
404     async (dispatch: Dispatch<any>) => {
405         await dispatch(loadSearchResultsPanel());
406     });
407
408 export const loadVirtualMachines = handleFirstTimeLoad(
409     async (dispatch: Dispatch<any>) => {
410         await dispatch(loadVirtualMachinesPanel());
411         dispatch(setBreadcrumbs([{ label: 'Virtual Machines' }]));
412     });
413
414 export const loadRepositories = handleFirstTimeLoad(
415     async (dispatch: Dispatch<any>) => {
416         await dispatch(loadRepositoriesPanel());
417         dispatch(setBreadcrumbs([{ label: 'Repositories' }]));
418     });
419
420 export const loadSshKeys = handleFirstTimeLoad(
421     async (dispatch: Dispatch<any>) => {
422         await dispatch(loadSshKeysPanel());
423     });
424
425 export const loadMyAccount = handleFirstTimeLoad(
426     (dispatch: Dispatch<any>) => {
427         dispatch(loadMyAccountPanel());
428     });
429
430 export const loadKeepServices = handleFirstTimeLoad(
431     async (dispatch: Dispatch<any>) => {
432         await dispatch(loadKeepServicesPanel());
433     });
434
435 export const loadUsers = handleFirstTimeLoad(
436     async (dispatch: Dispatch<any>) => {
437         await dispatch(loadUsersPanel());
438         dispatch(setBreadcrumbs([{ label: 'Users' }]));
439     });
440
441 export const loadComputeNodes = handleFirstTimeLoad(
442     async (dispatch: Dispatch<any>) => {
443         await dispatch(loadComputeNodesPanel());
444     });
445
446 export const loadApiClientAuthorizations = handleFirstTimeLoad(
447     async (dispatch: Dispatch<any>) => {
448         await dispatch(loadApiClientAuthorizationsPanel());
449     });
450
451 export const loadGroupsPanel = handleFirstTimeLoad(
452     (dispatch: Dispatch<any>) => {
453         dispatch(setBreadcrumbs([{ label: 'Groups' }]));
454         dispatch(groupPanelActions.loadGroupsPanel());
455     });
456
457 const finishLoadingProject = (project: GroupContentsResource | string) =>
458     async (dispatch: Dispatch<any>) => {
459         const uuid = typeof project === 'string' ? project : project.uuid;
460         dispatch(openProjectPanel(uuid));
461         dispatch(loadDetailsPanel(uuid));
462         if (typeof project !== 'string') {
463             dispatch(updateResources([project]));
464         }
465     };
466
467 const loadGroupContentsResource = async (params: {
468     uuid: string,
469     userUuid: string,
470     services: ServiceRepository
471 }) => {
472     const filters = new FilterBuilder()
473         .addEqual('uuid', params.uuid)
474         .getFilters();
475     const { items } = await params.services.groupsService.contents(params.userUuid, {
476         filters,
477         recursive: true,
478         includeTrash: true,
479     });
480     const resource = items.shift();
481     let handler: GroupContentsHandler;
482     if (resource) {
483         handler = (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
484             ? groupContentsHandlers.TRASHED(resource)
485             : groupContentsHandlers.OWNED(resource);
486     } else {
487         const kind = extractUuidKind(params.uuid);
488         let resource: GroupContentsResource;
489         if (kind === ResourceKind.COLLECTION) {
490             resource = await params.services.collectionService.get(params.uuid);
491         } else if (kind === ResourceKind.PROJECT) {
492             resource = await params.services.projectService.get(params.uuid);
493         } else {
494             resource = await params.services.containerRequestService.get(params.uuid);
495         }
496         handler = groupContentsHandlers.SHARED(resource);
497     }
498     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) =>
499         groupContentsHandlers.match(handler, cases);
500
501 };
502
503 const groupContentsHandlersRecord = {
504     TRASHED: ofType<GroupContentsResource>(),
505     SHARED: ofType<GroupContentsResource>(),
506     OWNED: ofType<GroupContentsResource>(),
507 };
508
509 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
510
511 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;