note acl refactoring and period change

This commit is contained in:
Yuri Kuznetsov
2021-10-08 15:35:05 +03:00
parent 9c56a14fb0
commit c99566410a
2 changed files with 43 additions and 16 deletions
+7
View File
@@ -31,6 +31,8 @@ namespace Espo\Entities;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\DateTime;
use stdClass;
class Note extends Entity
@@ -117,6 +119,11 @@ class Note extends Entity
return $this->get('post');
}
public function getCreatedAt(): ?DateTime
{
return $this->getValueObject('createdAt');
}
public function setAclIsProcessed(): void
{
$this->aclIsProcessed = true;
+36 -16
View File
@@ -108,7 +108,18 @@ class Stream
private $recordServiceContainer;
private const NOTE_ACL_PERIOD = '1 hour';
/**
* When a record is re-assigned, ACL will be recalculated for related notes
* created within the period.
*/
private const NOTE_ACL_PERIOD = '3 days';
private const NOTE_ACL_LIMIT = 50;
/**
* Not used currently.
*/
private const NOTE_NOTIFICATION_PERIOD = '1 hour';
public function __construct(
EntityManager $entityManager,
@@ -2110,6 +2121,8 @@ class Stream
return;
}
$limit = $this->config->get('noteAclLimit', self::NOTE_ACL_LIMIT);
$noteList = $this->entityManager
->getRDBRepository('Note')
->where([
@@ -2137,6 +2150,8 @@ class Stream
'relatedId',
'createdAt',
])
->order('number', 'DESC')
->limit(0, $limit)
->find();
$noteOptions = [];
@@ -2145,9 +2160,11 @@ class Stream
$noteOptions['forceProcessNotifications'] = true;
}
$period = '-' . $this->config->get('noteNotificationPeriod', self::NOTE_ACL_PERIOD);
$notificationPeriod = '-' . $this->config->get('noteNotificationPeriod', self::NOTE_NOTIFICATION_PERIOD);
$aclPeriod = '-' . $this->config->get('noteAclPeriod', self::NOTE_ACL_PERIOD);
$threshold = (new DateTime())->modify($period);
$notificationThreshold = (new DateTime())->modify($notificationPeriod);
$aclThreshold = (new DateTime())->modify($aclPeriod);
foreach ($noteList as $note) {
$this->processNoteAclItem($entity, $note, [
@@ -2156,7 +2173,8 @@ class Stream
'forceProcessNoteNotifications' => $forceProcessNoteNotifications,
'teamIdList' => $teamIdList,
'userIdList' => $userIdList,
'threshold' => $threshold,
'notificationThreshold' => $notificationThreshold,
'aclThreshold' => $aclThreshold,
]);
}
}
@@ -2170,21 +2188,21 @@ class Stream
$teamIdList = $params['teamIdList'];
$userIdList = $params['userIdList'];
$threshold = $params['threshold'];
$notificationThreshold = $params['notificationThreshold'];
$aclThreshold = $params['aclThreshold'];
$noteOptions = [
'forceProcessNotifications' => $forceProcessNoteNotifications,
];
$createdAt = $note->getCreatedAt();
if (!$entity->isNew() && $note->get('createdAt')) {
try {
$createdAtDt = new DateTime($note->get('createdAt'));
}
catch (Exception $e) {
return;
if (!$createdAt) {
return;
}
if (!$entity->isNew()) {
if ($createdAt->getTimestamp() < $notificationThreshold->getTimestamp()) {
$forceProcessNoteNotifications = false;
}
if ($createdAtDt->getTimestamp() < $threshold->getTimestamp()) {
if ($createdAt->getTimestamp() < $aclThreshold->getTimestamp()) {
return;
}
}
@@ -2197,7 +2215,9 @@ class Stream
$note->set('usersIds', $userIdList);
}
$this->entityManager->saveEntity($note, $noteOptions);
$this->entityManager->saveEntity($note, [
'forceProcessNotifications' => $forceProcessNoteNotifications,
]);
}
public function applyAccessControlToNote(NoteEntity $note, ?User $user = null): void