🐛 User is not able to delete or move files that was share with him (#392)

This commit is contained in:
Anton Shepilov
2024-02-29 10:43:39 +01:00
committed by GitHub
parent 4f372adddc
commit cb3dcb13ca
6 changed files with 38 additions and 38 deletions
@@ -419,7 +419,7 @@ export const getItemScope = async (
context: CompanyExecutionContext,
): Promise<"personal" | "shared"> => {
let scope: "personal" | "shared";
if (item.parent_id === "user_" + context.user?.id) {
if (item.parent_id.startsWith("user_")) {
scope = "personal";
} else if (item.parent_id === "root") {
scope = "shared";
@@ -467,6 +467,7 @@ export class DocumentsService {
if ((content as any)[key]) {
if (
key === "parent_id" &&
oldParent !== item.parent_id &&
!(await canMoveItem(item.id, content.parent_id, this.repository, context))
) {
throw Error("Move operation not permitted");
@@ -495,7 +496,7 @@ export class DocumentsService {
});
}
item.access_info.entities.forEach(async info => {
item.access_info.entities.forEach(info => {
if (!info.grantor) {
info.grantor = context.user.id;
}
@@ -528,14 +529,11 @@ export class DocumentsService {
if (oldParent) {
item.scope = await getItemScope(item, this.repository, context);
this.repository.save(item);
await this.repository.save(item);
await updateItemSize(oldParent, this.repository, context);
this.notifyWebsocket(oldParent, context);
}
this.notifyWebsocket(item.parent_id, context);
if (item.parent_id === this.TRASH) {
//When moving to trash we recompute the access level to make them flat
item.access_info = await makeStandaloneAccessLevel(
@@ -715,7 +713,7 @@ export class DocumentsService {
throw new CrudException("User does not have access to this item or its children", 401);
}
if (isInTrash(item, this.repository, context)) {
if (await isInTrash(item, this.repository, context)) {
if (item.is_in_trash != true) {
if (item.scope === "personal") {
item.parent_id = "user_" + context.user.id;
@@ -726,9 +724,7 @@ export class DocumentsService {
item.is_in_trash = false;
}
}
this.repository.save(item);
this.notifyWebsocket("trash", context);
await this.repository.save(item);
};
/**
@@ -805,10 +801,9 @@ export class DocumentsService {
notificationReceiver: item.creator,
});
this.notifyWebsocket(item.parent_id, context);
await updateItemSize(item.parent_id, this.repository, context);
globalResolver.platformServices.messageQueue.publish<DocumentsMessageQueueRequest>(
await globalResolver.platformServices.messageQueue.publish<DocumentsMessageQueueRequest>(
"services:documents:process",
{
data: {
@@ -938,7 +933,7 @@ export class DocumentsService {
}
}
archive.finalize();
await archive.finalize();
return archive;
};
@@ -42,25 +42,4 @@ export class UserExternalLinksServiceImpl {
return user;
}
async createExternalGroup(
group: ExternalGroup,
context?: ExecutionContext,
): Promise<ExternalGroup> {
await this.externalGroupRepository.save(group, context);
//Save company provider and provider id here
const internalCompany = await this.companyRepository.findOne(
{ id: group.company_id },
{},
context,
);
if (internalCompany) {
internalCompany.identity_provider = group.service_id;
internalCompany.identity_provider_id = group.external_id;
this.companyRepository.save(internalCompany, context);
}
return group;
}
}