[ARVADOS-WORKBENCH2] created: 1.3.0-350-g116c09a6

Git user git at public.curoverse.com
Fri Feb 1 06:01:15 EST 2019


        at  116c09a69fd71a9e80d8c49d21302574bbff9068 (commit)


commit 116c09a69fd71a9e80d8c49d21302574bbff9068
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date:   Fri Feb 1 12:01:00 2019 +0100

    sharing-with-groups
    
    Feature #14759
    
    Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>

diff --git a/src/store/sharing-dialog/sharing-dialog-actions.ts b/src/store/sharing-dialog/sharing-dialog-actions.ts
index 37de6f8c..17b237ec 100644
--- a/src/store/sharing-dialog/sharing-dialog-actions.ts
+++ b/src/store/sharing-dialog/sharing-dialog-actions.ts
@@ -19,6 +19,8 @@ import { differenceWith } from "lodash";
 import { withProgress } from "~/store/progress-indicator/with-progress";
 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions.ts';
 import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions";
+import { extractUuidKind, ResourceKind } from "~/models/resource";
+import { LinkClass } from "~/models/link";
 
 export const openSharingDialog = (resourceUuid: string) =>
     (dispatch: Dispatch) => {
@@ -189,15 +191,32 @@ const saveManagementChanges = async (_: Dispatch, getState: () => RootState, { p
     }
 };
 
-const sendInvitations = async (_: Dispatch, getState: () => RootState, { permissionService }: ServiceRepository) => {
+const sendInvitations = async (_: Dispatch, getState: () => RootState, { permissionService, userService }: ServiceRepository) => {
     const state = getState();
     const { user } = state.auth;
     const dialog = getDialog<string>(state.dialog, SHARING_DIALOG_NAME);
     if (dialog && user) {
-
         const invitations = getFormValues(SHARING_INVITATION_FORM_NAME)(state) as SharingInvitationFormData;
 
-        const invitationData = invitations.invitedPeople
+        const getGroupsFromForm = invitations.invitedPeople.filter((invitation) => extractUuidKind(invitation.uuid) === ResourceKind.GROUP);
+        const getUsersFromForm = invitations.invitedPeople.filter((invitation) => extractUuidKind(invitation.uuid) === ResourceKind.USER);
+        const uuids = getGroupsFromForm.map(group => group.uuid);
+
+        const permissions = await permissionService.list({
+            filters: new FilterBuilder()
+                .addIn('tailUuid', uuids)
+                .addEqual('linkClass', LinkClass.PERMISSION)
+                .getFilters()
+        });
+
+        const usersFromGroups = await userService.list({
+            filters: new FilterBuilder()
+                .addIn('uuid', permissions.items.map(item => item.headUuid))
+                .getFilters()
+
+        });
+
+        const invitationDataUsers = getUsersFromForm
             .map(person => ({
                 ownerUuid: user.uuid,
                 headUuid: dialog.data,
@@ -205,9 +224,19 @@ const sendInvitations = async (_: Dispatch, getState: () => RootState, { permiss
                 name: invitations.permissions
             }));
 
-        for (const invitation of invitationData) {
+        const invitationsDataGroups = usersFromGroups.items.map(
+            person => ({
+                ownerUuid: user.uuid,
+                headUuid: dialog.data,
+                tailUuid: person.uuid,
+                name: invitations.permissions
+            })
+        );
+
+        const data = invitationDataUsers.concat(invitationsDataGroups);
+
+        for (const invitation of data) {
             await permissionService.create(invitation);
         }
-
     }
 };
diff --git a/src/views-components/dialog-forms/add-group-member-dialog.tsx b/src/views-components/dialog-forms/add-group-member-dialog.tsx
index f4a5c2cf..2bd2109e 100644
--- a/src/views-components/dialog-forms/add-group-member-dialog.tsx
+++ b/src/views-components/dialog-forms/add-group-member-dialog.tsx
@@ -41,6 +41,7 @@ const UsersFieldValidation = [minLength(1, () => 'Select at least one user')];
 
 const UsersSelect = ({ fields }: WrappedFieldArrayProps<Person>) =>
     <PeopleSelect
+        onlyPeople
         autofocus
         label='Enter email adresses '
         items={fields.getAll() || []}
diff --git a/src/views-components/dialog-forms/create-group-dialog.tsx b/src/views-components/dialog-forms/create-group-dialog.tsx
index 554ad790..ff692fbd 100644
--- a/src/views-components/dialog-forms/create-group-dialog.tsx
+++ b/src/views-components/dialog-forms/create-group-dialog.tsx
@@ -56,6 +56,7 @@ const UsersField = () =>
 
 const UsersSelect = ({ fields }: WrappedFieldArrayProps<Person>) =>
     <PeopleSelect
+        onlyPeople
         label='Enter email adresses '
         items={fields.getAll() || []}
         onSelect={fields.push}
diff --git a/src/views-components/sharing-dialog/people-select.tsx b/src/views-components/sharing-dialog/people-select.tsx
index f62e6f55..f6f6c092 100644
--- a/src/views-components/sharing-dialog/people-select.tsx
+++ b/src/views-components/sharing-dialog/people-select.tsx
@@ -4,13 +4,13 @@
 
 import * as React from 'react';
 import { Autocomplete } from '~/components/autocomplete/autocomplete';
-import { UserResource } from '~/models/user';
 import { connect, DispatchProp } from 'react-redux';
 import { ServiceRepository } from '~/services/services';
 import { FilterBuilder } from '../../services/api/filter-builder';
 import { debounce } from 'debounce';
 import { ListItemText, Typography } from '@material-ui/core';
 import { noop } from 'lodash/fp';
+import { GroupClass } from '~/models/group';
 
 export interface Person {
     name: string;
@@ -23,6 +23,7 @@ export interface PeopleSelectProps {
     items: Person[];
     label?: string;
     autofocus?: boolean;
+    onlyPeople?: boolean;
 
     onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
     onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
@@ -34,7 +35,7 @@ export interface PeopleSelectProps {
 
 export interface PeopleSelectState {
     value: string;
-    suggestions: UserResource[];
+    suggestions: any[];
 }
 
 export const PeopleSelect = connect()(
@@ -46,8 +47,7 @@ export const PeopleSelect = connect()(
         };
 
         render() {
-
-            const { label = 'Invite people' } = this.props;
+            const { label = 'Share' } = this.props;
 
             return (
                 <Autocomplete
@@ -71,10 +71,12 @@ export const PeopleSelect = connect()(
             return name ? name : uuid;
         }
 
-        renderSuggestion({ firstName, lastName, email }: UserResource) {
+        renderSuggestion({ firstName, lastName, email, name }: any) {
             return (
                 <ListItemText>
-                    <Typography noWrap>{`${firstName} ${lastName} <<${email}>>`}</Typography>
+                    {name ?
+                        <Typography noWrap>{name}</Typography> :
+                        <Typography noWrap>{`${firstName} ${lastName} <<${email}>>`}</Typography>}
                 </ListItemText>
             );
         }
@@ -96,12 +98,12 @@ export const PeopleSelect = connect()(
             }
         }
 
-        handleSelect = ({ email, firstName, lastName, uuid }: UserResource) => {
+        handleSelect = ({ email, firstName, lastName, uuid, name }: any) => {
             const { onSelect = noop } = this.props;
             this.setState({ value: '', suggestions: [] });
             onSelect({
                 email,
-                name: `${firstName} ${lastName}`,
+                name: `${name ? name : `${firstName} ${lastName}`}`,
                 uuid,
             });
         }
@@ -112,13 +114,18 @@ export const PeopleSelect = connect()(
 
         getSuggestions = debounce(() => this.props.dispatch<any>(this.requestSuggestions), 500);
 
-        requestSuggestions = async (_: void, __: void, { userService }: ServiceRepository) => {
+        requestSuggestions = async (_: void, __: void, { userService, groupsService }: ServiceRepository) => {
             const { value } = this.state;
-            const filters = new FilterBuilder()
+            const filterGroups = new FilterBuilder()
+                .addNotIn('groupClass', [GroupClass.PROJECT])
+                .addILike('name', value)
+                .getFilters();
+            const groupItems = await groupsService.list({ filters: filterGroups, limit: 5 });
+            const filterUsers = new FilterBuilder()
                 .addILike('email', value)
                 .getFilters();
-            const { items } = await userService.list({ filters, limit: 5 });
-            this.setState({ suggestions: items });
+            const userItems: any = await userService.list({ filters: filterUsers, limit: 5 });
+            const items = groupItems.items.concat(userItems.items);
+            this.setState({ suggestions: this.props.onlyPeople ? userItems.items : items });
         }
-
     });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list