Skip to content

Commit

Permalink
fix(chat): hide clientdata folder (Issue #2704) (#2824)
Browse files Browse the repository at this point in the history
Co-authored-by: Irina_Kartun <[email protected]>
  • Loading branch information
IlyaBondar and irinakartun authored Dec 16, 2024
1 parent 16868e4 commit 8952e52
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
2 changes: 2 additions & 0 deletions apps/chat-e2e/src/core/dialFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import { TemperatureSlider } from '@/src/ui/webElements/temperatureSlider';
import { Tooltip } from '@/src/ui/webElements/tooltip';
import { UploadFromDeviceModal } from '@/src/ui/webElements/uploadFromDeviceModal';
import { VariableModalDialog } from '@/src/ui/webElements/variableModalDialog';
import { BucketUtil } from '@/src/utils';
import { allure } from 'allure-playwright';
import path from 'path';
import { APIRequestContext } from 'playwright-core';
Expand Down Expand Up @@ -564,6 +565,7 @@ const dialTest = test.extend<
) => {
const additionalSecondShareUserFileApiHelper = new FileApiHelper(
additionalSecondShareUserRequestContext,
BucketUtil.getAdditionalSecondShareUserBucket(),
);
await use(additionalSecondShareUserFileApiHelper);
},
Expand Down
1 change: 1 addition & 0 deletions apps/chat-e2e/src/core/dialSharedWithMeFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const dialSharedWithMeTest = dialTest.extend<{
) => {
const additionalShareUserFileApiHelper = new FileApiHelper(
additionalShareUserRequestContext,
BucketUtil.getAdditionalShareUserBucket(),
);
await use(additionalShareUserFileApiHelper);
},
Expand Down
12 changes: 10 additions & 2 deletions apps/chat-e2e/src/testData/api/fileApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import { BucketUtil, ItemUtil } from '@/src/utils';
import { expect } from '@playwright/test';
import * as fs from 'fs';
import path from 'path';
import { APIRequestContext } from 'playwright-core';

export class FileApiHelper extends BaseApiHelper {
private readonly userBucket?: string;

constructor(request: APIRequestContext, userBucket?: string) {
super(request);
this.userBucket = userBucket;
}

public async putFile(filename: string, parentPath?: string) {
const encodedFilename = encodeURIComponent(filename);
const encodedParentPath = parentPath
? ItemUtil.getEncodedItemId(parentPath)
: undefined;
const filePath = path.join(Attachment.attachmentPath, filename);
const bufferedFile = fs.readFileSync(filePath);
const baseUrl = `${API.fileHost}/${BucketUtil.getBucket()}`;
const baseUrl = `${API.fileHost}/${this.userBucket ?? BucketUtil.getBucket()}`;
const url = parentPath
? `${baseUrl}/${encodedParentPath}/${encodedFilename}`
: `${baseUrl}/${encodedFilename}`;
Expand Down Expand Up @@ -65,7 +73,7 @@ export class FileApiHelper extends BaseApiHelper {
public async listEntities(nodeType: BackendDataNodeType, url?: string) {
const host = url
? `${API.listingHost}/${url.substring(0, url.length - 1)}`
: `${API.filesListingHost()}/${BucketUtil.getBucket()}`;
: `${API.filesListingHost()}/${this.userBucket ?? BucketUtil.getBucket()}`;
const response = await this.request.get(host, {
params: {
filter: nodeType,
Expand Down
2 changes: 2 additions & 0 deletions apps/chat-e2e/src/testData/api/itemApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { APIRequestContext } from 'playwright-core';

export class ItemApiHelper extends BaseApiHelper {
private readonly userBucket?: string;

constructor(request: APIRequestContext, userBucket?: string) {
super(request);
this.userBucket = userBucket;
}

public async deleteAllData(bucket?: string, isOverlay = false) {
const bucketToUse = this.userBucket ?? bucket;
const conversations = await this.listItems(
Expand Down
6 changes: 6 additions & 0 deletions apps/chat-e2e/src/tests/sharedFilesAttachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ dialSharedWithMeTest(
conversationData,
dataInjector,
fileApiHelper,
additionalShareUserFileApiHelper,
mainUserShareApiHelper,
additionalUserShareApiHelper,
additionalShareUserSendMessage,
Expand Down Expand Up @@ -580,6 +581,11 @@ dialSharedWithMeTest(
await fileApiHelper.putFile(
user1ConversationInFolderImageInResponse1,
);

//upload file into 'All files' section to have it visible
await additionalShareUserFileApiHelper.putFile(
Attachment.heartImageName,
);
},
);

Expand Down
57 changes: 33 additions & 24 deletions apps/chat/src/utils/app/data/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { FolderType } from '@/src/types/folder';
import { HTTPMethod } from '@/src/types/http';

import { CLIENTDATA_PATH } from '@/src/constants/client-data';

import { ApiUtils } from '../../server/api';
import { constructPath } from '../file';
import { getFileRootId } from '../id';
Expand Down Expand Up @@ -121,30 +123,37 @@ export class FileService {
this.getListingUrl({ path: parentPath, resultQuery }),
).pipe(
map((folders: BackendFileFolder[]) => {
return folders.map((folder): FileFolderInterface => {
const relativePath = folder.parentPath
? ApiUtils.decodeApiUrl(folder.parentPath)
: undefined;

return {
id: constructPath(
ApiKeys.Files,
folder.bucket,
relativePath,
folder.name,
),
name: folder.name,
type: FolderType.File,
absolutePath: constructPath(
ApiKeys.Files,
folder.bucket,
relativePath,
),
relativePath: relativePath,
folderId: constructPath(getFileRootId(folder.bucket), relativePath),
serverSynced: true,
};
});
return folders
.filter(
(folder) => !!folder.parentPath || folder.name !== CLIENTDATA_PATH,
)
.map((folder): FileFolderInterface => {
const relativePath = folder.parentPath
? ApiUtils.decodeApiUrl(folder.parentPath)
: undefined;

return {
id: constructPath(
ApiKeys.Files,
folder.bucket,
relativePath,
folder.name,
),
name: folder.name,
type: FolderType.File,
absolutePath: constructPath(
ApiKeys.Files,
folder.bucket,
relativePath,
),
relativePath: relativePath,
folderId: constructPath(
getFileRootId(folder.bucket),
relativePath,
),
serverSynced: true,
};
});
}),
);
}
Expand Down

0 comments on commit 8952e52

Please sign in to comment.