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