Skip to content

EspoCRM – Open Source CRM Application

Move allowInternalNotes to streamDefs

Yurii22093328c6e7
diff --git a/application/Espo/Classes/RecordHooks/Note/BeforeCreate.php b/application/Espo/Classes/RecordHooks/Note/BeforeCreate.php
index 195a6738a9..e54ab8c5d1 100644
--- a/application/Espo/Classes/RecordHooks/Note/BeforeCreate.php
+++ b/application/Espo/Classes/RecordHooks/Note/BeforeCreate.php
@@ -33,6 +33,7 @@ use Espo\Core\Acl;
use Espo\Core\Acl\Table as AclTable;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Record\Hook\SaveHook;
+use Espo\Core\Utils\Metadata;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
@@ -49,7 +50,8 @@ class BeforeCreate implements SaveHook
private EntityManager $entityManager,
private Acl $acl,
private User $user,
- private NoteUtil $noteUtil
+ private NoteUtil $noteUtil,
+ private Metadata $metadata,
) {}
public function process(Entity $entity): void
@@ -64,6 +66,14 @@ class BeforeCreate implements SaveHook
$entity->setIsInternal(false);
}
+ if (
+ !$entity->isPost() ||
+ !$entity->getParentType() ||
+ !$this->metadata->get("streamDefs.{$entity->getParentType()}.allowInternalNotes")
+ ) {
+ $entity->setIsInternal(false);
+ }
+
if ($entity->isPost()) {
$this->noteUtil->handlePostText($entity);
}
diff --git a/application/Espo/Core/Upgrades/Migrations/V10_0/AfterUpgrade.php b/application/Espo/Core/Upgrades/Migrations/V10_0/AfterUpgrade.php
index 3ebfa80ade..6f9021915d 100644
--- a/application/Espo/Core/Upgrades/Migrations/V10_0/AfterUpgrade.php
+++ b/application/Espo/Core/Upgrades/Migrations/V10_0/AfterUpgrade.php
@@ -31,8 +31,10 @@ namespace Espo\Core\Upgrades\Migrations\V10_0;
use Espo\Core\Upgrades\Migration\Script;
use Espo\Core\Utils\Config\ConfigWriter;
+use Espo\Core\Utils\Metadata;
use Espo\Entities\Preferences;
use Espo\Entities\User;
+use Espo\Modules\Crm\Entities\CaseObj;
use Espo\ORM\EntityManager;
class AfterUpgrade implements Script
@@ -40,12 +42,30 @@ class AfterUpgrade implements Script
public function __construct(
private EntityManager $entityManager,
private ConfigWriter $configWriter,
+ private Metadata $metadata,
) {}
public function run(): void
{
$this->updatePreferences();
$this->updateConfig();
+
+ /** @var array<string, array<string, mixed>> $clientDefs */
+ $clientDefs = $this->metadata->get('clientDefs') ?? [];
+
+ foreach ($clientDefs as $name => $defs) {
+ if ($name === CaseObj::ENTITY_TYPE) {
+ continue;
+ }
+
+ if ($defs['allowInternalNotes'] ?? false) {
+ $this->metadata->set('streamDefs', $name, [
+ 'allowInternalNotes' => true,
+ ]);
+ }
+ }
+
+ $this->metadata->save();
}
private function updatePreferences(): void
diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json
index a19e301c9a..a39ab5d335 100644
--- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json
+++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json
@@ -103,7 +103,6 @@
"selectDefaultFilters": {
"filter": "open"
},
- "allowInternalNotes": true,
"additionalLayouts": {
"detailPortal": {
"type": "detail"
diff --git a/application/Espo/Modules/Crm/Resources/metadata/streamDefs/Case.json b/application/Espo/Modules/Crm/Resources/metadata/streamDefs/Case.json
new file mode 100644
index 0000000000..1ca1f0495a
--- /dev/null
+++ b/application/Espo/Modules/Crm/Resources/metadata/streamDefs/Case.json
@@ -0,0 +1,3 @@
+{
+ "allowInternalNotes": true
+}
diff --git a/client/src/views/stream/panel.js b/client/src/views/stream/panel.js
index 5e9280f7d5..d9a8183a8f 100644
--- a/client/src/views/stream/panel.js
+++ b/client/src/views/stream/panel.js
@@ -208,7 +208,7 @@ class PanelStreamView extends RelationshipPanelView {
this.allowInternalNotes = false;
if (!this.getUser().isPortal()) {
- this.allowInternalNotes = this.getMetadata().get(['clientDefs', this.entityType, 'allowInternalNotes']);
+ this.allowInternalNotes = this.getMetadata().get(['streamDefs', this.entityType, 'allowInternalNotes']);
}
this.hasPinned = this.model.entityType !== 'User';
diff --git a/schema/metadata/clientDefs.json b/schema/metadata/clientDefs.json
index 6a87695acd..fa6f38a3b6 100644
--- a/schema/metadata/clientDefs.json
+++ b/schema/metadata/clientDefs.json
@@ -754,10 +754,6 @@
"description": "Whether the scope has the kanban view mode on the list view.",
"type": "boolean"
},
- "allowInternalNotes": {
- "description": "If true, it will be possible to post internal posts in the stream. Internal posts are not visible in portals.",
- "type": "boolean"
- },
"isExpandedByDefault": {
"description": "Actual for category scopes (e.g. DocumentFolder). If true, then by default it will be in expanded mode.",
"type": "boolean"
diff --git a/schema/metadata/streamDefs.json b/schema/metadata/streamDefs.json
index ccc47932e1..8123a3a962 100644
--- a/schema/metadata/streamDefs.json
+++ b/schema/metadata/streamDefs.json
@@ -33,6 +33,10 @@
"bypassAssignedUserFollow": {
"type": "boolean",
"description": "Assigned users won't follow the record when they get assigned to it. If enabling, consider also enabling `forceAssignmentNotificator` in notificationDefs – otherwise, the assignee won't receive any notification. As of v10.0."
+ },
+ "allowInternalNotes": {
+ "type": "boolean",
+ "description": "Allow internal notes. As of v10.0."
}
}
}