🐛 Fixed problem with deleting files uploaded by an application (#793)
This commit is contained in:
@@ -419,9 +419,9 @@ export const getItemScope = async (
|
||||
context: CompanyExecutionContext,
|
||||
): Promise<"personal" | "shared"> => {
|
||||
let scope: "personal" | "shared";
|
||||
if (item.parent_id.startsWith("user_")) {
|
||||
if (item.parent_id.startsWith("user_") || item.parent_id.startsWith("trash_")) {
|
||||
scope = "personal";
|
||||
} else if (item.parent_id === "root") {
|
||||
} else if (item.parent_id === "root" || item.parent_id === "trash") {
|
||||
scope = "shared";
|
||||
} else {
|
||||
const driveItemParent = await repository.findOne(
|
||||
|
||||
@@ -821,7 +821,8 @@ export class DocumentsService {
|
||||
// Check item belongs to someone
|
||||
if (item.creator !== context?.user?.id) {
|
||||
const creator = await this.userRepository.findOne({ id: item.creator });
|
||||
if (creator.type === "anonymous") {
|
||||
//if the file was created by an application or anonymous user
|
||||
if (creator == null || creator.type === "anonymous") {
|
||||
const loadedCreators = new Map<string, User>();
|
||||
let firstOwnedItem: DriveFile | undefined;
|
||||
for (let i = path.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DriveItemDetailsMockClass,
|
||||
} from "../common/entities/mock_entities";
|
||||
import { Open } from "unzipper";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
describe("the Drive feature", () => {
|
||||
let platform: TestPlatform;
|
||||
@@ -121,6 +122,28 @@ describe("the Drive feature", () => {
|
||||
expect(zip.files.map(f => f.path).sort()).toEqual(fileNames.sort())
|
||||
});
|
||||
|
||||
|
||||
it("Delete document that was uploaded by an application", async () => {
|
||||
const doc = await currentUser.uploadRandomFileAndCreateDocument();
|
||||
expect(doc.id).toBeDefined();
|
||||
|
||||
//update creator files
|
||||
const update = await currentUser.platform.documentService.repository.findOne({id: doc.id})
|
||||
update.creator = randomUUID();
|
||||
await currentUser.platform.documentService.repository.save(update)
|
||||
|
||||
const updated = await currentUser.getDocumentOKCheck(doc.id);
|
||||
|
||||
expect(updated.item.creator).toBe(update.creator);
|
||||
|
||||
let deleteResponse = await currentUser.delete(doc.id);
|
||||
expect(deleteResponse.statusCode).toEqual(200);
|
||||
|
||||
//delete from trash
|
||||
deleteResponse = await currentUser.delete(doc.id);
|
||||
expect(deleteResponse.statusCode).toEqual(200);
|
||||
});
|
||||
|
||||
it("did create a version for a drive item", async () => {
|
||||
const item = await currentUser.createDefaultDocument();
|
||||
const fileUploadResponse = await e2e_createDocumentFile(platform);
|
||||
|
||||
@@ -16,6 +16,7 @@ import StorageAPI from "../../../src/core/platform/services/storage/provider";
|
||||
import {SearchServiceAPI} from "../../../src/core/platform/services/search/api";
|
||||
import Session from "../../../src/services/console/entities/session";
|
||||
import EmailPusherAPI from "../../../src/core/platform/services/email-pusher/provider";
|
||||
import { DocumentsService } from "../../../src/services/documents/services";
|
||||
|
||||
type TokenPayload = {
|
||||
sub: string;
|
||||
@@ -48,6 +49,7 @@ export interface TestPlatform {
|
||||
messageQueue: MessageQueueServiceAPI;
|
||||
authService: AuthServiceAPI;
|
||||
filesService: FileServiceImpl;
|
||||
documentService: DocumentsService;
|
||||
auth: {
|
||||
getJWTToken(payload?: TokenPayload): Promise<string>;
|
||||
};
|
||||
@@ -102,6 +104,7 @@ export async function init(
|
||||
currentSession: uuidv1(),
|
||||
authService: auth,
|
||||
filesService: globalResolver.services.files,
|
||||
documentService: globalResolver.services.documents.documents,
|
||||
auth: {
|
||||
getJWTToken,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user