Skip to content

Commit

Permalink
Merge branch 'main' into release/v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlinagora authored Oct 15, 2024
2 parents c4ea3f7 + 359a537 commit 03435a3
Show file tree
Hide file tree
Showing 60 changed files with 3,136 additions and 3,156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: e2e-mongo-s3-test
run: |
cd tdrive
docker compose -f docker-compose.tests.yml run --rm -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:all
docker compose -f docker-compose.tests.yml run --rm -e NODE_OPTIONS=--unhandled-rejections=warn node npm run test:all
docker compose -f docker-compose.tests.yml down
- name: e2e-opensearch-test
run: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish_feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ jobs:
filters: |
backend:
- "tdrive/backend/node/**"
- "tdrive/docker/tdrive-node/Dockerfile"
frontend:
- "tdrive/frontend/**"
- "tdrive/docker/tdrive-frontend/**"
onlyoffice-connector:
- "tdrive/connectors/onlyoffice-connector/**"
- "tdrive/docker/onlyoffice-connector/Dockerfile"
ldap-sync:
- "tdrive/backend/utils/ldap-sync/**"
- "tdrive/docker/tdrive-ldap-sync/Dockerfile"
nextcloud-migration:
- "tdrive/backend/utils/nextcloud-migration/**"
- "tdrive/docker/tdrive-nextcloud-migration/Dockerfile"
publish-feature:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions tdrive/backend/node/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
"defaultLanguage": "DRIVE_DEFAULT_LANGUAGE",
"defaultCompany": "DRIVE_DEFAULT_COMPANY",
"defaultUserQuota": "DRIVE_DEFAULT_USER_QUOTA",
"featureSearchUsers": "ENABLE_FEATURE_SEARCH_USERS",
"featureDisplayEmail": "ENABLE_FEATURE_DISPLAY_EMAIL",
"featureUserQuota": "ENABLE_FEATURE_USER_QUOTA"
"featureUserQuota": "ENABLE_FEATURE_USER_QUOTA",
"featureManageAccess": "ENABLE_FEATURE_MANAGE_ACCESS"
}
}
4 changes: 2 additions & 2 deletions tdrive/backend/node/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"mongodb": {
"uri": "mongodb://mongo:27017",
"database": "tdrive"
},
}
},
"message-queue": {
"// possible 'type' values are": "'amqp' or 'local'",
Expand Down Expand Up @@ -114,9 +114,9 @@
},
"drive": {
"featureSharedDrive": true,
"featureSearchUsers": true,
"featureDisplayEmail": true,
"featureUserQuota": false,
"featureManageAccess": true,
"defaultCompany": "00000000-0000-4000-0000-000000000000",
"defaultUserQuota": 200000000
},
Expand Down
10 changes: 5 additions & 5 deletions tdrive/backend/node/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hello": "Hello",
"virtual-folder.shared-drive": "Shared Drive",
"virtual-folder.my-drive": "My Drive",
"virtual-folder.trash": "Trash"
}
"hello": "Hello",
"virtual-folder.my-drive": "My Drive",
"virtual-folder.shared-drive": "Shared Drive",
"virtual-folder.trash": "Trash"
}
2 changes: 1 addition & 1 deletion tdrive/backend/node/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hello": "Bonjour",
"virtual-folder.shared-drive": "Disque Partagé",
"virtual-folder.my-drive": "Mon disque",
"virtual-folder.shared-drive": "Disque Partagé",
"virtual-folder.trash": "Corbeille"
}
10 changes: 5 additions & 5 deletions tdrive/backend/node/locales/ru.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hello": "Привет",
"virtual-folder.shared-drive": "Общий Диск",
"virtual-folder.my-drive": "Мой Диск",
"virtual-folder.trash": "Корзина"
}
"hello": "Привет",
"virtual-folder.my-drive": "Мой Диск",
"virtual-folder.shared-drive": "Общий Диск",
"virtual-folder.trash": "Корзина"
}
6 changes: 6 additions & 0 deletions tdrive/backend/node/locales/vi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hello": "Xin chào",
"virtual-folder.my-drive": "Drive của tôi",
"virtual-folder.shared-drive": "Drive chia sẻ",
"virtual-folder.trash": "Thùng rác"
}
6 changes: 0 additions & 6 deletions tdrive/backend/node/locales/vn.json

This file was deleted.

9 changes: 3 additions & 6 deletions tdrive/backend/node/src/cli/cmds/dev_cmds/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import parseYargsCommaSeparatedStringArray from "../../utils/yargs-comma-array";
import { NonPlatformCommandYargsBuilder } from "../../utils/non-plaform-command-yargs-builder";
import { openWithSystemViewer } from "../../../utils/exec";

const CORE_LANGUAGES = "en fr ru vn".split(" ");

// const iso639ToTwakeDriveISO = set1 => (set1 === "vi" ? "vn" : set1);
const twakeDriveISOToISO639 = twakeLang => (twakeLang === "vn" ? "vi" : twakeLang);
const CORE_LANGUAGES = "en fr ru vi".split(" ");

const TEMPLATE_VAR_NAME = "TDCLI_TRANSLATOR_URL";
const urlToTranslate = (text: string, to: string, from?: string) => {
const template = process.env[TEMPLATE_VAR_NAME];
if (!template) throw new Error(`${TEMPLATE_VAR_NAME} environment variable must be set.`);
const variables = {
to: twakeDriveISOToISO639(to),
from: from ? twakeDriveISOToISO639(from) : from,
to,
from,
text,
};
return template.replace(/%\{([^}:]+)(?::([^}]+))?\}/g, (_, varName, absentValue) => {
Expand Down
4 changes: 4 additions & 0 deletions tdrive/backend/node/src/cli/cmds/editing_session_cmds/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ async function report(platform: TdrivePlatform, args: ListArguments) {
` - ${formatTS(version.date_added)} by ${await formatUser(version.creator_id)}`,
);
console.error(` - id: ${version.id}`);
if (dfile.name != version.filename)
console.error(` - filename: ${JSON.stringify(version.filename)}`);
if (dfile.name != version.file_metadata.name)
console.error(` - meta.name: ${JSON.stringify(version.file_metadata.name)}`);
console.error(
` - size: ${version.file_metadata.size} (${
version.file_metadata.size > previousSize ? "+" : ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ export class CrudException extends Error {
}

export interface Paginable {
/**
* In page token can be different type of data depending of the source.
* For ES it will be exactly page token, identifier of the next page.
* For PostgreSQL it will be number of the next page.
* For MongoDB it will be offset.
* This information is relevant for the Service/Repository level, in the controller
* we have only offset there for every type of source because in the "browse" controller
* we do not pass "next_page_token" to frontend and hence we are calculating
* offset on the frontend side and then passing offset to DocumentService.
*
*/
page_token?: string;
limitStr?: string;
reversed?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Connector, UpsertOptions } from ".";
import { ConnectionOptions, DatabaseType } from "../..";
import { FindOptions } from "../repository/repository";
import { ColumnDefinition, EntityDefinition } from "../types";
import { ListResult } from "../../../../../framework/api/crud-service";
import { ListResult, Paginable, Pagination } from "../../../../../framework/api/crud-service";

export abstract class AbstractConnector<T extends ConnectionOptions> implements Connector {
constructor(protected type: DatabaseType, protected options: T, protected secret: string) {}
Expand Down Expand Up @@ -38,6 +38,8 @@ export abstract class AbstractConnector<T extends ConnectionOptions> implements
options: FindOptions,
): Promise<ListResult<EntityType>>;

abstract getOffsetPagination(options: Paginable): Pagination;

getOptions(): T {
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DatabaseType } from "../..";
import { MongoConnectionOptions } from "./mongodb/mongodb";
import { ColumnDefinition, EntityDefinition } from "../types";
import { FindOptions } from "../repository/repository";
import { ListResult } from "../../../../../framework/api/crud-service";
import { ListResult, Paginable, Pagination } from "../../../../../framework/api/crud-service";
import { PostgresConnectionOptions } from "./postgres/postgres";

export * from "./mongodb/mongodb";
Expand Down Expand Up @@ -92,6 +92,13 @@ export interface Connector extends Initializable {
filters: any,
options: FindOptions,
): Promise<ListResult<EntityType>>;

/**
* Get the pagination for the given options where the pagination is offset based
* @param options Paginable
* @returns Pagination
*/
getOffsetPagination(options: Paginable): Pagination;
}

export declare type ConnectionOptions = MongoConnectionOptions | PostgresConnectionOptions;
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,9 @@ export class MongoConnector extends AbstractConnector<MongoConnectionOptions> {
const nextPage: Paginable = new Pagination(nextToken, options.pagination.limitStr || "100");
return new ListResult<Table>(entityDefinition.type, entities, nextPage);
}

getOffsetPagination(options: Paginable): Pagination {
const { page_token, limitStr } = options;
return new Pagination(`${page_token}`, `${limitStr}`, options.reversed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ export class PostgresConnector extends AbstractConnector<PostgresConnectionOptio
throw err;
}
}

getOffsetPagination(options: Paginable): Pagination {
const { page_token, limitStr } = options;
const pageNumber = parseInt(page_token) / parseInt(limitStr);
return new Pagination(`${pageNumber}`, `${limitStr}`, options.reversed);
}
}

export type TableRowInfo = {
Expand Down
85 changes: 51 additions & 34 deletions tdrive/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class DocumentsService {
defaultQuota: number = config.has("drive.defaultUserQuota")
? config.get("drive.defaultUserQuota")
: 0;
manageAccessEnabled: boolean = config.has("drive.featureManageAccess")
? config.get("drive.featureManageAccess")
: false;
logger: TdriveLogger = getLogger("Documents Service");

async init(): Promise<this> {
Expand Down Expand Up @@ -222,18 +225,12 @@ export class DocumentsService {
if (options?.sort) {
sortField = this.getSortFieldMapping(options.sort);
}
const dbType = await globalResolver.database.getConnector().getType();

// Initialize pagination
let pagination;

if (options?.pagination) {
const { page_token, limitStr } = options.pagination;
const pageNumber =
dbType === "mongodb" ? parseInt(page_token) : parseInt(page_token) / parseInt(limitStr);

pagination = new Pagination(`${pageNumber}`, `${limitStr}`, false);
}
if (options?.pagination)
pagination = globalResolver.database.getConnector().getOffsetPagination(options.pagination);

let children = isDirectory
? (
Expand Down Expand Up @@ -562,33 +559,38 @@ export class DocumentsService {
oldParent = item.parent_id;
}
if (key === "access_info") {
const sharedWith = content.access_info.entities.filter(
info =>
info.type === "user" &&
info.id !== context.user.id &&
!item.access_info.entities.find(entity => entity.id === info.id),
);
// if manage access is disabled, we don't allow changing access level
if (!this.manageAccessEnabled) {
delete content.access_info;
} else if (content.access_info) {
const sharedWith = content.access_info.entities.filter(
info =>
info.type === "user" &&
info.id !== context.user.id &&
!item.access_info.entities.find(entity => entity.id === info.id),
);

item.access_info = content.access_info;
item.access_info = content.access_info;

if (sharedWith.length > 0) {
// Notify the user that the document has been shared with them
this.logger.info("Notifying user that the document has been shared with them: ", {
sharedWith,
});
gr.services.documents.engine.notifyDocumentShared({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: sharedWith[0].id,
});
}

if (sharedWith.length > 0) {
// Notify the user that the document has been shared with them
this.logger.info("Notifying user that the document has been shared with them: ", {
sharedWith,
});
gr.services.documents.engine.notifyDocumentShared({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: sharedWith[0].id,
item.access_info.entities.forEach(info => {
if (!info.grantor) {
info.grantor = context.user.id;
}
});
}

item.access_info.entities.forEach(info => {
if (!info.grantor) {
info.grantor = context.user.id;
}
});
} else if (key === "name") {
renamedTo = item.name = await getItemName(
content.parent_id || item.parent_id,
Expand Down Expand Up @@ -1148,7 +1150,15 @@ export class DocumentsService {
}

if (file) {
const fileEntity = await globalResolver.services.files.save(null, file, options, context);
const fileEntity = await globalResolver.services.files.save(
null,
file,
{
...options,
filename: options.filename ?? driveFile.name,
},
context,
);

await globalResolver.services.documents.documents.createVersion(
driveFile.id,
Expand All @@ -1158,6 +1168,7 @@ export class DocumentsService {
file_metadata: {
external_id: fileEntity.id,
source: "internal",
name: file.filename ?? driveFile.name,
},
},
context,
Expand All @@ -1184,8 +1195,14 @@ export class DocumentsService {
)}`,
);
} catch (error) {
logger.error({ error: `${error}` }, "Failed to cancel editing Drive item");
CrudException.throwMe(error, new CrudException("Failed to cancel editing Drive item", 500));
logger.error(
{ error: `${error}` },
`Failed to ${keepEditing ? "update" : "end"} editing Drive item`,
);
CrudException.throwMe(
error,
new CrudException(`Failed to ${keepEditing ? "update" : "end"} editing Drive item`, 500),
);
}
}
};
Expand Down
1 change: 1 addition & 0 deletions tdrive/backend/node/src/services/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export const addDriveItemToArchive = async (
if (item.is_in_trash) return;

if (!item.is_directory) {
// random comment
const file_id = item.last_version_cache.file_metadata.external_id;
const file = await gr.services.files.download(file_id, context);

Expand Down
Loading

0 comments on commit 03435a3

Please sign in to comment.