Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 16, 2024
1 parent f0d83d0 commit e282405
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion databox/api/src/Entity/Core/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
),
Expand Down
15 changes: 1 addition & 14 deletions databox/client/src/components/Acl/AclForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<PermissionList
onListChanged={onListChanged}
displayedPermissions={displayedPermissions}
loadPermissions={loadPermissions}
updatePermission={updatePermission}
Expand Down
15 changes: 15 additions & 0 deletions databox/client/src/components/Dialog/Collection/InfoCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import EventIcon from '@mui/icons-material/Event';
import InfoRow from '../Info/InfoRow';
import PersonIcon from '@mui/icons-material/Person';
import {useTranslation} from 'react-i18next';
import FolderIcon from "@mui/icons-material/Folder";
import BusinessIcon from "@mui/icons-material/Business";

type Props = {
id: string;
Expand Down Expand Up @@ -44,6 +46,19 @@ export default function InfoCollection({data, onClose, minHeight}: Props) {
value={data.updatedAt}
icon={<EventIcon />}
/>
<InfoRow
icon={<BusinessIcon />}
label={t('collection.info.workspace', `Workspace`)}
value={data.workspace.name}
copyValue={data.workspace.id}
/>
<InfoRow
icon={<FolderIcon />}
label={t('collection.info.absolute_path', `Absolute Path`)}
value={
data.absoluteTitle
}
/>
</MenuList>
</ContentTab>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default function AssetViewActions({asset, file}: Props) {
<>
<Box
sx={{
zIndex: 1,
position:'relative',
'display': 'inline-block',
'ml': 2,
'> * + *': {
Expand Down
6 changes: 5 additions & 1 deletion databox/client/src/components/Media/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export default function LeftPanel() {
const {t} = useTranslation();
const [tab, setTab] = useState<TabEnum>(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);
};

Expand All @@ -67,7 +71,7 @@ export default function LeftPanel() {
<Facets/>
</TabPanel>
<TabPanel value={tab} index={TabEnum.tree}>
{tab === TabEnum.tree ? <CollectionsPanel/> : ''}
{treeLoadedOnce.current || tab === TabEnum.tree ? <CollectionsPanel/> : ''}
</TabPanel>
{isAuthenticated() ? (
<TabPanel value={tab} index={TabEnum.baskets}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ export default function UserPreferencesProvider({children}: Props) {
const initialData = getFromStorage();
const queryKey = ['userPreferences', user?.id];

const {data: preferences, isSuccess} = useQuery<UserPreferences>({
const {data: preferences, isLoading} = useQuery<UserPreferences>({
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 <T extends keyof UserPreferences>({
Expand Down Expand Up @@ -134,7 +133,8 @@ export default function UserPreferencesProvider({children}: Props) {
})}
/>

{isSuccess ? children : <FullPageLoader
{!isLoading ? children : <FullPageLoader
backdrop={false}
message={t('user_preferences.loading', 'Loading user preferences…')}
/>}
</ThemeEditorProvider>
Expand Down
2 changes: 1 addition & 1 deletion lib/js/phrasea-ui/src/components/FullPageLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function FullPageLoader({
}: Props) {
return <Backdrop
sx={theme => ({
color: theme.palette.common.white,
color: backdrop ? theme.palette.common.white : undefined,
zIndex: theme.zIndex.drawer + 1,
flexDirection: 'column',
})}
Expand Down

0 comments on commit e282405

Please sign in to comment.