mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-25 04:25:13 +03: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 CardLabelPresenter from './components/presenters/LabelPresenter.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> {
|
||||
showPopup(MoveView, { object })
|
||||
@ -61,7 +61,10 @@ export default async (): Promise<Resources> => ({
|
||||
Join: addCurrentUser,
|
||||
Move: showMoveCardPopup,
|
||||
Dates: showDatePickerPopup,
|
||||
Labels: showCardLabelsPopup
|
||||
Labels: showCardLabelsPopup,
|
||||
Archive: archiveCard,
|
||||
SendToBoard: unarchiveCard,
|
||||
Delete: deleteCard
|
||||
},
|
||||
cardActionSupportedHandler: {
|
||||
Join: canAddCurrentUser,
|
||||
|
@ -9,6 +9,10 @@ export function updateCard (client: Client, card: Card, field: string, value: an
|
||||
client.update(card, { [field]: value })
|
||||
}
|
||||
|
||||
export function deleteCard (card: Card, client: Client): void {
|
||||
client.remove(card)
|
||||
}
|
||||
|
||||
export function isArchived (card: Card): boolean {
|
||||
return !!card.isArchived
|
||||
}
|
||||
@ -45,3 +49,11 @@ export function addCurrentUser (card: Card, client: Client): void {
|
||||
members.push(employee)
|
||||
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.
|
||||
//
|
||||
|
||||
export * from './base'
|
||||
export * from './modified'
|
||||
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 { Middleware, SessionContext, TxMiddlewareResult, FindAllMiddlewareResult } from '@anticrm/server-core'
|
||||
import { DOMAIN_PREFERENCE } from '@anticrm/server-preference'
|
||||
import { BaseMiddleware } from './base'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export class PrivateMiddleware implements Middleware {
|
||||
export class PrivateMiddleware extends BaseMiddleware implements Middleware {
|
||||
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 {
|
||||
@ -48,14 +50,7 @@ export class PrivateMiddleware implements Middleware {
|
||||
return [res[0], res[1], res[2] ?? target]
|
||||
}
|
||||
|
||||
private async provideTx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
|
||||
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>> {
|
||||
override async findAll <T extends Doc>(ctx: SessionContext, _class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindAllMiddlewareResult<T>> {
|
||||
let newQuery = query
|
||||
const domain = this.storage.hierarchy.getDomain(_class)
|
||||
if (this.targetDomains.includes(domain)) {
|
||||
@ -68,13 +63,6 @@ export class PrivateMiddleware implements Middleware {
|
||||
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>> {
|
||||
if (ctx.userEmail === undefined) {
|
||||
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
|
||||
|
@ -27,7 +27,7 @@ import {
|
||||
TxResult
|
||||
} from '@anticrm/core'
|
||||
import { createElasticAdapter } from '@anticrm/elastic'
|
||||
import { PrivateMiddleware } from '@anticrm/middleware'
|
||||
import { PrivateMiddleware, ModifiedMiddleware } from '@anticrm/middleware'
|
||||
import { createMongoAdapter, createMongoTxAdapter } from '@anticrm/mongo'
|
||||
import { addLocation } from '@anticrm/platform'
|
||||
import { serverAttachmentId } from '@anticrm/server-attachment'
|
||||
@ -103,6 +103,7 @@ export function start (
|
||||
addLocation(serverTelegramId, () => import('@anticrm/server-telegram-resources'))
|
||||
|
||||
const middlewares: MiddlewareCreator[] = [
|
||||
ModifiedMiddleware.create,
|
||||
PrivateMiddleware.create
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user