Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy committed Sep 18, 2023
1 parent 9c8a4cb commit 46d9858
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 77 deletions.
39 changes: 12 additions & 27 deletions tdrive/backend/node/src/services/documents/services/access-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export const getAccessLevel = async (
const isAdmin = !context?.user?.id || (await isCompanyAdmin(context));
const isMember = !context?.user?.id || (await isCompanyMember(context));

if (!id || id === "root") {
if (!context?.user?.id || (await isCompanyGuest(context))) {
return "none";
}
}

if (id.startsWith("user_")) {
if (await isCompanyApplication(context)) return "read";
}

if (context?.user?.id) {
/**
* Drive root directories access management
Expand All @@ -181,9 +191,8 @@ export const getAccessLevel = async (

if (id === "root") {
if (isAdmin) return "manage";
if (isMember) return "read";

return "none";
return "read";
}

if (id === "trash") {
Expand Down Expand Up @@ -214,33 +223,8 @@ export const getAccessLevel = async (
if (item.scope === "shared") {
if (isAdmin) return "manage";
if (isMember) return "read";

return "none";
}
}
/*const isMember = !context?.user?.id || (await isCompanyMember(context));
if (!id || id === "root") {
if (!context?.user?.id || (await isCompanyGuest(context))) {
return "none";
} else {
if (isMember) return "read";
return "manage";
}
}
if (id === "trash")
return (await isCompanyGuest(context)) || !context?.user?.id
? "none"
: (await isCompanyAdmin(context))
? "manage"
: "write";
if (id === "shared_with_me") return "read";
//If it is my personal folder, I have full access
if (id.startsWith("user_")) {
if (id === "user_" + context.user?.id) return "manage";
if (await isCompanyApplication(context)) return "manage";
return "none";
}*/

let publicToken = context.public_token;
const prevalidatedPublicTokenDocumentId = context?.user?.public_token_document_id;
Expand All @@ -256,6 +240,7 @@ export const getAccessLevel = async (
if (!item) {
throw Error("Drive item doesn't exist");
}

/*
* Specific user or channel rule is applied first. Then less restrictive level will be chosen
* between the parent folder and company accesses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class DriveFileDTOBuilder {
"access_info",
"content_keywords",
"creator",
"scope",
],
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class DocumentsService {
throw Error("content mismatch");
}

const updatable = ["access_info", "name", "tags", "parent_id", "description"];
const updatable = ["access_info", "name", "tags", "parent_id", "description", "is_in_trash"];

for (const key of updatable) {
if ((content as any)[key]) {
Expand Down
1 change: 1 addition & 0 deletions tdrive/backend/node/src/services/documents/web/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const documentSchema = {
last_user: { type: "string" },
attachements: { type: "array" },
last_version_cache: fileVersionSchema,
scope: { type: "string" },
},
};

Expand Down
2 changes: 1 addition & 1 deletion tdrive/backend/node/test/e2e/documents/documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ describe("the Drive feature", () => {
DriveItemDetailsMockClass,
listTrashResponse.body,
);

expect(listTrashResult.item.name).toEqual("Trash");
expect(createItemResult).toBeDefined();
expect(createItemResult.scope).toEqual("shared");
expect(listTrashResult.children.some(({ id }) => id === createItemResult.id)).toBeTruthy();
});
Expand Down
36 changes: 2 additions & 34 deletions tdrive/backend/node/test/e2e/documents/public-links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ describe("the public links feature", () => {
platform = null;
});


describe("Basic Flow", () => {

const createItem = async (): Promise<DriveFileMockClass> => {
await TestHelpers.getInstance(platform, true, {companyRole: "admin"});
await TestHelpers.getInstance(platform, true, { companyRole: "admin" });

const item = {
name: "public file",
Expand Down Expand Up @@ -284,33 +282,7 @@ describe("the public links feature", () => {
});
});

describe("Share file from My Drive", () => {

it("Share file from some folder", async () => {
const user = await TestHelpers.getInstance(platform, true);
const anotherUser = await TestHelpers.getInstance(platform, true);

//create directory in "My Drive" and upload a file
const directory = await user.createDirectory("user_" + user.user.id);
const doc = await user.createRandomDocument(directory.id);

//check that another user doesn't see any file
expect((await anotherUser.getDocument(doc.id)).statusCode).toBe(401);

//share file with the public link
await user.shareWithPublicLink(doc, "read");

const token = await anotherUser.getPublicLinkAccessToken(doc);

anotherUser.jwt = token.value;
await anotherUser.getDocumentOKCheck(doc.id);

});

});

describe("Download Folder from shared link", () => {

it("Share folder", async () => {
const user = await TestHelpers.getInstance(platform, true);
const anotherUser = await TestHelpers.getInstance(platform, true);
Expand All @@ -332,9 +304,5 @@ describe("the public links feature", () => {

expect((await anotherUser.getFolder(doc.id)).statusCode).toBe(200);
});

});



});
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ const PublicLinkOptions = (props: {
};


/* useEffect(() => {
useEffect(() => {
props.onChangePassword(usePassword ? password : '');
}, [usePassword, password]); */
}, [usePassword, password]);

useEffect(() => {
props.onChangeExpiration(useExpiration ? expiration : 0);
Expand Down Expand Up @@ -144,18 +144,6 @@ const PublicLinkOptions = (props: {
className="max-w-xs"
value={password}
onChange={e => setPassword(e.target.value)}
onBlur={handlePasswordBlur}
// changes password only when press enter
onKeyPress={e => {
if (e.key === 'Enter') {
props.onChangePassword(password);
e.preventDefault();
if (password) {
copyToClipboard(password);
ToasterService.success(Languages.t('components.public-link-security_password_copied'));
}
}
}}
// saves and copies password
onClick={() => {
if (password) copyToClipboard(password);
Expand Down

0 comments on commit 46d9858

Please sign in to comment.