From 49ec20d60ea6e744224b70599673cdc8df2bf6ba Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Mon, 5 Jun 2023 10:06:22 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Writeable=20shared=20links?= =?UTF-8?q?=20part=201=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Minor fixes and implemented writeable shared links (no security) * Go t onode 16 for frontend --- .github/workflows/publish-frontend.yml | 2 +- .../src/app/deprecated/user/CurrentUser.ts | 18 --- .../features/companies/hooks/use-companies.ts | 4 +- .../features/drive/api-client/api-client.ts | 4 + .../features/users/hooks/use-current-user.ts | 17 +-- .../app/views/client/body/drive/browser.tsx | 6 +- .../views/client/body/drive/context-menu.tsx | 6 +- .../views/client/body/drive/header-path.tsx | 4 +- .../update-access/public-link-access.tsx | 2 +- .../app/views/client/body/drive/shared.tsx | 15 ++- .../frontend/src/app/views/client/index.tsx | 2 +- .../src/app/views/client/side-bar/actions.tsx | 112 ++++++++++-------- 12 files changed, 97 insertions(+), 95 deletions(-) diff --git a/.github/workflows/publish-frontend.yml b/.github/workflows/publish-frontend.yml index 384290ea..0fac6d6a 100644 --- a/.github/workflows/publish-frontend.yml +++ b/.github/workflows/publish-frontend.yml @@ -44,7 +44,7 @@ jobs: path: tdrive/frontend/build/ publish-frontend: -# needs: build-frontend + # needs: build-frontend runs-on: ubuntu-20.04 if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/qa' || github.ref == 'refs/heads/canary' steps: diff --git a/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts b/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts index e3fff98d..ca5dcbb3 100755 --- a/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts +++ b/tdrive/frontend/src/app/deprecated/user/CurrentUser.ts @@ -51,24 +51,6 @@ class CurrentUser extends Observable { return getUser(Login.currentUserId); } - updateUserStatus = (newStatus: string[]) => { - return () => { - const { updateStatus } = useCurrentUser(); - updateStatus(newStatus); - }; - }; - - async updateStatusIcon(status: string[]) { - const update = { - id: Login.currentUserId, - status_icon: status, - }; - - Collections.get('users').updateObject(update); - this.updateUserStatus(status); - await UserAPIClient.updateUserStatus(`${status[0]} ${status[1]}`); - } - updateTutorialStatus(key: string, set_false?: unknown) { const user = this.get(); if (!user) { diff --git a/tdrive/frontend/src/app/features/companies/hooks/use-companies.ts b/tdrive/frontend/src/app/features/companies/hooks/use-companies.ts index 45c9c366..01406a40 100644 --- a/tdrive/frontend/src/app/features/companies/hooks/use-companies.ts +++ b/tdrive/frontend/src/app/features/companies/hooks/use-companies.ts @@ -106,7 +106,9 @@ export const useCurrentCompanyRealtime = () => { * @param user * @returns CompanyType | undefined */ -export function useBestCandidateCompany(user: UserType | undefined): CompanyType | undefined { +export function useBestCandidateCompany( + user: UserType | undefined | null, +): CompanyType | undefined { const routerCompanyId = useRouterCompany(); const storageCompanyId = (LocalStorage.getItem('default_company_id') as string) || null; diff --git a/tdrive/frontend/src/app/features/drive/api-client/api-client.ts b/tdrive/frontend/src/app/features/drive/api-client/api-client.ts index 24132e69..eb967d4a 100644 --- a/tdrive/frontend/src/app/features/drive/api-client/api-client.ts +++ b/tdrive/frontend/src/app/features/drive/api-client/api-client.ts @@ -24,6 +24,10 @@ export const setPublicLinkToken = (token: string | null) => { publicLinkToken = token; }; +export const getPublicLinkToken = () => { + return publicLinkToken; +}; + export const setTdriveTabToken = (token: string | null) => { tdriveTabToken = token; }; diff --git a/tdrive/frontend/src/app/features/users/hooks/use-current-user.ts b/tdrive/frontend/src/app/features/users/hooks/use-current-user.ts index e847ab38..c3743705 100644 --- a/tdrive/frontend/src/app/features/users/hooks/use-current-user.ts +++ b/tdrive/frontend/src/app/features/users/hooks/use-current-user.ts @@ -6,18 +6,17 @@ import { useRecoilState } from 'recoil'; import { CurrentUserState } from '../state/atoms/current-user'; import { useRealtimeRoom } from '@features/global/hooks/use-realtime'; import Languages from '@features/global/services/languages-service'; -import { RealtimeApplicationEvent } from '@features/global/types/realtime-types'; import { useSetUserList } from './use-user-list'; +import { getPublicLinkToken } from 'app/features/drive/api-client/api-client'; export const useCurrentUser = () => { - console.log("getting current user"); const [user, setUser] = useRecoilState(CurrentUserState); const { set: setUserList } = useSetUserList('useCurrentUser'); //Depreciated way to get use update from LoginService LoginService.recoilUpdateUser = setUser; useEffect(() => { - if (!user) { + if (!user && !getPublicLinkToken()) { LoginService.init(); LoginService.login({}); } @@ -29,17 +28,13 @@ export const useCurrentUser = () => { if (user?.preferences?.locale) Languages.setLanguage(user?.preferences?.locale); }, [user?.preferences?.locale]); - const updateStatus = async (userStatus: string[]) => { - await UserAPIClient.updateUserStatus(`${userStatus[0]} ${userStatus[1]}`); - - await refresh(); - }; - const refresh = async () => { - await LoginService.updateUser(); + if (!getPublicLinkToken()) { + await LoginService.updateUser(); + } }; - return { user, refresh, updateStatus }; + return { user, refresh }; }; export const useCurrentUserRealtime = () => { diff --git a/tdrive/frontend/src/app/views/client/body/drive/browser.tsx b/tdrive/frontend/src/app/views/client/body/drive/browser.tsx index ccce5ed4..6114173b 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/browser.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/browser.tsx @@ -118,7 +118,7 @@ export default memo( return ( @@ -167,7 +167,7 @@ export default memo( -
+
{folders.length > 0 && ( <> Folders diff --git a/tdrive/frontend/src/app/views/client/body/drive/context-menu.tsx b/tdrive/frontend/src/app/views/client/body/drive/context-menu.tsx index b9f670d2..c3ec7844 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/context-menu.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/context-menu.tsx @@ -8,7 +8,7 @@ import { PropertiesModalAtom } from './modals/properties'; import { SelectorModalAtom } from './modals/selector'; import { AccessModalAtom } from './modals/update-access'; import { VersionsModalAtom } from './modals/versions'; -import { DriveApiClient } from '@features/drive/api-client/api-client'; +import { DriveApiClient, getPublicLinkToken } from '@features/drive/api-client/api-client'; import { useDriveActions } from '@features/drive/hooks/use-drive-actions'; import { getPublicLink } from '@features/drive/hooks/use-drive-item'; import { useDrivePreview } from '@features/drive/hooks/use-drive-preview'; @@ -71,8 +71,8 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s }, { type: 'menu', - text: 'Manage access', - hide: access === 'read', + text: 'Manage access and sharing', + hide: access === 'read' || getPublicLinkToken(), onClick: () => setAccessModalState({ open: true, id: item.id }), }, { diff --git a/tdrive/frontend/src/app/views/client/body/drive/header-path.tsx b/tdrive/frontend/src/app/views/client/body/drive/header-path.tsx index 0b5507dd..b9f6b96b 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/header-path.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/header-path.tsx @@ -95,7 +95,7 @@ const PathItem = ({ href="#" className="text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white" onClick={evt => { - if (first) { + if (first && user?.id) { MenusManager.openMenu( [ { type: 'menu', text: 'Home', onClick: () => onClick('root') }, @@ -114,7 +114,7 @@ const PathItem = ({ {item?.access_info?.public?.level && item?.access_info?.public?.level !== 'none' && ( )} - {first && ( + {first && !!user?.id && ( diff --git a/tdrive/frontend/src/app/views/client/body/drive/modals/update-access/public-link-access.tsx b/tdrive/frontend/src/app/views/client/body/drive/modals/update-access/public-link-access.tsx index ad2903ed..79ba7af4 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/modals/update-access/public-link-access.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/modals/update-access/public-link-access.tsx @@ -41,7 +41,7 @@ export const PublicLinkManager = ({ id, disabled }: { id: string; disabled?: boo
{ diff --git a/tdrive/frontend/src/app/views/client/body/drive/shared.tsx b/tdrive/frontend/src/app/views/client/body/drive/shared.tsx index 2ce6ec99..b979be2e 100755 --- a/tdrive/frontend/src/app/views/client/body/drive/shared.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/shared.tsx @@ -6,15 +6,20 @@ import Languages from '@features/global/services/languages-service'; import { addApiUrlIfNeeded } from '@features/global/utils/URLUtils'; import RouterService from '@features/router/services/router-service'; import Drive from '@views/client/body/drive'; +import { Button } from 'app/atoms/button/button'; +import { Input } from 'app/atoms/input/input-text'; +import { Base, Subtitle, Title } from 'app/atoms/text'; +import UploadsViewer from 'app/components/file-uploads/uploads-viewer'; +import { useDriveItem } from 'app/features/drive/hooks/use-drive-item'; +import { useDriveUpload } from 'app/features/drive/hooks/use-drive-upload'; import { useParams } from 'react-router-dom'; +import { useSetRecoilState } from 'recoil'; import shortUUID from 'short-uuid'; import Avatar from '../../../../atoms/avatar'; import { setPublicLinkToken } from '../../../../features/drive/api-client/api-client'; import useRouterCompany from '../../../../features/router/hooks/use-router-company'; -import { useDriveItem } from 'app/features/drive/hooks/use-drive-item'; -import { Base, Subtitle, Title } from 'app/atoms/text'; -import { Input } from 'app/atoms/input/input-text'; -import { Button } from 'app/atoms/button/button'; +import { CreateModalAtom } from './modals/create'; +import { CreateModalWithUploadZones } from '../../side-bar/actions'; export default () => { const companyId = useRouterCompany(); @@ -71,6 +76,8 @@ export default () => {
+ +
); }; diff --git a/tdrive/frontend/src/app/views/client/index.tsx b/tdrive/frontend/src/app/views/client/index.tsx index ebb23121..4d8bc807 100755 --- a/tdrive/frontend/src/app/views/client/index.tsx +++ b/tdrive/frontend/src/app/views/client/index.tsx @@ -46,7 +46,7 @@ export default React.memo((): JSX.Element => { <>
setMenuIsOpen(true)} /> -
+
{ +export const CreateModalWithUploadZones = () => { const companyId = useRouterCompany(); + const uploadZoneRef = useRef(null); + const uploadFolderZoneRef = useRef(null); + const setCreationModalState = useSetRecoilState(CreateModalAtom); + const { uploadTree, uploadFromUrl } = useDriveUpload(); + const [parentId, _] = useRecoilState(DriveCurrentFolderAtom('root')); + + return ( + <> + { + const tree = await getFilesTree(event); + setCreationModalState({ parent_id: '', open: false }); + uploadTree(tree, { + companyId, + parentId, + }); + }} + /> + { + const tree = await getFilesTree(event); + setCreationModalState({ parent_id: '', open: false }); + uploadTree(tree, { + companyId, + parentId, + }); + }} + /> + uploadFolderZoneRef.current?.open()} + selectFromDevice={() => uploadZoneRef.current?.open()} + addFromUrl={(url, name) => { + setCreationModalState({ parent_id: '', open: false }); + uploadFromUrl(url, name, { + companyId, + parentId, + }); + }} + /> + + ); +}; + +export default () => { const [parentId, _] = useRecoilState(DriveCurrentFolderAtom('root')); const { access, item, inTrash } = useDriveItem(parentId); const { children: trashChildren } = useDriveItem('trash'); const uploadZoneRef = useRef(null); - const uploadFolderZoneRef = useRef(null); const setConfirmDeleteModalState = useSetRecoilState(ConfirmDeleteModalAtom); const setCreationModalState = useSetRecoilState(CreateModalAtom); - const { uploadTree, uploadFromUrl } = useDriveUpload(); const openItemModal = useCallback(() => { if (item?.id) setCreationModalState({ open: true, parent_id: item.id }); }, [item?.id, setCreationModalState]); return ( -
+
- { - const tree = await getFilesTree(event); - setCreationModalState({ parent_id: '', open: false }); - uploadTree(tree, { - companyId, - parentId, - }); - }} - /> - { - const tree = await getFilesTree(event); - setCreationModalState({ parent_id: '', open: false }); - uploadTree(tree, { - companyId, - parentId, - }); - }} - /> - uploadFolderZoneRef.current?.open()} - selectFromDevice={() => uploadZoneRef.current?.open()} - addFromUrl={(url, name) => { - setCreationModalState({ parent_id: '', open: false }); - uploadFromUrl(url, name, { - companyId, - parentId, - }); - }} - /> + {inTrash && access === 'manage' && ( <>