Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🕹 Manage root users #146

Merged
merged 14 commits into from
Aug 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ import {
} from "../../types";
import { DriveFileDTO } from "../dto/drive-file-dto";
import { DriveFileDTOBuilder } from "../../services/drive-file-dto-builder";

import {
ExecutionContext,
} from "../../../../core/platform/framework/api/crud-service";
import gr from "../../../global-resolver";
export class DocumentsController {
private driveFileDTOBuilder = new DriveFileDTOBuilder();

private getCompanyUserRole(companyId: string, userId: string, context?: ExecutionContext) {
return gr.services.companies
.getCompanyUser({ id: companyId }, { id: userId }, context)
.then(a => (a ? a.level : null));
}

/**
* Creates a DriveFile item
Expand Down Expand Up @@ -158,6 +167,8 @@ export class DocumentsController {
const context = getDriveExecutionContext(request);
const { id } = request.params;

const companyUserRole = await this.getCompanyUserRole(request.body.company_id || context.company.id, context.user.id);

const options: SearchDocumentsOptions = {
...request.body,
company_id: request.body.company_id || context.company.id,
Expand All @@ -166,7 +177,7 @@ export class DocumentsController {
onlyUploadedNotByMe: true,
};

return {
let data = {
...(await globalResolver.services.documents.documents.browse(id, options, context)),
websockets: request.currentUser?.id
? globalResolver.platformServices.realtime.sign(
Expand All @@ -175,6 +186,13 @@ export class DocumentsController {
)
: [],
};

if(id == "root" && companyUserRole < 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 1 mean?

(Magic constant spotted).

I recommend to extract this as a global variable and give it a name.

data.children = [];
data.access = "read";
}

return data;
};

sharedWithMe = async (
Expand Down
1 change: 1 addition & 0 deletions tdrive/frontend/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"components.item_context_menu.add_documents": "Add document or folder",
"components.item_context_menu.download_folder": "Download folder",
"components.item_context_menu.go_to_trash": "Go to trash",
"components.item_context_menu.manage_users": "Manager users",
"components.item_context_menu.all": "All",
"components.item_context_menu.today": "Today",
"components.item_context_menu.last_week": "Last week",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
},
},
{ type: 'separator', hide: inTrash || parent.access === 'read' },
{
type: 'menu',
text: Languages.t('components.item_context_menu.manage_users'),
},
{ type: 'separator', hide: inTrash || parent.access === 'read' },
{
type: 'menu',
text: Languages.t('components.item_context_menu.go_to_trash'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Select from '@atoms/input/input-select';
import { DriveFileAccessLevel } from '@features/drive/types';
import Languages from 'features/global/services/languages-service';

export const AccessLevel = ({
disabled,
level,
onChange,
canRemove,
hiddenLevels,
className,
}: {
disabled?: boolean;
level: DriveFileAccessLevel | null;
onChange: (level: DriveFileAccessLevel & 'remove') => void;
canRemove?: boolean;
className?: string;
hiddenLevels?: string[];
}) => {
return (
<Select
disabled={disabled}
className={
className +
' w-auto ' +
(level === 'none' ? '!text-rose-500 !bg-rose-100 dark-bg-rose-800' : '')
}
value={level || 'none'}
onChange={e => onChange(e.target.value as DriveFileAccessLevel & 'remove')}
>
{!hiddenLevels?.includes('manage') && <option value={'manage'}>{Languages.t('common.access-level_full_acess')}</option>}
{!hiddenLevels?.includes('write') && <option value={'write'}>{Languages.t('common.access-level_write')}</option>}
{!hiddenLevels?.includes('read') && <option value={'read'}>{Languages.t('common.access-level_read')}</option>}
{!hiddenLevels?.includes('none') && <option value={'none'}>{Languages.t('common.access-level_no_access')}</option>}
{canRemove && <option value={'remove'}>Remove</option>}
</Select>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Modal, ModalContent } from '@atoms/modal';
import { useDriveItem } from '@features/drive/hooks/use-drive-item';
import { useEffect } from 'react';
import { atom, useRecoilState } from 'recoil';
import { InternalAccessManager } from './internal-access';
import { PublicLinkManager } from './public-link-access';
import Languages from 'features/global/services/languages-service';


export type AccessModalType = {
open: boolean;
id: string;
};

export const AccessModalAtom = atom<AccessModalType>({
key: 'AccessModalAtom',
default: {
open: false,
id: '',
},
});

export const AccessModal = () => {
const [state, setState] = useRecoilState(AccessModalAtom);

return (
<Modal open={state.open} onClose={() => setState({ ...state, open: false })}>
{!!state.id && <AccessModalContent id={state.id} />}
</Modal>
);
};

const AccessModalContent = ({ id }: { id: string }) => {
const { item, access, refresh } = useDriveItem(id);

useEffect(() => {
refresh(id);
}, []);

console.log(item?.access_info?.public?.level, 'item');

return (
<ModalContent title={Languages.t('components.item_context_menu.manage_access_to') + " " + item?.name}>
<PublicLinkManager id={id} disabled={access !== 'manage'} />
<InternalAccessManager id={id} disabled={access !== 'manage'} />
</ModalContent>
);
};
Loading