mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
Merge remote-tracking branch 'origin/main' into ano/create-edit-label
# Conflicts: # plugins/board-resources/src/index.ts
This commit is contained in:
commit
34bf067777
@ -30,7 +30,7 @@ import MoveView from './components/popups/MoveCard.svelte'
|
|||||||
import DateRangePicker from './components/popups/DateRangePicker.svelte'
|
import DateRangePicker from './components/popups/DateRangePicker.svelte'
|
||||||
import CardLabelPresenter from './components/presenters/LabelPresenter.svelte'
|
import CardLabelPresenter from './components/presenters/LabelPresenter.svelte'
|
||||||
import CardDatePresenter from './components/presenters/DatePresenter.svelte'
|
import CardDatePresenter from './components/presenters/DatePresenter.svelte'
|
||||||
import { addCurrentUser, canAddCurrentUser, isArchived, isUnarchived } from './utils/CardUtils'
|
import { addCurrentUser, canAddCurrentUser, isArchived, isUnarchived, archiveCard, unarchiveCard, deleteCard } from './utils/CardUtils'
|
||||||
|
|
||||||
async function showMoveCardPopup (object: Card): Promise<void> {
|
async function showMoveCardPopup (object: Card): Promise<void> {
|
||||||
showPopup(MoveView, { object })
|
showPopup(MoveView, { object })
|
||||||
@ -61,7 +61,10 @@ export default async (): Promise<Resources> => ({
|
|||||||
Join: addCurrentUser,
|
Join: addCurrentUser,
|
||||||
Move: showMoveCardPopup,
|
Move: showMoveCardPopup,
|
||||||
Dates: showDatePickerPopup,
|
Dates: showDatePickerPopup,
|
||||||
Labels: showCardLabelsPopup
|
Labels: showCardLabelsPopup,
|
||||||
|
Archive: archiveCard,
|
||||||
|
SendToBoard: unarchiveCard,
|
||||||
|
Delete: deleteCard
|
||||||
},
|
},
|
||||||
cardActionSupportedHandler: {
|
cardActionSupportedHandler: {
|
||||||
Join: canAddCurrentUser,
|
Join: canAddCurrentUser,
|
||||||
|
@ -9,6 +9,10 @@ export function updateCard (client: Client, card: Card, field: string, value: an
|
|||||||
client.update(card, { [field]: value })
|
client.update(card, { [field]: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deleteCard (card: Card, client: Client): void {
|
||||||
|
client.remove(card)
|
||||||
|
}
|
||||||
|
|
||||||
export function isArchived (card: Card): boolean {
|
export function isArchived (card: Card): boolean {
|
||||||
return !!card.isArchived
|
return !!card.isArchived
|
||||||
}
|
}
|
||||||
@ -45,3 +49,11 @@ export function addCurrentUser (card: Card, client: Client): void {
|
|||||||
members.push(employee)
|
members.push(employee)
|
||||||
updateCard(client, card, 'members', members)
|
updateCard(client, card, 'members', members)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function archiveCard (card: Card, client: Client): void {
|
||||||
|
updateCard(client, card, 'isArchived', true)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unarchiveCard (card: Card, client: Client): void {
|
||||||
|
updateCard(client, card, 'isArchived', false)
|
||||||
|
}
|
||||||
|
43
server/middleware/src/base.ts
Normal file
43
server/middleware/src/base.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// Copyright © 2022 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 { Class, Doc, DocumentQuery, FindOptions, Ref, ServerStorage, Tx } from '@anticrm/core'
|
||||||
|
import { FindAllMiddlewareResult, Middleware, SessionContext, TxMiddlewareResult } from '@anticrm/server-core'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export abstract class BaseMiddleware {
|
||||||
|
constructor (protected readonly storage: ServerStorage, protected readonly next?: Middleware) {
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
||||||
|
return await this.provideFindAll(ctx, _class, query, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async provideTx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
|
||||||
|
if (this.next !== undefined) {
|
||||||
|
return await this.next.tx(ctx, tx)
|
||||||
|
}
|
||||||
|
return [ctx, tx, undefined]
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async provideFindAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
||||||
|
if (this.next !== undefined) {
|
||||||
|
return await this.next.findAll(ctx, _class, query, options)
|
||||||
|
}
|
||||||
|
return [ctx, _class, query, options]
|
||||||
|
}
|
||||||
|
}
|
@ -13,4 +13,6 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
export * from './base'
|
||||||
|
export * from './modified'
|
||||||
export * from './private'
|
export * from './private'
|
||||||
|
43
server/middleware/src/modified.ts
Normal file
43
server/middleware/src/modified.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// Copyright © 2022 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, { Doc, ServerStorage, Timestamp, Tx, TxCreateDoc } from '@anticrm/core'
|
||||||
|
import { Middleware, SessionContext, TxMiddlewareResult } from '@anticrm/server-core'
|
||||||
|
import { BaseMiddleware } from './base'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export class ModifiedMiddleware extends BaseMiddleware implements Middleware {
|
||||||
|
private constructor (storage: ServerStorage, next?: Middleware) {
|
||||||
|
super(storage, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
static create (storage: ServerStorage, next?: Middleware): ModifiedMiddleware {
|
||||||
|
return new ModifiedMiddleware(storage, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
async tx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
|
||||||
|
tx.modifiedOn = Date.now()
|
||||||
|
if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCreateDoc)) {
|
||||||
|
const createTx = tx as TxCreateDoc<Doc & { createOn: Timestamp }>
|
||||||
|
if (createTx.attributes.createOn !== undefined) {
|
||||||
|
createTx.attributes.createOn = tx.modifiedOn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const res = await this.provideTx(ctx, tx)
|
||||||
|
return [res[0], res[1], res[2]]
|
||||||
|
}
|
||||||
|
}
|
@ -17,14 +17,16 @@ import core, { Tx, Doc, Ref, Class, DocumentQuery, FindOptions, ServerStorage, A
|
|||||||
import platform, { PlatformError, Severity, Status } from '@anticrm/platform'
|
import platform, { PlatformError, Severity, Status } from '@anticrm/platform'
|
||||||
import { Middleware, SessionContext, TxMiddlewareResult, FindAllMiddlewareResult } from '@anticrm/server-core'
|
import { Middleware, SessionContext, TxMiddlewareResult, FindAllMiddlewareResult } from '@anticrm/server-core'
|
||||||
import { DOMAIN_PREFERENCE } from '@anticrm/server-preference'
|
import { DOMAIN_PREFERENCE } from '@anticrm/server-preference'
|
||||||
|
import { BaseMiddleware } from './base'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class PrivateMiddleware implements Middleware {
|
export class PrivateMiddleware extends BaseMiddleware implements Middleware {
|
||||||
private readonly targetDomains = [DOMAIN_PREFERENCE]
|
private readonly targetDomains = [DOMAIN_PREFERENCE]
|
||||||
|
|
||||||
private constructor (private readonly storage: ServerStorage, private readonly next?: Middleware) {
|
private constructor (storage: ServerStorage, next?: Middleware) {
|
||||||
|
super(storage, next)
|
||||||
}
|
}
|
||||||
|
|
||||||
static create (storage: ServerStorage, next?: Middleware): PrivateMiddleware {
|
static create (storage: ServerStorage, next?: Middleware): PrivateMiddleware {
|
||||||
@ -48,14 +50,7 @@ export class PrivateMiddleware implements Middleware {
|
|||||||
return [res[0], res[1], res[2] ?? target]
|
return [res[0], res[1], res[2] ?? target]
|
||||||
}
|
}
|
||||||
|
|
||||||
private async provideTx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
|
override async findAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
||||||
if (this.next !== undefined) {
|
|
||||||
return await this.next.tx(ctx, tx)
|
|
||||||
}
|
|
||||||
return [ctx, tx, undefined]
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
|
||||||
let newQuery = query
|
let newQuery = query
|
||||||
const domain = this.storage.hierarchy.getDomain(_class)
|
const domain = this.storage.hierarchy.getDomain(_class)
|
||||||
if (this.targetDomains.includes(domain)) {
|
if (this.targetDomains.includes(domain)) {
|
||||||
@ -68,13 +63,6 @@ export class PrivateMiddleware implements Middleware {
|
|||||||
return await this.provideFindAll(ctx, _class, newQuery, options)
|
return await this.provideFindAll(ctx, _class, newQuery, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async provideFindAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
|
||||||
if (this.next !== undefined) {
|
|
||||||
return await this.next.findAll(ctx, _class, query, options)
|
|
||||||
}
|
|
||||||
return [ctx, _class, query, options]
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getUser (ctx: SessionContext): Promise<Ref<Account>> {
|
private async getUser (ctx: SessionContext): Promise<Ref<Account>> {
|
||||||
if (ctx.userEmail === undefined) {
|
if (ctx.userEmail === undefined) {
|
||||||
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
||||||
|
@ -27,7 +27,7 @@ import {
|
|||||||
TxResult
|
TxResult
|
||||||
} from '@anticrm/core'
|
} from '@anticrm/core'
|
||||||
import { createElasticAdapter } from '@anticrm/elastic'
|
import { createElasticAdapter } from '@anticrm/elastic'
|
||||||
import { PrivateMiddleware } from '@anticrm/middleware'
|
import { PrivateMiddleware, ModifiedMiddleware } from '@anticrm/middleware'
|
||||||
import { createMongoAdapter, createMongoTxAdapter } from '@anticrm/mongo'
|
import { createMongoAdapter, createMongoTxAdapter } from '@anticrm/mongo'
|
||||||
import { addLocation } from '@anticrm/platform'
|
import { addLocation } from '@anticrm/platform'
|
||||||
import { serverAttachmentId } from '@anticrm/server-attachment'
|
import { serverAttachmentId } from '@anticrm/server-attachment'
|
||||||
@ -103,6 +103,7 @@ export function start (
|
|||||||
addLocation(serverTelegramId, () => import('@anticrm/server-telegram-resources'))
|
addLocation(serverTelegramId, () => import('@anticrm/server-telegram-resources'))
|
||||||
|
|
||||||
const middlewares: MiddlewareCreator[] = [
|
const middlewares: MiddlewareCreator[] = [
|
||||||
|
ModifiedMiddleware.create,
|
||||||
PrivateMiddleware.create
|
PrivateMiddleware.create
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user