mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-21 17:17:54 +02:00
EZQMS-729: Restrict spaces operations (#5500)
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user