🐛 Do not display deleted items in the shared with me section (#394)
This commit is contained in:
@@ -678,6 +678,7 @@ export class DocumentsService {
|
|||||||
* restore a Drive Document and its children
|
* restore a Drive Document and its children
|
||||||
*
|
*
|
||||||
* @param {string} id - the item id
|
* @param {string} id - the item id
|
||||||
|
* @param item item to restore
|
||||||
* @param {DriveExecutionContext} context - the execution context
|
* @param {DriveExecutionContext} context - the execution context
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
@@ -981,7 +982,7 @@ export class DocumentsService {
|
|||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
],
|
],
|
||||||
$nin: [...(options.onlyDirectlyShared ? [["creator", [context.user.id]] as inType] : [])],
|
$nin: [...(options.onlyUploadedNotByMe ? [["creator", [context.user.id]] as inType] : [])],
|
||||||
$lte: [
|
$lte: [
|
||||||
...(options.last_modified_lt
|
...(options.last_modified_lt
|
||||||
? [["last_modified", options.last_modified_lt] as comparisonType]
|
? [["last_modified", options.last_modified_lt] as comparisonType]
|
||||||
@@ -1011,7 +1012,10 @@ export class DocumentsService {
|
|||||||
const filteredResult = await this.filter(result.getEntities(), async item => {
|
const filteredResult = await this.filter(result.getEntities(), async item => {
|
||||||
try {
|
try {
|
||||||
//skip all the fiels
|
//skip all the fiels
|
||||||
return await checkAccess(item.id, null, "read", this.repository, context);
|
return (
|
||||||
|
!item.is_in_trash &&
|
||||||
|
(await checkAccess(item.id, null, "read", this.repository, context))
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.warn("failed to check item access", error);
|
this.logger.warn("failed to check item access", error);
|
||||||
return false;
|
return false;
|
||||||
@@ -1023,7 +1027,7 @@ export class DocumentsService {
|
|||||||
|
|
||||||
if (options.onlyUploadedNotByMe) {
|
if (options.onlyUploadedNotByMe) {
|
||||||
const filteredResult = await this.filter(result.getEntities(), async item => {
|
const filteredResult = await this.filter(result.getEntities(), async item => {
|
||||||
return item.creator != context.user.id;
|
return item.creator != context.user.id && !item.is_in_trash;
|
||||||
});
|
});
|
||||||
|
|
||||||
return new ListResult(result.type, filteredResult, result.nextPage);
|
return new ListResult(result.type, filteredResult, result.nextPage);
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ export default class UserApi {
|
|||||||
|
|
||||||
async browseDocuments(
|
async browseDocuments(
|
||||||
id: string,
|
id: string,
|
||||||
payload: Record<string, any>
|
payload: Record<string, any> = {}
|
||||||
) {
|
) {
|
||||||
const response = await this.platform.app.inject({
|
const response = await this.platform.app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ describe("The Documents Browser Window and API", () => {
|
|||||||
expect((await anotherUser.browseDocuments("shared_with_me", {pagination: {limitStr: 100}})).children).toHaveLength(1);
|
expect((await anotherUser.browseDocuments("shared_with_me", {pagination: {limitStr: 100}})).children).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("User should be able to delete file that was shared with him with right permissions", async () => {
|
it("User should be able to delete file that was shared with him with 'manage' permissions", async () => {
|
||||||
const oneUser = await UserApi.getInstance(platform, true, {companyRole: "admin"});
|
const oneUser = await UserApi.getInstance(platform, true, {companyRole: "admin"});
|
||||||
const anotherUser = await UserApi.getInstance(platform, true, {companyRole: "admin"});
|
const anotherUser = await UserApi.getInstance(platform, true, {companyRole: "admin"});
|
||||||
|
|
||||||
@@ -170,6 +170,58 @@ describe("The Documents Browser Window and API", () => {
|
|||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("User should be able to delete folder with the files that was shared with him with 'manage' permissions", async () => {
|
||||||
|
const oneUser = await UserApi.getInstance(platform, true);
|
||||||
|
const anotherUser = await UserApi.getInstance(platform, true);
|
||||||
|
|
||||||
|
const dir = await oneUser.createDirectory("user_" + oneUser.user.id);
|
||||||
|
const level2Dir = await oneUser.createDirectory(dir.id);
|
||||||
|
const level2Dir2 = await oneUser.createDirectory(dir.id);
|
||||||
|
await oneUser.uploadAllFilesOneByOne(level2Dir.id);
|
||||||
|
await oneUser.uploadAllFilesOneByOne(level2Dir2.id);
|
||||||
|
await oneUser.uploadAllFilesOneByOne(dir.id);
|
||||||
|
await new Promise(r => setTimeout(r, 5000));
|
||||||
|
|
||||||
|
dir.access_info.entities.push({
|
||||||
|
type: "user",
|
||||||
|
id: anotherUser.user.id,
|
||||||
|
level: "manage",
|
||||||
|
grantor: null,
|
||||||
|
});
|
||||||
|
await oneUser.updateDocument(dir.id, dir);
|
||||||
|
|
||||||
|
const response = await anotherUser.delete(dir.id);
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Shouldn't return files that are in trash", async () => {
|
||||||
|
const oneUser = await UserApi.getInstance(platform, true);
|
||||||
|
const anotherUser = await UserApi.getInstance(platform, true);
|
||||||
|
|
||||||
|
const dir = await oneUser.createDirectory("user_" + oneUser.user.id);
|
||||||
|
|
||||||
|
dir.access_info.entities.push({
|
||||||
|
type: "user",
|
||||||
|
id: anotherUser.user.id,
|
||||||
|
level: "manage",
|
||||||
|
grantor: null,
|
||||||
|
});
|
||||||
|
await oneUser.updateDocument(dir.id, dir);
|
||||||
|
await new Promise(r => setTimeout(r, 3000));
|
||||||
|
|
||||||
|
//can brows files
|
||||||
|
let sharedDocs = await anotherUser.browseDocuments("shared_with_me");
|
||||||
|
expect(sharedDocs.children.length).toBe(1);
|
||||||
|
|
||||||
|
//when
|
||||||
|
const response = await anotherUser.delete(dir.id);
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
await new Promise(r => setTimeout(r, 3000));
|
||||||
|
|
||||||
|
sharedDocs = await anotherUser.browseDocuments("shared_with_me");
|
||||||
|
expect(sharedDocs.children.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { DriveItem } from '@features/drive/types';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { atom, useRecoilState } from 'recoil';
|
import { atom, useRecoilState } from 'recoil';
|
||||||
import Languages from '@features/global/services/languages-service';
|
import Languages from '@features/global/services/languages-service';
|
||||||
|
import RouterServices from "features/router/services/router-service";
|
||||||
|
|
||||||
|
|
||||||
export type ConfirmTrashModalType = {
|
export type ConfirmTrashModalType = {
|
||||||
@@ -39,6 +40,7 @@ const ConfirmTrashModalContent = ({ items }: { items: DriveItem[] }) => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [state, setState] = useRecoilState(ConfirmTrashModalAtom);
|
const [state, setState] = useRecoilState(ConfirmTrashModalAtom);
|
||||||
const [, setSelected] = useRecoilState(DriveItemSelectedList);
|
const [, setSelected] = useRecoilState(DriveItemSelectedList);
|
||||||
|
const { viewId } = RouterServices.getStateFromRoute();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh(items[0].id);
|
refresh(items[0].id);
|
||||||
@@ -59,10 +61,17 @@ const ConfirmTrashModalContent = ({ items }: { items: DriveItem[] }) => {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await Promise.all((items || []).map(async item => await remove(item.id, item.parent_id)));
|
await Promise.all((items || []).map(async item => {
|
||||||
|
let parent = item.parent_id;
|
||||||
|
if (viewId === "shared_with_me" && parent && parent.startsWith("user_")) {
|
||||||
|
console.log("Refresh shared_with_me");
|
||||||
|
parent = "shared_with_me";
|
||||||
|
}
|
||||||
|
await remove(item.id, parent)
|
||||||
|
}));
|
||||||
setSelected({});
|
setSelected({});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
refresh('trash');
|
await refresh("trash");
|
||||||
setState({ ...state, open: false });
|
setState({ ...state, open: false });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user