From ef0b99d916041f03e0280a53751e44d4d014f65e Mon Sep 17 00:00:00 2001 From: Anton Alexeyev Date: Mon, 28 Apr 2025 16:31:17 +0700 Subject: [PATCH] Add ForbidCreateFunnel permission Signed-off-by: Anton Alexeyev --- models/lead/src/index.ts | 2 ++ models/lead/src/permissions.ts | 19 +++++++++++++++++++ packages/core/src/component.ts | 2 +- plugins/lead-assets/lang/cs.json | 6 ++++-- plugins/lead-assets/lang/de.json | 6 ++++-- plugins/lead-assets/lang/en.json | 6 ++++-- plugins/lead-assets/lang/es.json | 6 ++++-- plugins/lead-assets/lang/fr.json | 6 ++++-- plugins/lead-assets/lang/it.json | 4 +++- plugins/lead-assets/lang/ja.json | 4 +++- plugins/lead-assets/lang/pt.json | 6 ++++-- plugins/lead-assets/lang/ru.json | 6 ++++-- plugins/lead-assets/lang/zh.json | 4 +++- plugins/lead/src/index.ts | 19 +++++++++++++++++-- .../components/spaceTypes/RoleEditor.svelte | 2 +- plugins/tracker/src/index.ts | 3 ++- server/middleware/src/spacePermissions.ts | 11 ++++++++--- 17 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 models/lead/src/permissions.ts diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index 56964a75bf..b463c3f52c 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -32,6 +32,7 @@ import { type ViewOptionsModel } from '@hcengineering/view' import lead from './plugin' import { defineSpaceType } from './spaceType' +import { definePermissions } from './permissions' import { TCustomer, TFunnel, TLead } from './types' export { leadId } from '@hcengineering/lead' @@ -659,4 +660,5 @@ export function createModel (builder: Builder): void { }) defineSpaceType(builder) + definePermissions(builder) } diff --git a/models/lead/src/permissions.ts b/models/lead/src/permissions.ts new file mode 100644 index 0000000000..afb8d5287d --- /dev/null +++ b/models/lead/src/permissions.ts @@ -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 + ) +} diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index e3963f0cbf..cbadbd1f18 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -267,7 +267,7 @@ export default plugin(coreId, { DeleteObject: '' as Ref, ForbidDeleteObject: '' as Ref, UpdateSpace: '' as Ref, - ArchiveSpace: '' as Ref, + ArchiveSpace: '' as Ref }, role: { Admin: '' as Ref diff --git a/plugins/lead-assets/lang/cs.json b/plugins/lead-assets/lang/cs.json index caa91c9c46..93a4e895dc 100644 --- a/plugins/lead-assets/lang/cs.json +++ b/plugins/lead-assets/lang/cs.json @@ -34,6 +34,8 @@ "ConfigDescription": "Rozšíření pro řízení vztahů se zákazníky", "EditFunnel": "Upravit trychtýř", "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" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/de.json b/plugins/lead-assets/lang/de.json index e980844817..d8d6fb98af 100644 --- a/plugins/lead-assets/lang/de.json +++ b/plugins/lead-assets/lang/de.json @@ -34,6 +34,8 @@ "ConfigDescription": "Erweiterung für Customer Relationship Management", "EditFunnel": "Trichter bearbeiten", "FunnelMembers": "Mitglieder", - "RoleLabel": "Rolle: {role}" + "RoleLabel": "Rolle: {role}", + "ForbidCreateFunnelPermission": "Trichtererstellung verbieten", + "ForbidCreateFunnelPermissionDescription": "Verbietet Benutzern das Erstellen neuer Trichter" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/en.json b/plugins/lead-assets/lang/en.json index 7fa0cd0249..64b84b2b01 100644 --- a/plugins/lead-assets/lang/en.json +++ b/plugins/lead-assets/lang/en.json @@ -34,6 +34,8 @@ "ConfigDescription": "Extension for Customer relation management", "EditFunnel": "Edit Funnel", "FunnelMembers": "Members", - "RoleLabel": "Role: {role}" + "RoleLabel": "Role: {role}", + "ForbidCreateFunnelPermission": "Forbid create funnel", + "ForbidCreateFunnelPermissionDescription": "Forbid users creating new funnels" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/es.json b/plugins/lead-assets/lang/es.json index f21a3e765f..5879b2e339 100644 --- a/plugins/lead-assets/lang/es.json +++ b/plugins/lead-assets/lang/es.json @@ -34,6 +34,8 @@ "ConfigDescription": "Extensión para la gestión de las relaciones con los Clientes", "EditFunnel": "Editar Embudo", "FunnelMembers": "Miembros", - "RoleLabel": "Role: {role}" + "RoleLabel": "Role: {role}", + "ForbidCreateFunnelPermission": "Prohibir crear embudo", + "ForbidCreateFunnelPermissionDescription": "Prohíbe a los usuarios crear nuevos embudos" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/fr.json b/plugins/lead-assets/lang/fr.json index f22b854a6c..b081b26282 100644 --- a/plugins/lead-assets/lang/fr.json +++ b/plugins/lead-assets/lang/fr.json @@ -34,6 +34,8 @@ "ConfigDescription": "Extension pour la gestion de la relation client", "EditFunnel": "Modifier le pipeline", "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" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/it.json b/plugins/lead-assets/lang/it.json index c38fff4af5..c6c3e3e3ab 100644 --- a/plugins/lead-assets/lang/it.json +++ b/plugins/lead-assets/lang/it.json @@ -34,6 +34,8 @@ "ConfigDescription": "Estensione per la gestione delle relazioni con i clienti", "EditFunnel": "Modifica Funnel", "FunnelMembers": "Membri", - "RoleLabel": "Ruolo: {role}" + "RoleLabel": "Ruolo: {role}", + "ForbidCreateFunnelPermission": "Vieta creazione funnel", + "ForbidCreateFunnelPermissionDescription": "Vieta agli utenti di creare nuovi funnel" } } diff --git a/plugins/lead-assets/lang/ja.json b/plugins/lead-assets/lang/ja.json index 4d1b6ed266..d325075fef 100644 --- a/plugins/lead-assets/lang/ja.json +++ b/plugins/lead-assets/lang/ja.json @@ -34,6 +34,8 @@ "ConfigDescription": "顧客関係管理のための拡張機能", "EditFunnel": "ファネルを編集", "FunnelMembers": "メンバー", - "RoleLabel": "ロール: {role}" + "RoleLabel": "ロール: {role}", + "ForbidCreateFunnelPermission": "ファネルの作成禁止", + "ForbidCreateFunnelPermissionDescription": "ユーザーが新しいファネルを作成することを禁止します" } } diff --git a/plugins/lead-assets/lang/pt.json b/plugins/lead-assets/lang/pt.json index 0b5e871c90..3b95402ecb 100644 --- a/plugins/lead-assets/lang/pt.json +++ b/plugins/lead-assets/lang/pt.json @@ -34,6 +34,8 @@ "ConfigDescription": "Extensão para gestão de relacionamento com o Cliente", "EditFunnel": "Editar Funil", "FunnelMembers": "Membros", - "RoleLabel": "Cargo: {role}" + "RoleLabel": "Cargo: {role}", + "ForbidCreateFunnelPermission": "Proibir criação de funil", + "ForbidCreateFunnelPermissionDescription": "Proíbe os utilizadores de criar novos funis" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/ru.json b/plugins/lead-assets/lang/ru.json index 0478aba685..670b876cfd 100644 --- a/plugins/lead-assets/lang/ru.json +++ b/plugins/lead-assets/lang/ru.json @@ -34,6 +34,8 @@ "ConfigDescription": "Расширение по работе с клиентами", "EditFunnel": "Редактировать воронку", "FunnelMembers": "Участники", - "RoleLabel": "Роль: {role}" + "RoleLabel": "Роль: {role}", + "ForbidCreateFunnelPermission": "Запретить создание воронки", + "ForbidCreateFunnelPermissionDescription": "Запрещает пользователям создавать новые воронки" } -} \ No newline at end of file +} diff --git a/plugins/lead-assets/lang/zh.json b/plugins/lead-assets/lang/zh.json index 8139b3d9a1..ea77699590 100644 --- a/plugins/lead-assets/lang/zh.json +++ b/plugins/lead-assets/lang/zh.json @@ -34,6 +34,8 @@ "ConfigDescription": "用于客户关系管理的扩展", "EditFunnel": "编辑漏斗", "FunnelMembers": "成员", - "RoleLabel": "角色:{role}" + "RoleLabel": "角色:{role}", + "ForbidCreateFunnelPermission": "禁止创建漏斗", + "ForbidCreateFunnelPermissionDescription": "禁止用户创建新漏斗" } } diff --git a/plugins/lead/src/index.ts b/plugins/lead/src/index.ts index f30be8eb82..bf4579ac9b 100644 --- a/plugins/lead/src/index.ts +++ b/plugins/lead/src/index.ts @@ -15,7 +15,17 @@ // 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 type { Asset, IntlString, Plugin } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' @@ -73,7 +83,9 @@ const lead = plugin(leadId, { }, string: { Lead: '' as IntlString, - ConfigLabel: '' as IntlString + ConfigLabel: '' as IntlString, + ForbidCreateFunnelPermission: '' as IntlString, + ForbidCreateFunnelPermissionDescription: '' as IntlString }, attribute: { State: '' as Ref> @@ -96,6 +108,9 @@ const lead = plugin(leadId, { }, space: { DefaultFunnel: '' as Ref + }, + permission: { + ForbidCreateFunnel: '' as Ref } }) diff --git a/plugins/setting-resources/src/components/spaceTypes/RoleEditor.svelte b/plugins/setting-resources/src/components/spaceTypes/RoleEditor.svelte index dee0b3fc58..88e77c2b3f 100644 --- a/plugins/setting-resources/src/components/spaceTypes/RoleEditor.svelte +++ b/plugins/setting-resources/src/components/spaceTypes/RoleEditor.svelte @@ -46,7 +46,7 @@ if (spaceType._class === core.class.SpaceType) { const additionalPermissionsQuery = createQuery() 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)) }) } diff --git a/plugins/tracker/src/index.ts b/plugins/tracker/src/index.ts index 8b1b7ee2e0..d0dbc7e037 100644 --- a/plugins/tracker/src/index.ts +++ b/plugins/tracker/src/index.ts @@ -29,7 +29,8 @@ import { Space, Status, Timestamp, - Type, type Permission + Type, + type Permission } from '@hcengineering/core' import { Asset, IntlString, Plugin, Resource, plugin } from '@hcengineering/platform' import { Preference } from '@hcengineering/preference' diff --git a/server/middleware/src/spacePermissions.ts b/server/middleware/src/spacePermissions.ts index 4489f0dfc7..b5cd68c247 100644 --- a/server/middleware/src/spacePermissions.ts +++ b/server/middleware/src/spacePermissions.ts @@ -81,14 +81,19 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle } private getPermissions (): Permission[] { - return this.context.modelDb.findAllSync(core.class.Permission, { }) + return this.context.modelDb.findAllSync(core.class.Permission, {}) } private getRoles (spaceTypeId: Ref): Role[] { return this.context.modelDb.findAllSync(core.class.Role, { attachedTo: spaceTypeId }) } - private setPermissions (spaceId: Ref, roles: Role[], assignment: RolesAssignment, permissions: Permission[]): void { + private setPermissions ( + spaceId: Ref, + roles: Role[], + assignment: RolesAssignment, + permissions: Permission[] + ): void { for (const role of roles) { const roleMembers: Ref[] = assignment[role._id] ?? [] @@ -98,7 +103,7 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle } 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 this.permissionsBySpace[spaceId][member].add(p) }