Skip to content

Commit

Permalink
📁 Several Drive fixes (#2762)
Browse files Browse the repository at this point in the history
* Add "copy public link" into browser

* Make sure we search in the current company

* Fix unallowed access to Drive listing

* Fix preview modal

* Small change on the canary version note
  • Loading branch information
RomaricMourgues authored Feb 27, 2023
1 parent b2b7069 commit 3de6bc0
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 330 deletions.
10 changes: 7 additions & 3 deletions twake/backend/node/src/services/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const isCompanyGuest = async (context: CompanyExecutionContext): Promise<
context.user?.id,
);

return userRole === "guest";
return userRole === "guest" || !userRole;
};

/**
Expand Down Expand Up @@ -343,9 +343,10 @@ export const getAccessLevel = async (
repository: Repository<DriveFile>,
context: CompanyExecutionContext & { public_token?: string; twake_tab_token?: string },
): Promise<DriveFileAccessLevel | "none"> => {
if (!id || id === "root") return (await isCompanyGuest(context)) ? "read" : "manage";
if (!id || id === "root")
return !context?.user?.id ? "none" : (await isCompanyGuest(context)) ? "read" : "manage";
if (id === "trash")
return (await isCompanyGuest(context))
return (await isCompanyGuest(context)) || !context?.user?.id
? "none"
: (await isCompanyAdmin(context))
? "manage"
Expand Down Expand Up @@ -377,6 +378,9 @@ export const getAccessLevel = async (
if (itemToken === publicToken) return itemLevel;
}

//From there a user must be logged in
if (!context.user.id) return "none";

const accessEntities = item.access_info.entities || [];

//Users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ export class DocumentsController {
const { search = "", added = "", company_id = "", creator = "" } = request.body;

const options: SearchDocumentsOptions = {
company_id: company_id || context.company.id,
...(search ? { search } : {}),
...(added ? { added } : {}),
...(company_id ? { company_id } : {}),
...(creator ? { creator } : {}),
};

Expand Down
1 change: 1 addition & 0 deletions twake/backend/node/src/services/user/services/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export class CompanyServiceImpl {
}

async getUserRole(companyId: uuid, userId: uuid): Promise<CompanyUserRole> {
if (!userId) return "guest";
const companyUser = await this.getCompanyUser({ id: companyId }, { id: userId });
if (!companyUser) {
return "guest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { openDriveItem, onDriveItemDownloadClick } from '../common';
import ResultContext from './result-context';
import { useCompanyApplications } from 'app/features/applications/hooks/use-company-applications';
import { DriveCurrentFolderAtom } from 'app/views/applications/drive/browser';
import { FolderIcon } from '@heroicons/react/solid';

export default (props: { driveItem: DriveItem & { user?: UserType } }) => {
const input = useRecoilValue(SearchInputState);
Expand Down Expand Up @@ -122,6 +123,14 @@ export const FileResultMedia = (props: {
let iconClassName = 'absolute left-0 top-0 bottom-0 right-0 m-auto w-8 h-8';
if (url) iconClassName = 'absolute bottom-1 left-1 w-6 h-6';

if (file.is_directory) {
return (
<div className={'relative flex bg-blue-100 rounded-md ' + (props.className || '')}>
<FolderIcon className="w-10 h-10 m-auto text-blue-500" />
</div>
);
}

return (
<div className={'relative flex bg-zinc-200 rounded-md ' + (props.className || '')}>
<Media
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DriveTwakeTab } from '../types';
export class DriveTwakeApiClient {
static async getTab(companyId: string, tabId: string) {
return await Api.get<DriveTwakeTab>(
`/internal/services/documents/v1/companies/${companyId}/tab/${tabId}`,
`/internal/services/documents/v1/companies/${companyId}/tabs/${tabId}`,
);
}

Expand All @@ -16,7 +16,7 @@ export class DriveTwakeApiClient {
level: 'write' | 'read',
) {
return await Api.post<DriveTwakeTab, DriveTwakeTab>(
`/internal/services/documents/v1/companies/${companyId}/tab/${tabId}`,
`/internal/services/documents/v1/companies/${companyId}/tabs/${tabId}`,
{
company_id: companyId,
tab_id: tabId,
Expand Down
16 changes: 10 additions & 6 deletions twake/frontend/src/app/features/drive/hooks/use-drive-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ export const useDriveItem = (id: string) => {
};
};

export const usePublicLink = (item?: DriveItem) => {
export const usePublicLink = (item?: DriveItem): string => {
const translator = useRef(short()).current;
const publicLink =
`${document.location.protocol}//${document.location.host}` +
`/shared/${translator.fromUUID(item?.company_id || '')}` +
`/drive/${translator.fromUUID(item?.id || '')}` +
`/t/${item?.access_info?.public?.token}`;
let publicLink = `${document.location.protocol}//${document.location.host}`;
try {
publicLink +=
`/shared/${translator.fromUUID(item?.company_id || '')}` +
`/drive/${translator.fromUUID(item?.id || '')}` +
`/t/${item?.access_info?.public?.token}`;
} catch (e) {
return publicLink;
}

return publicLink;
};
20 changes: 10 additions & 10 deletions twake/frontend/src/app/features/viewer/hooks/use-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ export const useFileViewer = () => {
loading: true,
});

const details = await ViewerAPIClient.getMessageFile(
status.file.company_id || '',
status.file.message_id || '',
status.file.id || '',
);
const details = await ViewerAPIClient.getMessageFile(
status.file.company_id || '',
status.file.message_id || '',
status.file.id || '',
);

setStatus({
...status,
details: details.resource || (details as unknown as MessageFileDetails),
loading: false,
});
setStatus({
...status,
details: details.resource || (details as unknown as MessageFileDetails),
loading: false,
});
}
},
[status.file?.id],
Expand Down
Loading

0 comments on commit 3de6bc0

Please sign in to comment.