Skip to content

Commit

Permalink
📁 Canary drive fix 1 (#2774)
Browse files Browse the repository at this point in the history
* Fix plugins, public write, apps crash

* Asynchronous menus for drive

* Load page before to change it

* Remove id restriction and allow delete only to manage

* Several fixes around versions
  • Loading branch information
RomaricMourgues authored and Labels Bot committed Mar 9, 2023
1 parent e0b45b4 commit 4dfa59e
Show file tree
Hide file tree
Showing 28 changed files with 510 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class MemberServiceImpl {
if (ChannelEntity.isDirectChannel(channel) || ChannelEntity.isPrivateChannel(channel)) {
const isMember = await this.getChannelMember(context.user, channel, undefined, context);

if (!isMember && !context.user.server_request) {
if (!isMember && !context.user.application_id && !context.user.server_request) {
throw CrudException.badRequest("User does not have enough rights to get channels");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ChannelCrudController
context,
);

if (!isMember) {
if (!isMember && !context.user.application_id && !context.user.server_request) {
throw CrudException.badRequest("User does not have enough rights to get channel");
}
}
Expand Down
15 changes: 13 additions & 2 deletions twake/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class DocumentsService {
): Promise<DriveFile> => {
try {
const driveItem = getDefaultDriveItem(content, context);
const driveItemVersion = getDefaultDriveItemVersion(version, context);
let driveItemVersion = getDefaultDriveItemVersion(version, context);

const hasAccess = await checkAccess(
driveItem.parent_id,
Expand Down Expand Up @@ -445,7 +445,7 @@ export class DocumentsService {
}

try {
if (!(await checkAccess(item.id, item, "write", this.repository, context))) {
if (!(await checkAccess(item.id, item, "manage", this.repository, context))) {
this.logger.error("user does not have access drive item ", id);
throw Error("user does not have access to this item");
}
Expand Down Expand Up @@ -569,6 +569,17 @@ export class DocumentsService {

this.notifyWebsocket(item.parent_id, context);

globalResolver.platformServices.messageQueue.publish<DocumentsMessageQueueRequest>(
"services:documents:process",
{
data: {
item,
version: driveItemVersion,
context,
},
},
);

return driveItemVersion;
} catch (error) {
this.logger.error("Failed to create Drive item version", error);
Expand Down
4 changes: 2 additions & 2 deletions twake/backend/node/src/services/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const getAccessLevel = async (
company_id: context.company.id,
application_id: context.user.application_id,
})
)?.application?.access //TODO check precise access right
)?.application?.access //TODO check precise access right for applications
) {
return "manage";
}
Expand Down Expand Up @@ -699,7 +699,7 @@ export const getItemName = async (
context: CompanyExecutionContext,
): Promise<string> => {
try {
let newName = name;
let newName = name.substring(0, 255);
let exists = true;
const children = await repository.find(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ export class DocumentsController {
const context = getDriveExecutionContext(request);
const { id } = request.params;

if (!id) throw new CrudException("Missing id", 400);

return {
...(await globalResolver.services.documents.documents.get(id, context)),
websockets: request.currentUser?.id
Expand Down
40 changes: 24 additions & 16 deletions twake/backend/node/src/services/files/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,10 @@ export class FileServiceImpl {
);

if (options.waitForThumbnail) {
for (let i = 1; i < 100; i++) {
entity = await this.repository.findOne(
{
company_id: context.company.id,
id: entity.id,
},
{},
context,
);
if (entity.metadata.thumbnails_status === "done") {
break;
}
await new Promise(r => setTimeout(r, i * 200));
}
entity = await gr.services.files.getFile({
id: entity.id,
company_id: context.company.id,
});
}
} catch (err) {
entity.metadata.thumbnails_status = "error";
Expand Down Expand Up @@ -247,8 +237,26 @@ export class FileServiceImpl {
return this.getFile({ id, company_id: context.company.id }, context);
}

async getFile(pk: Pick<File, "company_id" | "id">, context?: ExecutionContext): Promise<File> {
return this.repository.findOne(pk, {}, context);
async getFile(
pk: Pick<File, "company_id" | "id">,
context?: ExecutionContext,
options?: {
waitForThumbnail?: boolean;
},
): Promise<File> {
let entity = await this.repository.findOne(pk, {}, context);

if (options?.waitForThumbnail) {
for (let i = 1; i < 100; i++) {
if (entity.metadata.thumbnails_status === "done") {
break;
}
await new Promise(r => setTimeout(r, i * 200));
entity = await this.repository.findOne(pk, {}, context);
}
}

return entity;
}

getThumbnailRoute(file: File, index: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ThreadsController
id: participant.id,
},
);
if (!isMember) {
if (!isMember && !context.user.application_id && !context.user.server_request) {
throw CrudException.notFound("Channel not found");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ViewsController {
id: request.params.channel_id,
},
);
if (!isMember) {
if (!isMember && !context.user.application_id && !context.user.server_request) {
throw CrudException.notFound("Channel not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default ({ pendingFileState, pendingFile }: PropsType) => {
}}
>
<Col className="small-left-margin" flex="auto" style={{ lineHeight: '16px' }}>
{pendingFile.originalFile.name ? (
{pendingFile?.originalFile.name ? (
<Row justify="start" align="middle" wrap={false}>
<Text
ellipsis
Expand All @@ -78,7 +78,7 @@ export default ({ pendingFileState, pendingFile }: PropsType) => {
verticalAlign: 'middle',
}}
>
{capitalize(pendingFile.originalFile.name)}
{capitalize(pendingFile?.originalFile.name)}
</Text>
{isPendingFileStatusPause(pendingFile.status) && (
<Text type="secondary" style={{ verticalAlign: 'middle', marginLeft: 4 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default ({ pendingFilesState, visible }: PropsType) => {
const uploadingFiles = pendingFiles.filter(f => f?.resumable && f.resumable.isUploading());

const remainingSizeTotal = uploadingFiles
.map(f => (1 - f.progress) * f.originalFile.size)
.map(f => (1 - f.progress) * (f?.originalFile?.size || 0))
.reduce((accumulator: number, nextValue: number) => accumulator + nextValue, 0);

const speed =
Expand Down
7 changes: 6 additions & 1 deletion twake/frontend/src/app/components/menus/menus-manager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ class MenusManager extends Observable {

this.notify();
}
openMenu(menu, domRect, positionType, options) {
async openMenu(menu, domRect, positionType, options) {

if(typeof menu === 'function') {
menu = await menu();
}

this.menus = [];

if (this.closeMenuTimeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const useDriveActions = () => {
set(DriveItemAtom(parentId), details);
for (const child of details.children) {
const currentValue = snapshot.getLoadable(DriveItemAtom(child.id)).contents;
set(DriveItemAtom(child.id), { ...currentValue, item: child });
if (!currentValue) {
//only update if not already in cache to avoid concurrent updates
set(DriveItemAtom(child.id), { item: child });
}
}
return details;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const useDriveItem = (id: string) => {
inTrash,
loading: loading,
children: children || [],
details: item,
path: item?.path,
item: item?.item,
access: item?.access,
Expand All @@ -89,8 +90,8 @@ export const useDriveItem = (id: string) => {
};
};

export const usePublicLink = (item?: DriveItem): string => {
const translator = useRef(short()).current;
const translator = short();
export const getPublicLink = (item?: DriveItem): string => {
let publicLink = `${document.location.protocol}//${document.location.host}`;
try {
publicLink +=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class FileUploadService {
pendingFile.resumable.on('fileAdded', () => pendingFile.resumable.upload());

pendingFile.resumable.on('fileProgress', (f: any) => {
const bytesDelta = (f.progress() - pendingFile.progress) * pendingFile.originalFile.size;
const bytesDelta =
(f.progress() - pendingFile.progress) * (pendingFile?.originalFile.size || 0);
const timeDelta = new Date().getTime() - pendingFile.lastProgress;

// To avoid jumping time ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class MessageEditorService extends Observable {
if (this.shouldLimitAttachements(threadId)) {
return Toaster.error(
Languages.t('services.apps.messages.message_editor_service.upload_error_toaster', [
file.originalFile.name,
file?.originalFile?.name || 'unknown file',
this.ATTACHEMENTS_LIMIT,
]),
4,
Expand Down
Loading

0 comments on commit 4dfa59e

Please sign in to comment.