mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-27 05:23:11 +03:00
Use ActivityMessageControl to ignore comments and add activity.mixin.… (#4282)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
4c488693c4
commit
682e7745e7
@ -30,7 +30,8 @@ import {
|
||||
type DocUpdateMessageViewletAttributesConfig,
|
||||
type Reaction,
|
||||
type TxViewlet,
|
||||
type ActivityMessageControl
|
||||
type ActivityMessageControl,
|
||||
type IgnoreActivity
|
||||
} from '@hcengineering/activity'
|
||||
import core, {
|
||||
DOMAIN_MODEL,
|
||||
@ -71,7 +72,6 @@ export const DOMAIN_ACTIVITY = 'activity' as Domain
|
||||
@Mixin(activity.mixin.ActivityDoc, core.class.Class)
|
||||
export class TActivityDoc extends TClass implements ActivityDoc {
|
||||
preposition?: IntlString
|
||||
ignoreCollections?: string[]
|
||||
}
|
||||
|
||||
@Mixin(activity.mixin.ActivityAttributeUpdatesPresenter, core.class.Class)
|
||||
@ -79,6 +79,9 @@ export class TActivityAttributeUpdatesPresenter extends TClass implements Activi
|
||||
presenter!: AnyComponent
|
||||
}
|
||||
|
||||
@Mixin(activity.mixin.IgnoreActivity, core.class.Class)
|
||||
export class TIgnoreActivity extends TClass implements IgnoreActivity {}
|
||||
|
||||
@Model(activity.class.TxViewlet, core.class.Doc, DOMAIN_MODEL)
|
||||
export class TTxViewlet extends TDoc implements TxViewlet {
|
||||
icon!: Asset
|
||||
@ -194,6 +197,7 @@ export class TReaction extends TAttachedDoc implements Reaction {
|
||||
@Prop(TypeRef(core.class.Account), view.string.Created)
|
||||
createBy!: Ref<Account>
|
||||
}
|
||||
|
||||
export function createModel (builder: Builder): void {
|
||||
builder.createModel(
|
||||
TTxViewlet,
|
||||
@ -207,7 +211,8 @@ export function createModel (builder: Builder): void {
|
||||
TReaction,
|
||||
TActivityAttributeUpdatesPresenter,
|
||||
TActivityInfoMessage,
|
||||
TActivityMessageControl
|
||||
TActivityMessageControl,
|
||||
TIgnoreActivity
|
||||
)
|
||||
|
||||
builder.mixin(activity.class.DocUpdateMessage, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
@ -221,22 +221,26 @@ export function createModel (builder: Builder): void {
|
||||
TContactsTab
|
||||
)
|
||||
|
||||
builder.mixin(contact.class.Contact, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
})
|
||||
builder.mixin(contact.class.Contact, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.mixin(contact.class.Person, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
preposition: contact.string.For,
|
||||
ignoreCollections: ['comments']
|
||||
preposition: contact.string.For
|
||||
})
|
||||
|
||||
builder.mixin(contact.mixin.Employee, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
preposition: contact.string.For,
|
||||
ignoreCollections: ['comments']
|
||||
preposition: contact.string.For
|
||||
})
|
||||
|
||||
builder.mixin(contact.class.Organization, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
builder.mixin(contact.class.Organization, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: contact.class.Contact,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
builder.createDoc(activity.class.ActivityExtension, core.space.Model, {
|
||||
|
@ -105,12 +105,18 @@ export function createModel (builder: Builder): void {
|
||||
|
||||
builder.createModel(TFunnel, TLead, TCustomer)
|
||||
|
||||
builder.mixin(lead.class.Lead, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
})
|
||||
builder.mixin(lead.class.Lead, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.mixin(lead.mixin.Customer, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
builder.mixin(lead.mixin.Customer, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: lead.class.Lead,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
builder.mixin(lead.class.Funnel, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
@ -199,16 +199,29 @@ export class TApplicantMatch extends TAttachedDoc implements ApplicantMatch {
|
||||
export function createModel (builder: Builder): void {
|
||||
builder.createModel(TVacancy, TCandidates, TCandidate, TApplicant, TReview, TOpinion, TVacancyList, TApplicantMatch)
|
||||
|
||||
builder.mixin(recruit.class.Vacancy, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
})
|
||||
builder.mixin(recruit.class.Applicant, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
})
|
||||
builder.mixin(recruit.class.Vacancy, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(recruit.class.Applicant, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(recruit.class.Review, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(recruit.mixin.Candidate, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.mixin(recruit.mixin.Candidate, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: recruit.class.Vacancy,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: recruit.class.Applicant,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
builder.createDoc(activity.class.ActivityExtension, core.space.Model, {
|
||||
|
@ -375,17 +375,49 @@ export function createModel (builder: Builder): void {
|
||||
)
|
||||
|
||||
builder.mixin(tracker.class.Project, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(tracker.class.Issue, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
builder.mixin(tracker.class.Issue, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(tracker.class.Milestone, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(tracker.class.Component, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
builder.mixin(tracker.class.IssueTemplate, core.class.Class, activity.mixin.ActivityDoc, {})
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: tracker.class.Issue,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
builder.mixin(tracker.class.Milestone, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: tracker.class.Milestone,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
builder.mixin(tracker.class.Component, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: tracker.class.Component,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
builder.mixin(tracker.class.IssueTemplate, core.class.Class, activity.mixin.ActivityDoc, {
|
||||
ignoreCollections: ['comments']
|
||||
|
||||
builder.createDoc(activity.class.ActivityMessageControl, core.space.Model, {
|
||||
objectClass: tracker.class.IssueTemplate,
|
||||
skip: [
|
||||
{
|
||||
_class: core.class.TxCollectionCUD,
|
||||
collection: 'comments'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
builder.createDoc(activity.class.ActivityExtension, core.space.Model, {
|
||||
|
@ -236,7 +236,6 @@ export interface ActivityMessagesFilter extends Doc {
|
||||
*/
|
||||
export interface ActivityDoc extends Class<Doc> {
|
||||
preposition?: IntlString
|
||||
ignoreCollections?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,10 +266,16 @@ export interface Reaction extends AttachedDoc {
|
||||
createBy: Ref<Account>
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface IgnoreActivity extends Class<Doc> {}
|
||||
|
||||
export default plugin(activityId, {
|
||||
mixin: {
|
||||
ActivityDoc: '' as Ref<Mixin<ActivityDoc>>,
|
||||
ActivityAttributeUpdatesPresenter: '' as Ref<Mixin<ActivityAttributeUpdatesPresenter>>
|
||||
ActivityAttributeUpdatesPresenter: '' as Ref<Mixin<ActivityAttributeUpdatesPresenter>>,
|
||||
IgnoreActivity: '' as Ref<Mixin<IgnoreActivity>>
|
||||
},
|
||||
class: {
|
||||
TxViewlet: '' as Ref<Class<TxViewlet>>,
|
||||
|
@ -157,17 +157,6 @@ async function pushDocUpdateMessages (
|
||||
return res
|
||||
}
|
||||
|
||||
const collection =
|
||||
originTx._class === core.class.TxCollectionCUD
|
||||
? (originTx as TxCollectionCUD<Doc, AttachedDoc>).collection
|
||||
: undefined
|
||||
|
||||
const { ignoreCollections = [] } = activityDoc
|
||||
|
||||
if (collection !== undefined && ignoreCollections.includes(collection)) {
|
||||
return res
|
||||
}
|
||||
|
||||
const tx =
|
||||
originTx._class === core.class.TxCollectionCUD ? (originTx as TxCollectionCUD<Doc, AttachedDoc>).tx : originTx
|
||||
|
||||
@ -216,30 +205,37 @@ export async function generateDocUpdateMessages (
|
||||
originTx?: TxCUD<Doc>,
|
||||
objectCache?: DocObjectCache
|
||||
): Promise<TxCollectionCUD<Doc, DocUpdateMessage>[]> {
|
||||
const { hierarchy } = control
|
||||
|
||||
if (tx.space === core.space.DerivedTx) {
|
||||
return res
|
||||
}
|
||||
|
||||
if (control.hierarchy.isDerived(tx.objectClass, activity.class.ActivityMessage)) {
|
||||
const etx = TxProcessor.extractTx(tx) as TxCUD<Doc>
|
||||
|
||||
if (
|
||||
hierarchy.isDerived(tx.objectClass, activity.class.ActivityMessage) ||
|
||||
hierarchy.isDerived(etx.objectClass, activity.class.ActivityMessage)
|
||||
) {
|
||||
return res
|
||||
}
|
||||
const etx = TxProcessor.extractTx(tx)
|
||||
|
||||
if (
|
||||
control.hierarchy.isDerived(etx._class, core.class.TxCUD) &&
|
||||
control.hierarchy.isDerived((etx as TxCUD<Doc>).objectClass, activity.class.ActivityMessage)
|
||||
hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.IgnoreActivity) !== undefined ||
|
||||
hierarchy.classHierarchyMixin(etx.objectClass, activity.mixin.IgnoreActivity) !== undefined
|
||||
) {
|
||||
return res
|
||||
}
|
||||
|
||||
// Check if we have override control over transaction => activity mappings
|
||||
const controlRules = control.modelDb.findAllSync(activity.class.ActivityMessageControl, {
|
||||
objectClass: { $in: control.hierarchy.getDescendants(tx.objectClass) }
|
||||
objectClass: { $in: hierarchy.getAncestors(tx.objectClass) }
|
||||
})
|
||||
if (controlRules.length > 0) {
|
||||
for (const r of controlRules) {
|
||||
for (const s of r.skip) {
|
||||
const otx = originTx ?? TxProcessor.extractTx(tx)
|
||||
if (matchQuery(otx !== undefined ? [tx, otx] : [tx], s, r.objectClass, control.hierarchy).length > 0) {
|
||||
const otx = originTx ?? etx
|
||||
if (matchQuery(otx !== undefined ? [tx, otx] : [tx], s, r.objectClass, hierarchy).length > 0) {
|
||||
// Match found, we need to skip
|
||||
return res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user