From e28240554850a6b1e69778ad1ba8180928961a40 Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Wed, 16 Oct 2024 18:58:39 +0200 Subject: [PATCH] WIP --- .../CollectionPostTransformListener.php | 36 +++++++++++++------ databox/api/src/Entity/Core/Collection.php | 5 ++- databox/client/src/components/Acl/AclForm.tsx | 15 +------- .../Dialog/Collection/InfoCollection.tsx | 15 ++++++++ .../Media/Asset/Actions/AssetViewActions.tsx | 2 ++ .../client/src/components/Media/LeftPanel.tsx | 6 +++- .../Preferences/UserPreferencesProvider.tsx | 16 ++++----- .../src/components/FullPageLoader.tsx | 2 +- 8 files changed, 61 insertions(+), 36 deletions(-) diff --git a/databox/api/src/Elasticsearch/Listener/CollectionPostTransformListener.php b/databox/api/src/Elasticsearch/Listener/CollectionPostTransformListener.php index b75d5c145..b9d9a1047 100644 --- a/databox/api/src/Elasticsearch/Listener/CollectionPostTransformListener.php +++ b/databox/api/src/Elasticsearch/Listener/CollectionPostTransformListener.php @@ -26,7 +26,7 @@ public function hydrateDocument(PostTransformEvent $event): void $document = $event->getDocument(); - $bestPrivacy = $collection->getBestPrivacyInParentHierarchy(); + $bestPrivacy = $collection->getPrivacy(); $users = $this->permissionManager->getAllowedUsers($collection, PermissionInterface::VIEW); $groups = $this->permissionManager->getAllowedGroups($collection, PermissionInterface::VIEW); @@ -35,21 +35,35 @@ public function hydrateDocument(PostTransformEvent $event): void $nlUsers = $users; $nlGroups = $groups; - if (!in_array(null, $users, true)) { - $parent = $collection->getParent(); - while (null !== $parent) { - $users = array_merge($users, $this->permissionManager->getAllowedUsers($parent, PermissionInterface::VIEW)); - if (in_array(null, $users, true)) { - break; - } + $parent = $collection->getParent(); + while (null !== $parent) { + $bestPrivacy = max($bestPrivacy, $parent->getPrivacy()); + if ($bestPrivacy >= WorkspaceItemPrivacyInterface::PUBLIC_FOR_USERS) { + $nlUsers = []; + $nlGroups = []; + break; + } + + $parentUsers = $this->permissionManager->getAllowedUsers($parent, PermissionInterface::VIEW); + $users = array_merge($users, $parentUsers); + $nlUsers = array_diff($nlUsers, $parentUsers); - $groups = array_merge($groups, $this->permissionManager->getAllowedGroups($parent, PermissionInterface::VIEW)); - $parent = $parent->getParent(); + if (in_array(null, $users, true)) { + $nlUsers = []; + $nlGroups = []; + $bestPrivacy = max($bestPrivacy, WorkspaceItemPrivacyInterface::PUBLIC_FOR_USERS); + break; } + + $parentGroups = $this->permissionManager->getAllowedGroups($parent, PermissionInterface::VIEW); + $groups = array_merge($groups, $parentGroups); + $nlGroups = array_diff($nlGroups, $parentGroups); + + $parent = $parent->getParent(); } if (in_array(null, $users, true)) { - $users = ['*']; + $users = []; $groups = []; $bestPrivacy = max($bestPrivacy, WorkspaceItemPrivacyInterface::PUBLIC_FOR_USERS); } diff --git a/databox/api/src/Entity/Core/Collection.php b/databox/api/src/Entity/Core/Collection.php index b75de96b4..71147460a 100644 --- a/databox/api/src/Entity/Core/Collection.php +++ b/databox/api/src/Entity/Core/Collection.php @@ -46,7 +46,10 @@ operations: [ new Get( normalizationContext: [ - 'groups' => [self::GROUP_READ], + 'groups' => [ + self::GROUP_READ, + self::GROUP_ABSOLUTE_TITLE, + ], ], security: 'is_granted("'.AbstractVoter::LIST.'", object)' ), diff --git a/databox/client/src/components/Acl/AclForm.tsx b/databox/client/src/components/Acl/AclForm.tsx index c2824f572..223d1cfdb 100644 --- a/databox/client/src/components/Acl/AclForm.tsx +++ b/databox/client/src/components/Acl/AclForm.tsx @@ -2,8 +2,7 @@ import {useCallback} from 'react'; import PermissionList from '../Permissions/PermissionList'; import {deleteAce, getAces, putAce} from '../../api/acl'; import {OnPermissionDelete, PermissionObject} from '../Permissions/permissions'; -import {Ace, UserType} from '../../types'; -import {useCollectionStore} from '../../store/collectionStore'; +import {UserType} from '../../types'; type Props = { objectType: PermissionObject; @@ -34,20 +33,8 @@ export default function AclForm({ [objectType, objectId] ); - const onListChanged = - objectType === 'collection' - ? (permissions: Ace[]) => { - useCollectionStore - .getState() - .partialUpdateCollection(objectId, { - shared: permissions.length > 0, - }); - } - : undefined; - return ( } /> + } + label={t('collection.info.workspace', `Workspace`)} + value={data.workspace.name} + copyValue={data.workspace.id} + /> + } + label={t('collection.info.absolute_path', `Absolute Path`)} + value={ + data.absoluteTitle + } + /> ); diff --git a/databox/client/src/components/Media/Asset/Actions/AssetViewActions.tsx b/databox/client/src/components/Media/Asset/Actions/AssetViewActions.tsx index 7facd3936..877b150a6 100644 --- a/databox/client/src/components/Media/Asset/Actions/AssetViewActions.tsx +++ b/databox/client/src/components/Media/Asset/Actions/AssetViewActions.tsx @@ -26,6 +26,8 @@ export default function AssetViewActions({asset, file}: Props) { <> * + *': { diff --git a/databox/client/src/components/Media/LeftPanel.tsx b/databox/client/src/components/Media/LeftPanel.tsx index cd6a74687..e2e4fa567 100644 --- a/databox/client/src/components/Media/LeftPanel.tsx +++ b/databox/client/src/components/Media/LeftPanel.tsx @@ -40,8 +40,12 @@ export default function LeftPanel() { const {t} = useTranslation(); const [tab, setTab] = useState(TabEnum.facets); const {isAuthenticated} = useAuth(); + const treeLoadedOnce = React.useRef(false); const handleChange = (_event: React.ChangeEvent<{}>, newValue: TabEnum) => { + if (newValue === TabEnum.tree && !treeLoadedOnce.current) { + treeLoadedOnce.current = true; + } setTab(newValue); }; @@ -67,7 +71,7 @@ export default function LeftPanel() { - {tab === TabEnum.tree ? : ''} + {treeLoadedOnce.current || tab === TabEnum.tree ? : ''} {isAuthenticated() ? ( diff --git a/databox/client/src/components/User/Preferences/UserPreferencesProvider.tsx b/databox/client/src/components/User/Preferences/UserPreferencesProvider.tsx index 6ae2cdddf..24fbe0e21 100644 --- a/databox/client/src/components/User/Preferences/UserPreferencesProvider.tsx +++ b/databox/client/src/components/User/Preferences/UserPreferencesProvider.tsx @@ -42,16 +42,15 @@ export default function UserPreferencesProvider({children}: Props) { const initialData = getFromStorage(); const queryKey = ['userPreferences', user?.id]; - const {data: preferences, isSuccess} = useQuery({ + const {data: preferences, isLoading} = useQuery({ initialData: initialData, + staleTime: 0, + refetchOnWindowFocus: false, queryFn: async () => { - if (user) { - return await getUserPreferences(); - } - - return initialData; + return await getUserPreferences(); }, - queryKey: queryKey, + queryKey, + enabled: !!user, }); const mutationFn = async ({ @@ -134,7 +133,8 @@ export default function UserPreferencesProvider({children}: Props) { })} /> - {isSuccess ? children : } diff --git a/lib/js/phrasea-ui/src/components/FullPageLoader.tsx b/lib/js/phrasea-ui/src/components/FullPageLoader.tsx index 1062c7096..10a29e7cb 100644 --- a/lib/js/phrasea-ui/src/components/FullPageLoader.tsx +++ b/lib/js/phrasea-ui/src/components/FullPageLoader.tsx @@ -14,7 +14,7 @@ export default function FullPageLoader({ }: Props) { return ({ - color: theme.palette.common.white, + color: backdrop ? theme.palette.common.white : undefined, zIndex: theme.zIndex.drawer + 1, flexDirection: 'column', })}