mass action notify
This commit is contained in:
@@ -38,6 +38,7 @@ use Espo\Core\MassAction\Params;
|
||||
use Espo\Core\MassAction\ServiceParams;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
|
||||
use stdClass;
|
||||
use RuntimeException;
|
||||
@@ -101,6 +102,19 @@ class MassAction
|
||||
return $this->service->getStatusData($id);
|
||||
}
|
||||
|
||||
public function postActionSubscribeToNotificationOnSuccess(Request $request, Response $response): void
|
||||
{
|
||||
$id = $request->getParsedBody()->id ?? null;
|
||||
|
||||
if (!$id || !is_string($id)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$this->service->subscribeToNotificationOnSuccess($id);
|
||||
|
||||
$response->writeBody('true');
|
||||
}
|
||||
|
||||
private function prepareMassActionParams(stdClass $data): array
|
||||
{
|
||||
$where = $data->where ?? null;
|
||||
|
||||
@@ -119,6 +119,7 @@ class Process implements Job
|
||||
$message = $this->language->translate('massActionProcessed', 'messages');
|
||||
|
||||
$notification
|
||||
->setType(Notification::TYPE_MESSAGE)
|
||||
->setMessage($message)
|
||||
->setUserId($entity->getCreatedBy()->getId());
|
||||
|
||||
|
||||
@@ -135,6 +135,24 @@ class Service
|
||||
];
|
||||
}
|
||||
|
||||
public function subscribeToNotificationOnSuccess(string $id): void
|
||||
{
|
||||
/** @var MassActionEntity|null $entity */
|
||||
$entity = $this->entityManager->getEntity(MassActionEntity::ENTITY_TYPE, $id);
|
||||
|
||||
if (!$entity) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
if ($entity->getCreatedBy()->getId() !== $this->user->getId()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity->setNotifyOnFinish();
|
||||
|
||||
$this->entityManager->saveEntity($entity);
|
||||
}
|
||||
|
||||
private function schedule(string $entityType, string $action, Params $params, stdClass $data): ServiceResult
|
||||
{
|
||||
$entity = $this->entityManager->createEntity(MassActionEntity::ENTITY_TYPE, [
|
||||
|
||||
@@ -155,4 +155,11 @@ class MassAction extends Entity
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNotifyOnFinish(bool $notifyOnFinish = true): self
|
||||
{
|
||||
$this->set('notifyOnFinish', $notifyOnFinish);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,16 @@ define('views/modals/mass-action', ['views/modal', 'model'], function (Dep, Mode
|
||||
],
|
||||
});
|
||||
|
||||
this.on('close', () => {
|
||||
if (this.model.get('status') !== 'Pending') {
|
||||
return;
|
||||
}
|
||||
|
||||
Espo.Ajax.postRequest('MassAction/action/subscribeToNotificationOnSuccess', {
|
||||
id: this.id,
|
||||
});
|
||||
});
|
||||
|
||||
this.checkStatus();
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user