Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-1009: Configurable platform #3055

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ Before we could start we need to create workspace/account and associate it with
cd ./tool
rushx run-local create-workspace ws1 -o DevWorkspace # Create workspace
rushx run-local create-account user1 -p 1234 -f John -l Appleseed # Create account
rushx run-local assign-workspace user1 ws1 # Assign worksapce to user
rushx run-local configure sanity-ws --list --enable '*' # Enable all modules, then if they are not yet intended to be used by wide audience.
rushx run-local assign-workspace user1 ws1 # Assign workspace to user

```

Following URL http://localhost:8087/login:component:LoginApp will lead us to app in production mode.
Following URL http://localhost:8087 will lead us to app in production mode.

## Run in development mode

Expand All @@ -39,7 +41,7 @@ cd dev/prod
rushx dev-server
```

Then go to http://localhost:8080/login:component:LoginApp
Then go to http://localhost:8080

## Update project structure and database

Expand All @@ -51,6 +53,7 @@ rush build
```

It also might be required to upgrade running database.

```bash
cd ./dev/tool
rushx upgrade
Expand All @@ -73,22 +76,12 @@ rush bundle
rush docker:build
## creates test docker containers and setups test database
./prepare.sh
## runs UI tests
## runs UI tests
rushx uitest
```


## Package publishing

```
npm login --registry=https://npm.pkg.github.com --scope=@hcengineering/anticrm
npm publish
```


### Libretranslate

```bash
pip install libretranslate
libretranslate --ssl --host 0.0.0.0 --port 4500 --load-only en,ru --update-models
node ./common/scripts/bump.js packageName
```
1 change: 1 addition & 0 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ services:
- MINIO_SECRET_KEY=minioadmin
- FRONT_URL=http://front:8080
- SES_URL=http://localhost:8091
- MODEL_ENABLED=*
restart: unless-stopped
collaborator:
image: hardcoreeng/collaborator
Expand Down
6 changes: 4 additions & 2 deletions dev/prod/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// limitations under the License.
//

import { addLocation } from '@hcengineering/platform'
import { Plugin, addLocation } from '@hcengineering/platform'

import { activityId } from '@hcengineering/activity'
import { attachmentId } from '@hcengineering/attachment'
import { automationId } from '@hcengineering/automation'
import { boardId } from '@hcengineering/board'
import { calendarId } from '@hcengineering/calendar'
import { chunterId } from '@hcengineering/chunter'
import { clientId } from '@hcengineering/client'
import client, { clientId } from '@hcengineering/client'
import { contactId } from '@hcengineering/contact'
import document, { documentId } from '@hcengineering/document'
import gmail, { gmailId } from '@hcengineering/gmail'
Expand Down Expand Up @@ -153,6 +153,8 @@ export async function configurePlatform() {
addLocation(bitrixId, () => import(/* webpackChunkName: "bitrix" */ '@hcengineering/bitrix-resources'))
addLocation(requestId, () => import(/* webpackChunkName: "request" */ '@hcengineering/request-resources'))

setMetadata(client.metadata.FilterModel, true)
setMetadata(client.metadata.ExtraPlugins, ['preference' as Plugin])

setMetadata(workbench.metadata.PlatformTitle, 'Platform')
}
2 changes: 1 addition & 1 deletion dev/storage/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class InMemoryTxAdapter extends DummyDbAdapter implements TxAdapter {
}

async getModel (): Promise<Tx[]> {
return builder.getTxes()
return builder().getTxes()
}
}

Expand Down
14 changes: 8 additions & 6 deletions dev/tool/src/__start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
import { prepareTools as prepareToolsRaw } from '@hcengineering/server-tool'

import { Data, Tx, Version } from '@hcengineering/core'
import { MinioService } from '@hcengineering/minio'
import { MigrateOperation } from '@hcengineering/model'
import builder, { migrateOperations, version } from '@hcengineering/model-all'
import { MinioService } from '@hcengineering/minio'
import { devTool } from '.'

import { addLocation } from '@hcengineering/platform'
import { serverAttachmentId } from '@hcengineering/server-attachment'
import { serverCalendarId } from '@hcengineering/server-calendar'
import { serverChunterId } from '@hcengineering/server-chunter'
import { serverContactId } from '@hcengineering/server-contact'
import { serverGmailId } from '@hcengineering/server-gmail'
import { serverHrId } from '@hcengineering/server-hr'
import { serverInventoryId } from '@hcengineering/server-inventory'
import { serverLeadId } from '@hcengineering/server-lead'
import { serverNotificationId } from '@hcengineering/server-notification'
import { serverRecruitId } from '@hcengineering/server-recruit'
import { serverRequestId } from '@hcengineering/server-request'
import { serverSettingId } from '@hcengineering/server-setting'
import { serverTagsId } from '@hcengineering/server-tags'
import { serverTaskId } from '@hcengineering/server-task'
import { serverTrackerId } from '@hcengineering/server-tracker'
import { serverTelegramId } from '@hcengineering/server-telegram'
import { serverHrId } from '@hcengineering/server-hr'
import { serverRequestId } from '@hcengineering/server-request'
import { serverTrackerId } from '@hcengineering/server-tracker'
import { serverViewId } from '@hcengineering/server-view'
import { addLocation } from '@hcengineering/platform'

addLocation(serverAttachmentId, () => import('@hcengineering/server-attachment-resources'))
addLocation(serverContactId, () => import('@hcengineering/server-contact-resources'))
Expand All @@ -65,7 +65,9 @@ function prepareTools (): {
version: Data<Version>
migrateOperations: [string, MigrateOperation][]
} {
return { ...prepareToolsRaw(builder.getTxes()), version, migrateOperations }
const enabled = (process.env.MODEL_ENABLED ?? '*').split(',').map((it) => it.trim())
const disabled = (process.env.MODEL_DISABLED ?? '').split(',').map((it) => it.trim())
return { ...prepareToolsRaw(builder(enabled, disabled).getTxes()), version, migrateOperations }
}

devTool(prepareTools, '')
4 changes: 2 additions & 2 deletions dev/tool/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function cleanWorkspace (
minio: MinioService,
elasticUrl: string,
transactorUrl: string,
opt: { recruit: boolean, tracker: boolean, removeTx: boolean }
opt: { recruit: boolean, tracker: boolean, removedTx: boolean }
): Promise<void> {
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup',
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function cleanWorkspace (
await client.connect()
const db = getWorkspaceDB(client, workspaceId)

if (opt.removeTx) {
if (opt.removedTx) {
const txes = await db.collection(DOMAIN_TX).find({}).toArray()

for (const tx of txes) {
Expand Down
70 changes: 70 additions & 0 deletions dev/tool/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Copyright © 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

import core, { BackupClient, Client as CoreClient, TxFactory, WorkspaceId } from '@hcengineering/core'
import { connect } from '@hcengineering/server-tool'

function toLen (val: string, sep: string, len: number): string {
while (val.length < len) {
val += sep
}
return val
}
export async function changeConfiguration (
workspaceId: WorkspaceId,
transactorUrl: string,
cmd: { enable?: string, disable?: string, list?: boolean }
): Promise<void> {
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup'
})) as unknown as CoreClient & BackupClient
try {
const config = await connection.findAll(core.class.PluginConfiguration, {})
if (cmd.list === true) {
for (const c of config) {
if (c.label !== undefined) {
console.log(toLen(c.pluginId, '-', 20), c.enabled)
}
}
}
const enable = (cmd.enable ?? '').trim().split(',')
console.log('enable', enable)
const ops = new TxFactory(core.account.ConfigUser)
if (enable.length > 0) {
const p = config.filter((it) => enable.includes(it.pluginId) || enable.includes('*'))
for (const pp of p) {
if (!pp.enabled) {
console.log('Enabling', pp.pluginId)
await connection.tx(
ops.createTxUpdateDoc(core.class.PluginConfiguration, core.space.Model, pp._id, { enabled: true })
)
}
}
}

if ((cmd.disable ?? '').trim() !== '') {
const p = config.find((it) => it.pluginId === (cmd.disable ?? '').trim())
if (p !== undefined) {
await connection.tx(
ops.createTxUpdateDoc(core.class.PluginConfiguration, core.space.Model, p._id, { enabled: false })
)
}
}
} catch (err: any) {
console.trace(err)
} finally {
await connection.close()
}
}
14 changes: 13 additions & 1 deletion dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { openAIConfigDefaults } from '@hcengineering/openai'
import { cleanArchivedSpaces, cleanRemovedTransactions, cleanWorkspace } from './clean'
import { rebuildElastic } from './elastic'
import { openAIConfig } from './openai'
import { changeConfiguration } from './configuration'

/**
* @public
Expand Down Expand Up @@ -442,7 +443,7 @@ export function devTool (
.option('--recruit', 'Clean recruit', false)
.option('--tracker', 'Clean tracker', false)
.option('--removedTx', 'Clean removed transactions', false)
.action(async (workspace: string, cmd: { recruit: boolean, tracker: boolean, removeTx: boolean }) => {
.action(async (workspace: string, cmd: { recruit: boolean, tracker: boolean, removedTx: boolean }) => {
const { mongodbUri, minio } = prepareTools()
return await withDatabase(mongodbUri, async (db) => {
await cleanWorkspace(
Expand Down Expand Up @@ -470,5 +471,16 @@ export function devTool (
await cleanArchivedSpaces(getWorkspaceId(workspace, productId), transactorUrl)
})

program
.command('configure <workspace>')
.description('clean archived spaces')
.option('--enable <enable>', 'Enable plugin configuration', '')
.option('--disable <disable>', 'Disable plugin configuration', '')
.option('--list', 'List plugin states', false)
.action(async (workspace: string, cmd: { enable: string, disable: string, list: boolean }) => {
console.log(JSON.stringify(cmd))
await changeConfiguration(getWorkspaceId(workspace, productId), transactorUrl, cmd)
})

program.parse(process.argv)
}
2 changes: 2 additions & 0 deletions models/activity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { TClass, TDoc } from '@hcengineering/model-core'
import type { Asset, IntlString, Resource } from '@hcengineering/platform'
import { AnyComponent } from '@hcengineering/ui'

export { activityId } from '@hcengineering/activity'

@Model(activity.class.TxViewlet, core.class.Doc, DOMAIN_MODEL)
export class TTxViewlet extends TDoc implements TxViewlet {
icon!: Asset
Expand Down
1 change: 1 addition & 0 deletions models/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@hcengineering/model-notification": "^0.6.0",
"@hcengineering/model-text-editor": "^0.6.0",
"@hcengineering/core": "^0.6.23",
"@hcengineering/platform": "^0.6.8",
"@hcengineering/model-tags": "^0.6.0",
"@hcengineering/model-calendar": "^0.6.0",
"@hcengineering/model-server-calendar": "^0.6.0",
Expand Down
2 changes: 1 addition & 1 deletion models/all/src/__genmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import builder from '.'
// import { writeFileSync } from 'fs'

const content = JSON.stringify(builder.getTxes(), undefined, 2)
const content = JSON.stringify(builder().getTxes(), undefined, 2)
console.log(content)
// writeFileSync('../../dev/storage/src/model.tx.json', content)
// writeFileSync('../../server/workspace/src/model.tx.json', content)
Expand Down
Loading