[ARVADOS-WORKBENCH2] updated: 1.4.1-369-g612b040a

Git user git at public.arvados.org
Tue Jun 16 19:15:50 UTC 2020


Summary of changes:
 src/common/test/group-fixtures.ts                  | 13 ------
 .../context-menu/context-menu-actions.test.ts      | 48 ++++++++++----------
 src/store/resources/resources.test.ts              | 52 +++++++++++++++++++++-
 src/store/resources/resources.ts                   | 24 ++++++++--
 4 files changed, 95 insertions(+), 42 deletions(-)
 delete mode 100644 src/common/test/group-fixtures.ts

       via  612b040a79d1338ea3935dd2fc57dc0908d6ee20 (commit)
      from  7cd56c2b3cb65089a6268d5a3de24466d1bb8a24 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 612b040a79d1338ea3935dd2fc57dc0908d6ee20
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Tue Jun 16 21:14:45 2020 +0200

    16437: Handled case for resources shared with all users
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/common/test/group-fixtures.ts b/src/common/test/group-fixtures.ts
deleted file mode 100644
index d68a49b3..00000000
--- a/src/common/test/group-fixtures.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-export default {
-  user_uuid: 'zzzzz-tpzed-0123456789ab789',
-  user_resource_uuid: 'zzzzz-tpzed-0123456789abcde',
-  unknown_user_resource_uuid: 'zzzzz-tpzed-0123456789ab987',
-  editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab456',
-  not_editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab654',
-  editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab123',
-  not_editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab321',
-};
diff --git a/src/store/context-menu/context-menu-actions.test.ts b/src/store/context-menu/context-menu-actions.test.ts
index 04657e90..4bcbf9f2 100644
--- a/src/store/context-menu/context-menu-actions.test.ts
+++ b/src/store/context-menu/context-menu-actions.test.ts
@@ -20,34 +20,34 @@ describe('context-menu-actions', () => {
             it('should return ContextMenuKind.PROJECT_ADMIN', () => {
                 // given
                 const isAdmin = true;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.PROJECT_ADMIN);
             });
-    
+
             it('should return ContextMenuKind.PROJECT', () => {
                 // given
                 const isAdmin = false;
                 const isEditable = true;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin, isEditable);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.PROJECT);
             });
-    
+
             it('should return ContextMenuKind.READONLY_PROJECT', () => {
                 // given
                 const isAdmin = false;
                 const isEditable = false;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin, isEditable);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.READONLY_PROJECT);
             });
@@ -63,34 +63,34 @@ describe('context-menu-actions', () => {
             it('should return ContextMenuKind.COLLECTION_ADMIN', () => {
                 // given
                 const isAdmin = true;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.COLLECTION_ADMIN);
             });
-    
+
             it('should return ContextMenuKind.COLLECTION_RESOURCE', () => {
                 // given
                 const isAdmin = false;
                 const isEditable = true;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin, isEditable);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.COLLECTION_RESOURCE);
             });
-    
+
             it('should return ContextMenuKind.READONLY_COLLECTION', () => {
                 // given
                 const isAdmin = false;
                 const isEditable = false;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin, isEditable);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.READONLY_COLLECTION);
             });
@@ -106,10 +106,10 @@ describe('context-menu-actions', () => {
             it('should return ContextMenuKind.PROCESS_ADMIN', () => {
                 // given
                 const isAdmin = true;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.PROCESS_ADMIN);
             });
@@ -117,10 +117,10 @@ describe('context-menu-actions', () => {
             it('should return ContextMenuKind.PROCESS_RESOURCE', () => {
                 // given
                 const isAdmin = false;
-    
+
                 // when
                 const result = resourceKindToContextMenuKind(uuid, isAdmin);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.PROCESS_RESOURCE);
             });
@@ -133,10 +133,10 @@ describe('context-menu-actions', () => {
                     .mockImplementation(() => resource.ResourceKind.USER);
             });
 
-            it('should return ContextMenuKind.ROOT_PROJECT', () => {    
+            it('should return ContextMenuKind.ROOT_PROJECT', () => {
                 // when
                 const result = resourceKindToContextMenuKind(uuid);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.ROOT_PROJECT);
             });
@@ -149,10 +149,10 @@ describe('context-menu-actions', () => {
                     .mockImplementation(() => resource.ResourceKind.LINK);
             });
 
-            it('should return ContextMenuKind.LINK', () => {    
+            it('should return ContextMenuKind.LINK', () => {
                 // when
                 const result = resourceKindToContextMenuKind(uuid);
-    
+
                 // then
                 expect(result).toEqual(ContextMenuKind.LINK);
             });
diff --git a/src/store/resources/resources.test.ts b/src/store/resources/resources.test.ts
index 1dfeaf96..da630eb4 100644
--- a/src/store/resources/resources.test.ts
+++ b/src/store/resources/resources.test.ts
@@ -4,11 +4,35 @@
 
 import { getResourceWithEditableStatus } from "./resources";
 import { ResourceKind } from "~/models/resource";
-import groupFixtures from "../../common/test/group-fixtures";
+
+const groupFixtures = {
+    all_users_group: 'zzzzz-j7d0g-fffffffffffffff',
+    user_uuid: 'zzzzz-tpzed-0123456789ab789',
+    user_resource_uuid: 'zzzzz-tpzed-0123456789abcde',
+    user_from_another_cluster_uuid: 'aaaaa-tpzed-0123456789ab111',
+    unknown_user_resource_uuid: 'zzzzz-tpzed-0123456789ab987',
+    editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab456',
+    not_editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab654',
+    editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab123',
+    not_editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab321',
+    project_shared_with_all_users_uuid: 'zzzzz-j7d0g-0123456789abaaa'
+};
 
 describe('resources', () => {
     describe('getResourceWithEditableStatus', () => {
         const resourcesState = {
+            [groupFixtures.project_shared_with_all_users_uuid]: {
+                uuid: groupFixtures.project_shared_with_all_users_uuid,
+                ownerUuid: groupFixtures.user_uuid,
+                createdAt: 'string',
+                modifiedByClientUuid: 'string',
+                modifiedByUserUuid: 'string',
+                modifiedAt: 'string',
+                href: 'string',
+                kind: ResourceKind.PROJECT,
+                writableBy: [groupFixtures.all_users_group],
+                etag: 'string',
+            },
             [groupFixtures.editable_project_resource_uuid]: {
                 uuid: groupFixtures.editable_project_resource_uuid,
                 ownerUuid: groupFixtures.user_uuid,
@@ -64,10 +88,34 @@ describe('resources', () => {
                 modifiedAt: 'string',
                 href: 'string',
                 kind: ResourceKind.USER,
-                etag: 'string', 
+                etag: 'string',
             }
         };
 
+        it('should return editable equal to true for all users from the same cluster', () => {
+            // given
+            const id = groupFixtures.project_shared_with_all_users_uuid;
+            const userUuid = groupFixtures.user_uuid;
+
+            // when
+            const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
+
+            // then
+            expect(result!.isEditable).toBeTruthy();
+        });
+
+        it('should return not editable for all users from another cluster cluster', () => {
+            // given
+            const id = groupFixtures.project_shared_with_all_users_uuid;
+            const userUuid = groupFixtures.user_from_another_cluster_uuid;
+
+            // when
+            const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
+
+            // then
+            expect(result!.isEditable).toBeFalsy();
+        });
+
         it('should return editable user resource (resource UUID is equal to user UUID)', () => {
             // given
             const id = groupFixtures.user_resource_uuid;
diff --git a/src/store/resources/resources.ts b/src/store/resources/resources.ts
index 8fb6b5ca..908762bb 100644
--- a/src/store/resources/resources.ts
+++ b/src/store/resources/resources.ts
@@ -9,6 +9,8 @@ import { GroupResource } from "~/models/group";
 
 export type ResourcesState = { [key: string]: Resource };
 
+const allUsersGroupSuffix = 'j7d0g-fffffffffffffff';
+
 const getResourceWritableBy = (state: ResourcesState, id: string, userUuid: string): string[] => {
     if (!id) {
         return [];
@@ -29,12 +31,28 @@ const getResourceWritableBy = (state: ResourcesState, id: string, userUuid: stri
     return writableBy || getResourceWritableBy(state, resource.ownerUuid, userUuid);
 };
 
-export const getResourceWithEditableStatus = <T extends EditableResource & GroupResource>(id: string, userUuid?: string) => 
+export const getResourceWithEditableStatus = <T extends EditableResource & GroupResource>(id: string, userUuid?: string) =>
     (state: ResourcesState): T | undefined => {
         const resource = JSON.parse(JSON.stringify(state[id] as T));
 
-        if (resource) {
-            resource.isEditable = userUuid ? getResourceWritableBy(state, id, userUuid).indexOf(userUuid) > -1 : false;
+        if (resource && userUuid) {
+            resource.isEditable = false;
+
+            const writableBy = getResourceWritableBy(state, id, userUuid);
+
+            if (writableBy.indexOf(userUuid) > -1) { // first check if user can edit the resource
+                resource.isEditable = true;
+            } else { // if user has no direct access check if resource is shared with all users
+                const sharedWithAll = writableBy.find(uuid => uuid.indexOf(allUsersGroupSuffix) === 6);
+
+                if (sharedWithAll) { // verify if clusterId match
+                    const [userClusterId] = userUuid.split('-');
+
+                    if (sharedWithAll.indexOf(userClusterId) === 0) {
+                        resource.isEditable = true;
+                    }
+                }
+            }
         }
 
         return resource;

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list