EZQMS-729: Restrict spaces operations (#5500)

This commit is contained in:
Alexey Zinoviev
2024-05-04 20:49:24 +07:00
committed by GitHub
parent ad59463057
commit 4bc1534ee0
57 changed files with 873 additions and 114 deletions
+37 -2
View File
@@ -13,8 +13,9 @@
// limitations under the License.
//
import { concatLink, Doc } from '@hcengineering/core'
import { Lead, leadId } from '@hcengineering/lead'
import { PersonAccount } from '@hcengineering/contact'
import core, { concatLink, Doc, Tx, TxUpdateDoc } from '@hcengineering/core'
import lead, { Lead, leadId } from '@hcengineering/lead'
import { getMetadata } from '@hcengineering/platform'
import serverCore, { TriggerControl } from '@hcengineering/server-core'
import view from '@hcengineering/view'
@@ -39,10 +40,44 @@ export async function leadTextPresenter (doc: Doc): Promise<string> {
return `LEAD-${lead.number}`
}
/**
* @public
*/
export async function OnWorkspaceOwnerAdded (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const targetFunnel = (
await control.findAll(lead.class.Funnel, {
_id: lead.space.DefaultFunnel
})
)[0]
if (targetFunnel === undefined) {
return []
}
const res: Tx[] = []
const actualTx = tx as TxUpdateDoc<PersonAccount>
if (
targetFunnel.owners === undefined ||
targetFunnel.owners.length === 0 ||
targetFunnel.owners[0] === core.account.System
) {
const updTx = control.txFactory.createTxUpdateDoc(lead.class.Funnel, targetFunnel.space, targetFunnel._id, {
owners: [actualTx.objectId]
})
res.push(updTx)
}
return res
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
function: {
LeadHTMLPresenter: leadHTMLPresenter,
LeadTextPresenter: leadTextPresenter
},
trigger: {
OnWorkspaceOwnerAdded
}
})
+4
View File
@@ -15,6 +15,7 @@
import type { Plugin, Resource } from '@hcengineering/platform'
import { plugin } from '@hcengineering/platform'
import { TriggerFunc } from '@hcengineering/server-core'
import { Presenter } from '@hcengineering/server-notification'
/**
@@ -29,5 +30,8 @@ export default plugin(serverLeadId, {
function: {
LeadHTMLPresenter: '' as Resource<Presenter>,
LeadTextPresenter: '' as Resource<Presenter>
},
trigger: {
OnWorkspaceOwnerAdded: '' as Resource<TriggerFunc>
}
})
+45 -13
View File
@@ -179,6 +179,37 @@ export async function OnComponentRemove (tx: Tx, control: TriggerControl): Promi
return res
}
/**
* @public
*/
export async function OnWorkspaceOwnerAdded (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const targetProject = (
await control.findAll(tracker.class.Project, {
_id: tracker.project.DefaultProject
})
)[0]
if (targetProject === undefined) {
return []
}
const res: Tx[] = []
const actualTx = tx as TxUpdateDoc<PersonAccount>
if (
targetProject.owners === undefined ||
targetProject.owners.length === 0 ||
targetProject.owners[0] === core.account.System
) {
const updTx = control.txFactory.createTxUpdateDoc(tracker.class.Project, targetProject.space, targetProject._id, {
owners: [actualTx.objectId]
})
res.push(updTx)
}
return res
}
/**
* @public
*/
@@ -245,19 +276,6 @@ export async function OnIssueUpdate (tx: Tx, control: TriggerControl): Promise<T
return []
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
function: {
IssueHTMLPresenter: issueHTMLPresenter,
IssueTextPresenter: issueTextPresenter,
IssueNotificationContentProvider: getIssueNotificationContent
},
trigger: {
OnIssueUpdate,
OnComponentRemove
}
})
async function doTimeReportUpdate (cud: TxCUD<TimeSpendReport>, tx: Tx, control: TriggerControl): Promise<Tx[]> {
const parentTx = tx as TxCollectionCUD<Issue, TimeSpendReport>
switch (cud._class) {
@@ -465,3 +483,17 @@ function updateIssueParentEstimations (
)
}
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
function: {
IssueHTMLPresenter: issueHTMLPresenter,
IssueTextPresenter: issueTextPresenter,
IssueNotificationContentProvider: getIssueNotificationContent
},
trigger: {
OnIssueUpdate,
OnComponentRemove,
OnWorkspaceOwnerAdded
}
})
+2 -1
View File
@@ -34,6 +34,7 @@ export default plugin(serverTrackerId, {
},
trigger: {
OnIssueUpdate: '' as Resource<TriggerFunc>,
OnComponentRemove: '' as Resource<TriggerFunc>
OnComponentRemove: '' as Resource<TriggerFunc>,
OnWorkspaceOwnerAdded: '' as Resource<TriggerFunc>
}
})