Add ForbidCreateFunnel permission

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
Anton Alexeyev 2025-04-28 16:31:17 +07:00
parent a4b3c1886e
commit ef0b99d916
17 changed files with 87 additions and 25 deletions

View File

@ -32,6 +32,7 @@ import { type ViewOptionsModel } from '@hcengineering/view'
import lead from './plugin' import lead from './plugin'
import { defineSpaceType } from './spaceType' import { defineSpaceType } from './spaceType'
import { definePermissions } from './permissions'
import { TCustomer, TFunnel, TLead } from './types' import { TCustomer, TFunnel, TLead } from './types'
export { leadId } from '@hcengineering/lead' export { leadId } from '@hcengineering/lead'
@ -659,4 +660,5 @@ export function createModel (builder: Builder): void {
}) })
defineSpaceType(builder) defineSpaceType(builder)
definePermissions(builder)
} }

View File

@ -0,0 +1,19 @@
import type { Builder } from '@hcengineering/model'
import core from '@hcengineering/core'
import lead from '@hcengineering/lead'
export function definePermissions (builder: Builder): void {
builder.createDoc(
core.class.Permission,
core.space.Model,
{
label: lead.string.ForbidCreateFunnelPermission,
scope: 'workspace',
txClass: core.class.TxCreateDoc,
objectClass: lead.class.Funnel,
forbid: true,
description: lead.string.ForbidCreateFunnelPermissionDescription
},
lead.permission.ForbidCreateFunnel
)
}

View File

@ -267,7 +267,7 @@ export default plugin(coreId, {
DeleteObject: '' as Ref<Permission>, DeleteObject: '' as Ref<Permission>,
ForbidDeleteObject: '' as Ref<Permission>, ForbidDeleteObject: '' as Ref<Permission>,
UpdateSpace: '' as Ref<Permission>, UpdateSpace: '' as Ref<Permission>,
ArchiveSpace: '' as Ref<Permission>, ArchiveSpace: '' as Ref<Permission>
}, },
role: { role: {
Admin: '' as Ref<Role> Admin: '' as Ref<Role>

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Rozšíření pro řízení vztahů se zákazníky", "ConfigDescription": "Rozšíření pro řízení vztahů se zákazníky",
"EditFunnel": "Upravit trychtýř", "EditFunnel": "Upravit trychtýř",
"FunnelMembers": "Členové", "FunnelMembers": "Členové",
"RoleLabel": "Role: {role}" "RoleLabel": "Role: {role}",
"ForbidCreateFunnelPermission": "Zakázat vytvoření trychtýře",
"ForbidCreateFunnelPermissionDescription": "Zakazuje uživatelům vytvářet nové trychtýře"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Erweiterung für Customer Relationship Management", "ConfigDescription": "Erweiterung für Customer Relationship Management",
"EditFunnel": "Trichter bearbeiten", "EditFunnel": "Trichter bearbeiten",
"FunnelMembers": "Mitglieder", "FunnelMembers": "Mitglieder",
"RoleLabel": "Rolle: {role}" "RoleLabel": "Rolle: {role}",
"ForbidCreateFunnelPermission": "Trichtererstellung verbieten",
"ForbidCreateFunnelPermissionDescription": "Verbietet Benutzern das Erstellen neuer Trichter"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Extension for Customer relation management", "ConfigDescription": "Extension for Customer relation management",
"EditFunnel": "Edit Funnel", "EditFunnel": "Edit Funnel",
"FunnelMembers": "Members", "FunnelMembers": "Members",
"RoleLabel": "Role: {role}" "RoleLabel": "Role: {role}",
"ForbidCreateFunnelPermission": "Forbid create funnel",
"ForbidCreateFunnelPermissionDescription": "Forbid users creating new funnels"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Extensión para la gestión de las relaciones con los Clientes", "ConfigDescription": "Extensión para la gestión de las relaciones con los Clientes",
"EditFunnel": "Editar Embudo", "EditFunnel": "Editar Embudo",
"FunnelMembers": "Miembros", "FunnelMembers": "Miembros",
"RoleLabel": "Role: {role}" "RoleLabel": "Role: {role}",
"ForbidCreateFunnelPermission": "Prohibir crear embudo",
"ForbidCreateFunnelPermissionDescription": "Prohíbe a los usuarios crear nuevos embudos"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Extension pour la gestion de la relation client", "ConfigDescription": "Extension pour la gestion de la relation client",
"EditFunnel": "Modifier le pipeline", "EditFunnel": "Modifier le pipeline",
"FunnelMembers": "Membres", "FunnelMembers": "Membres",
"RoleLabel": "Rôle : {role}" "RoleLabel": "Rôle : {role}",
"ForbidCreateFunnelPermission": "Interdire la création de pipeline",
"ForbidCreateFunnelPermissionDescription": "Interdit aux utilisateurs de créer de nouveaux pipelines"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Estensione per la gestione delle relazioni con i clienti", "ConfigDescription": "Estensione per la gestione delle relazioni con i clienti",
"EditFunnel": "Modifica Funnel", "EditFunnel": "Modifica Funnel",
"FunnelMembers": "Membri", "FunnelMembers": "Membri",
"RoleLabel": "Ruolo: {role}" "RoleLabel": "Ruolo: {role}",
"ForbidCreateFunnelPermission": "Vieta creazione funnel",
"ForbidCreateFunnelPermissionDescription": "Vieta agli utenti di creare nuovi funnel"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "顧客関係管理のための拡張機能", "ConfigDescription": "顧客関係管理のための拡張機能",
"EditFunnel": "ファネルを編集", "EditFunnel": "ファネルを編集",
"FunnelMembers": "メンバー", "FunnelMembers": "メンバー",
"RoleLabel": "ロール: {role}" "RoleLabel": "ロール: {role}",
"ForbidCreateFunnelPermission": "ファネルの作成禁止",
"ForbidCreateFunnelPermissionDescription": "ユーザーが新しいファネルを作成することを禁止します"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Extensão para gestão de relacionamento com o Cliente", "ConfigDescription": "Extensão para gestão de relacionamento com o Cliente",
"EditFunnel": "Editar Funil", "EditFunnel": "Editar Funil",
"FunnelMembers": "Membros", "FunnelMembers": "Membros",
"RoleLabel": "Cargo: {role}" "RoleLabel": "Cargo: {role}",
"ForbidCreateFunnelPermission": "Proibir criação de funil",
"ForbidCreateFunnelPermissionDescription": "Proíbe os utilizadores de criar novos funis"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "Расширение по работе с клиентами", "ConfigDescription": "Расширение по работе с клиентами",
"EditFunnel": "Редактировать воронку", "EditFunnel": "Редактировать воронку",
"FunnelMembers": "Участники", "FunnelMembers": "Участники",
"RoleLabel": "Роль: {role}" "RoleLabel": "Роль: {role}",
"ForbidCreateFunnelPermission": "Запретить создание воронки",
"ForbidCreateFunnelPermissionDescription": "Запрещает пользователям создавать новые воронки"
} }
} }

View File

@ -34,6 +34,8 @@
"ConfigDescription": "用于客户关系管理的扩展", "ConfigDescription": "用于客户关系管理的扩展",
"EditFunnel": "编辑漏斗", "EditFunnel": "编辑漏斗",
"FunnelMembers": "成员", "FunnelMembers": "成员",
"RoleLabel": "角色:{role}" "RoleLabel": "角色:{role}",
"ForbidCreateFunnelPermission": "禁止创建漏斗",
"ForbidCreateFunnelPermissionDescription": "禁止用户创建新漏斗"
} }
} }

View File

@ -15,7 +15,17 @@
// //
import type { Contact } from '@hcengineering/contact' import type { Contact } from '@hcengineering/contact'
import type { Attribute, Class, MarkupBlobRef, Doc, Markup, Ref, Status, Timestamp } from '@hcengineering/core' import type {
Attribute,
Class,
MarkupBlobRef,
Doc,
Markup,
Ref,
Status,
Timestamp,
Permission
} from '@hcengineering/core'
import { Mixin } from '@hcengineering/core' import { Mixin } from '@hcengineering/core'
import type { Asset, IntlString, Plugin } from '@hcengineering/platform' import type { Asset, IntlString, Plugin } from '@hcengineering/platform'
import { plugin } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform'
@ -73,7 +83,9 @@ const lead = plugin(leadId, {
}, },
string: { string: {
Lead: '' as IntlString, Lead: '' as IntlString,
ConfigLabel: '' as IntlString ConfigLabel: '' as IntlString,
ForbidCreateFunnelPermission: '' as IntlString,
ForbidCreateFunnelPermissionDescription: '' as IntlString
}, },
attribute: { attribute: {
State: '' as Ref<Attribute<Status>> State: '' as Ref<Attribute<Status>>
@ -96,6 +108,9 @@ const lead = plugin(leadId, {
}, },
space: { space: {
DefaultFunnel: '' as Ref<Funnel> DefaultFunnel: '' as Ref<Funnel>
},
permission: {
ForbidCreateFunnel: '' as Ref<Permission>
} }
}) })

View File

@ -46,7 +46,7 @@
if (spaceType._class === core.class.SpaceType) { if (spaceType._class === core.class.SpaceType) {
const additionalPermissionsQuery = createQuery() const additionalPermissionsQuery = createQuery()
additionalPermissionsQuery.query(core.class.Permission, { scope: 'workspace' }, (res) => { additionalPermissionsQuery.query(core.class.Permission, { scope: 'workspace' }, (res) => {
spacePermissions = descriptor.availablePermissions.concat(res.map(r => r._id)) spacePermissions = descriptor.availablePermissions.concat(res.map((r) => r._id))
}) })
} }

View File

@ -29,7 +29,8 @@ import {
Space, Space,
Status, Status,
Timestamp, Timestamp,
Type, type Permission Type,
type Permission
} from '@hcengineering/core' } from '@hcengineering/core'
import { Asset, IntlString, Plugin, Resource, plugin } from '@hcengineering/platform' import { Asset, IntlString, Plugin, Resource, plugin } from '@hcengineering/platform'
import { Preference } from '@hcengineering/preference' import { Preference } from '@hcengineering/preference'

View File

@ -81,14 +81,19 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle
} }
private getPermissions (): Permission[] { private getPermissions (): Permission[] {
return this.context.modelDb.findAllSync(core.class.Permission, { }) return this.context.modelDb.findAllSync(core.class.Permission, {})
} }
private getRoles (spaceTypeId: Ref<SpaceType>): Role[] { private getRoles (spaceTypeId: Ref<SpaceType>): Role[] {
return this.context.modelDb.findAllSync(core.class.Role, { attachedTo: spaceTypeId }) return this.context.modelDb.findAllSync(core.class.Role, { attachedTo: spaceTypeId })
} }
private setPermissions (spaceId: Ref<Space>, roles: Role[], assignment: RolesAssignment, permissions: Permission[]): void { private setPermissions (
spaceId: Ref<Space>,
roles: Role[],
assignment: RolesAssignment,
permissions: Permission[]
): void {
for (const role of roles) { for (const role of roles) {
const roleMembers: Ref<Account>[] = assignment[role._id] ?? [] const roleMembers: Ref<Account>[] = assignment[role._id] ?? []
@ -98,7 +103,7 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle
} }
for (const permission of role.permissions) { for (const permission of role.permissions) {
const p = permissions.find(p => p._id === permission) const p = permissions.find((p) => p._id === permission)
if (p === undefined) continue if (p === undefined) continue
this.permissionsBySpace[spaceId][member].add(p) this.permissionsBySpace[spaceId][member].add(p)
} }