✨ Shared with me browser view (#82)
* ✨shared with me page, move browser view backend
This commit is contained in:
@@ -157,6 +157,7 @@ export const getAccessLevel = async (
|
||||
: (await isCompanyAdmin(context))
|
||||
? "manage"
|
||||
: "write";
|
||||
if (id === "shared_with_me") return "read";
|
||||
|
||||
//If it is my personal folder, I have full access
|
||||
if (context?.user?.id && id.startsWith("user_")) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
TYPE as DriveTdriveTabRepoType,
|
||||
} from "../entities/drive-tdrive-tab";
|
||||
import {
|
||||
BrowseDetails,
|
||||
CompanyExecutionContext,
|
||||
DocumentsMessageQueueRequest,
|
||||
DriveExecutionContext,
|
||||
@@ -36,6 +37,7 @@ import {
|
||||
getItemName,
|
||||
getPath,
|
||||
getVirtualFoldersNames,
|
||||
isSharedWithMeFolder,
|
||||
isVirtualFolder,
|
||||
updateItemSize,
|
||||
} from "../utils";
|
||||
@@ -87,6 +89,27 @@ export class DocumentsService {
|
||||
return this;
|
||||
}
|
||||
|
||||
browse = async (
|
||||
id: string,
|
||||
options: SearchDocumentsOptions,
|
||||
context: DriveExecutionContext & { public_token?: string },
|
||||
): Promise<BrowseDetails> => {
|
||||
if (isSharedWithMeFolder(id)) {
|
||||
const children = await this.search(options, context);
|
||||
return {
|
||||
access: "read",
|
||||
children: children.getEntities(),
|
||||
nextPage: children.nextPage,
|
||||
path: [] as Array<DriveFile>,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
nextPage: null,
|
||||
...(await this.get(id, context)),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches a drive element
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ExecutionContext } from "../../core/platform/framework/api/crud-service";
|
||||
import { ExecutionContext, Paginable } from "../../core/platform/framework/api/crud-service";
|
||||
import { DriveFile } from "./entities/drive-file";
|
||||
import { FileVersion } from "./entities/file-version";
|
||||
import { SortType } from "../../core/platform/services/search/api";
|
||||
@@ -25,11 +25,14 @@ export type DriveItemDetails = {
|
||||
access: DriveFileAccessLevel | "none";
|
||||
};
|
||||
|
||||
export type BrowseDetails = DriveItemDetails & { nextPage: Paginable };
|
||||
|
||||
export type DriveFileAccessLevel = "read" | "write" | "manage";
|
||||
export type publicAccessLevel = "write" | "read" | "none";
|
||||
|
||||
export type RootType = "root";
|
||||
export type TrashType = "trash";
|
||||
export type SharedWithMeType = "shared_with_me";
|
||||
|
||||
export type DownloadZipBodyRequest = {
|
||||
items: string[];
|
||||
|
||||
@@ -17,13 +17,24 @@ import { stopWords } from "./const";
|
||||
import { DriveFile } from "./entities/drive-file";
|
||||
import { DriveFileMetadata, FileVersion } from "./entities/file-version";
|
||||
import { checkAccess, generateAccessToken } from "./services/access-check";
|
||||
import { CompanyExecutionContext, DriveExecutionContext, RootType, TrashType } from "./types";
|
||||
import {
|
||||
CompanyExecutionContext,
|
||||
DriveExecutionContext,
|
||||
RootType,
|
||||
SharedWithMeType,
|
||||
TrashType,
|
||||
} from "./types";
|
||||
|
||||
const ROOT: RootType = "root";
|
||||
const TRASH: TrashType = "trash";
|
||||
const SHARED_WITH_ME: SharedWithMeType = "shared_with_me";
|
||||
|
||||
export const isVirtualFolder = (id: string) => {
|
||||
return id === ROOT || id === TRASH || id.startsWith("user_");
|
||||
return id === ROOT || id === TRASH || id.startsWith("user_") || id == SHARED_WITH_ME;
|
||||
};
|
||||
|
||||
export const isSharedWithMeFolder = (id: string) => {
|
||||
return id === SHARED_WITH_ME;
|
||||
};
|
||||
|
||||
export const getVirtualFoldersNames = async (id: string, context: DriveExecutionContext) => {
|
||||
|
||||
@@ -141,6 +141,42 @@ export class DocumentsController {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Browse file, special endpoint for TDrive application widget.
|
||||
* Returns the current folder with the filtered content
|
||||
*
|
||||
* @param {FastifyRequest} request
|
||||
* @returns {Promise<DriveItemDetails>}
|
||||
*/
|
||||
browse = async (
|
||||
request: FastifyRequest<{
|
||||
Params: ItemRequestParams;
|
||||
Body: SearchDocumentsBody;
|
||||
Querystring: PaginationQueryParameters & { public_token?: string };
|
||||
}>,
|
||||
): Promise<DriveItemDetails & { websockets: ResourceWebsocket[] }> => {
|
||||
const context = getDriveExecutionContext(request);
|
||||
const { id } = request.params;
|
||||
|
||||
const options: SearchDocumentsOptions = {
|
||||
...request.body,
|
||||
company_id: request.body.company_id || context.company.id,
|
||||
view: DriveFileDTOBuilder.VIEW_SHARED_WITH_ME,
|
||||
onlyDirectlyShared: true,
|
||||
onlyUploadedNotByMe: true,
|
||||
};
|
||||
|
||||
return {
|
||||
...(await globalResolver.services.documents.documents.browse(id, options, context)),
|
||||
websockets: request.currentUser?.id
|
||||
? globalResolver.platformServices.realtime.sign(
|
||||
[{ room: `/companies/${context.company.id}/documents/item/${id}` }],
|
||||
request.currentUser?.id,
|
||||
)
|
||||
: [],
|
||||
};
|
||||
};
|
||||
|
||||
sharedWithMe = async (
|
||||
request: FastifyRequest<{
|
||||
Params: RequestParams;
|
||||
|
||||
@@ -94,6 +94,13 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, _options, next)
|
||||
handler: documentsController.sharedWithMe.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "POST",
|
||||
url: `${baseUrl}/browse/:id`,
|
||||
preValidation: [fastify.authenticate],
|
||||
handler: documentsController.browse.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: `${baseUrl}/tabs/:tab_id`,
|
||||
|
||||
Reference in New Issue
Block a user