new: [inboxes] Added `severity` level and `message` and removed `description` column
parent
0c4a73cc39
commit
00c1ae616f
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
|
||||
final class InboxSeverity extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$exists = $this->table('inbox')->hasColumn('severity');
|
||||
if (!$exists) {
|
||||
$this->table('inbox')
|
||||
->addColumn('severity', 'integer', [
|
||||
'null' => false,
|
||||
'default' => 0,
|
||||
'signed' => false,
|
||||
'length' => 10,
|
||||
])
|
||||
->renameColumn('comment', 'message')
|
||||
->removeColumn('description')
|
||||
->update();
|
||||
$this->table('outbox')
|
||||
->addColumn('severity', 'integer', [
|
||||
'null' => false,
|
||||
'default' => 0,
|
||||
'signed' => false,
|
||||
'length' => 10,
|
||||
])
|
||||
->renameColumn('comment', 'message')
|
||||
->removeColumn('description')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,9 +19,12 @@ class GenericInboxProcessor
|
|||
protected $validator;
|
||||
protected $processingTemplate = '/genericTemplates/confirm';
|
||||
protected $processingTemplatesDirectory = ROOT . '/libraries/default/InboxProcessors/templates';
|
||||
protected $defaultSeverity;
|
||||
protected $severity;
|
||||
|
||||
public function __construct($registerActions=false) {
|
||||
$this->Inbox = TableRegistry::getTableLocator()->get('Inbox');
|
||||
$this->defaultSeverity = $this->Inbox::SEVERITY_INFO;
|
||||
if ($registerActions) {
|
||||
$this->registerActionInProcessor();
|
||||
}
|
||||
|
@ -54,6 +57,10 @@ class GenericInboxProcessor
|
|||
{
|
||||
return $this->description ?? '';
|
||||
}
|
||||
public function getSeverity()
|
||||
{
|
||||
return $this->severity ?? $this->defaultSeverity;
|
||||
}
|
||||
|
||||
protected function getProcessingTemplatePath()
|
||||
{
|
||||
|
@ -192,7 +199,7 @@ class GenericInboxProcessor
|
|||
{
|
||||
$requestData['scope'] = $this->scope;
|
||||
$requestData['action'] = $this->action;
|
||||
$requestData['description'] = $this->description;
|
||||
$requestData['severity'] = $this->getSeverity();
|
||||
$request = $this->generateRequest($requestData);
|
||||
$savedRequest = $this->Inbox->createEntry($request);
|
||||
return $this->genActionResult(
|
||||
|
|
|
@ -193,7 +193,6 @@ class GenericOutboxProcessor
|
|||
$user_id = Router::getRequest()->getSession()->read('Auth.id');
|
||||
$requestData['scope'] = $this->scope;
|
||||
$requestData['action'] = $this->action;
|
||||
$requestData['description'] = $this->description;
|
||||
$requestData['user_id'] = $user_id;
|
||||
$request = $this->generateRequest($requestData);
|
||||
$savedRequest = $this->Outbox->createEntry($request);
|
||||
|
|
|
@ -16,8 +16,8 @@ use Cake\Http\Exception\ForbiddenException;
|
|||
|
||||
class InboxController extends AppController
|
||||
{
|
||||
public $filterFields = ['scope', 'action', 'title', 'origin', 'comment'];
|
||||
public $quickFilterFields = ['scope', 'action', ['title' => true], ['comment' => true]];
|
||||
public $filterFields = ['scope', 'action', 'title', 'origin', 'message'];
|
||||
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true]];
|
||||
public $containFields = ['Users'];
|
||||
|
||||
public $paginate = [
|
||||
|
|
|
@ -16,8 +16,8 @@ use Cake\Http\Exception\ForbiddenException;
|
|||
|
||||
class OutboxController extends AppController
|
||||
{
|
||||
public $filterFields = ['scope', 'action', 'title', 'comment'];
|
||||
public $quickFilterFields = ['scope', 'action', ['title' => true], ['comment' => true]];
|
||||
public $filterFields = ['scope', 'action', 'title', 'message'];
|
||||
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true]];
|
||||
public $containFields = ['Users'];
|
||||
|
||||
public function beforeFilter(EventInterface $event)
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\ORM\Entity;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
class AppModel extends Entity
|
||||
{
|
||||
|
@ -33,6 +35,11 @@ class AppModel extends Entity
|
|||
return $this->_accessibleOnNew ?? [];
|
||||
}
|
||||
|
||||
public function table(): AppTable
|
||||
{
|
||||
return TableRegistry::get($this->getSource());
|
||||
}
|
||||
|
||||
public function rearrangeForAPI(): void
|
||||
{
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use Cake\ORM\Entity;
|
|||
|
||||
class Inbox extends AppModel
|
||||
{
|
||||
protected $_virtual = ['local_tool_connector_name'];
|
||||
protected $_virtual = ['local_tool_connector_name', 'severity_variant'];
|
||||
|
||||
protected function _getLocalToolConnectorName()
|
||||
{
|
||||
|
@ -17,4 +17,9 @@ class Inbox extends AppModel
|
|||
}
|
||||
return $localConnectorName;
|
||||
}
|
||||
|
||||
protected function _getSeverityVariant(): string
|
||||
{
|
||||
return $this->table()->severityVariant[$this->severity];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,10 @@ use Cake\ORM\Entity;
|
|||
|
||||
class Outbox extends AppModel
|
||||
{
|
||||
|
||||
protected $_virtual = ['severity_variant'];
|
||||
|
||||
protected function _getSeverityVariant(): string
|
||||
{
|
||||
return $this->table()->severityVariant[$this->severity];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use Cake\ORM\Table;
|
|||
use Cake\ORM\RulesChecker;
|
||||
use Cake\Validation\Validator;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\ORM\ResultSet;
|
||||
|
||||
use App\Utility\UI\Notification;
|
||||
|
||||
|
@ -15,6 +16,17 @@ Type::map('json', 'Cake\Database\Type\JsonType');
|
|||
|
||||
class InboxTable extends AppTable
|
||||
{
|
||||
public const SEVERITY_PRIMARY = 0,
|
||||
SEVERITY_INFO = 1,
|
||||
SEVERITY_WARNING = 2,
|
||||
SEVERITY_DANGER = 3;
|
||||
|
||||
public $severityVariant = [
|
||||
self::SEVERITY_PRIMARY => 'primary',
|
||||
self::SEVERITY_INFO => 'info',
|
||||
self::SEVERITY_WARNING => 'warning',
|
||||
self::SEVERITY_DANGER => 'danger',
|
||||
];
|
||||
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
|
@ -97,8 +109,8 @@ class InboxTable extends AppTable
|
|||
$allNotifications = [];
|
||||
$inboxNotifications = $this->getNotificationsForUser($user);
|
||||
foreach ($inboxNotifications as $notification) {
|
||||
$title = __('New message');
|
||||
$details = $notification->title;
|
||||
$title = $notification->title;
|
||||
$details = $notification->message;
|
||||
$router = [
|
||||
'controller' => 'inbox',
|
||||
'action' => 'process',
|
||||
|
@ -109,7 +121,7 @@ class InboxTable extends AppTable
|
|||
'icon' => 'envelope',
|
||||
'details' => $details,
|
||||
'datetime' => $notification->created,
|
||||
'variant' => 'warning',
|
||||
'variant' => $notification->severity_variant,
|
||||
'_useModal' => true,
|
||||
'_sidebarId' => 'inbox',
|
||||
]))->get();
|
||||
|
@ -117,18 +129,14 @@ class InboxTable extends AppTable
|
|||
return $allNotifications;
|
||||
}
|
||||
|
||||
public function getNotificationsForUser(\App\Model\Entity\User $user): array
|
||||
public function getNotificationsForUser(\App\Model\Entity\User $user): ResultSet
|
||||
{
|
||||
$query = $this->find();
|
||||
$conditions = [];
|
||||
if ($user['role']['perm_admin']) {
|
||||
// Admin will not see notifications if it doesn't belong to them. They can see process the message from the inbox
|
||||
$conditions['Inbox.user_id IS'] = null;
|
||||
} else {
|
||||
$conditions['Inbox.user_id'] = $user->id;
|
||||
}
|
||||
$conditions = [
|
||||
'Inbox.user_id' => $user->id
|
||||
];
|
||||
$query->where($conditions);
|
||||
$notifications = $query->all()->toArray();
|
||||
$notifications = $query->all();
|
||||
return $notifications;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ use Cake\ORM\Table;
|
|||
use Cake\ORM\RulesChecker;
|
||||
use Cake\Validation\Validator;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
Type::map('json', 'Cake\Database\Type\JsonType');
|
||||
|
||||
class OutboxTable extends AppTable
|
||||
{
|
||||
public $severityVariant;
|
||||
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
|
@ -22,6 +24,9 @@ class OutboxTable extends AppTable
|
|||
$this->belongsTo('Users');
|
||||
$this->addBehavior('AuditLog');
|
||||
$this->setDisplayField('title');
|
||||
|
||||
$this->Inbox = TableRegistry::getTableLocator()->get('Inbox');
|
||||
$this->severityVariant = $this->Inbox->severityVariant;
|
||||
}
|
||||
|
||||
protected function _initializeSchema(TableSchemaInterface $schema): TableSchemaInterface
|
||||
|
|
|
@ -25,7 +25,7 @@ class Notification
|
|||
foreach ($options as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
$this->validate();
|
||||
$this->_validate();
|
||||
}
|
||||
|
||||
public function get(): array
|
||||
|
@ -36,7 +36,7 @@ class Notification
|
|||
return null;
|
||||
}
|
||||
|
||||
private function validate()
|
||||
protected function _validate()
|
||||
{
|
||||
$validator = new Validator();
|
||||
|
||||
|
|
|
@ -53,6 +53,18 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'data_path' => 'created',
|
||||
'element' => 'datetime'
|
||||
],
|
||||
[
|
||||
'name' => 'severity',
|
||||
'sort' => 'severity',
|
||||
'data_path' => 'severity',
|
||||
'element' => 'function',
|
||||
'function' => function ($entry, $context) {
|
||||
return $context->Bootstrap->badge([
|
||||
'text' => $entry->severity_variant,
|
||||
'variant' => $entry->severity_variant,
|
||||
]);
|
||||
}
|
||||
],
|
||||
[
|
||||
'name' => 'scope',
|
||||
'sort' => 'scope',
|
||||
|
@ -80,14 +92,9 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'element' => 'user'
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description',
|
||||
],
|
||||
[
|
||||
'name' => 'comment',
|
||||
'sort' => 'comment',
|
||||
'data_path' => 'comment',
|
||||
'name' => 'message',
|
||||
'sort' => 'message',
|
||||
'data_path' => 'message',
|
||||
],
|
||||
],
|
||||
'title' => __('Inbox'),
|
||||
|
|
|
@ -33,8 +33,8 @@ echo $this->element(
|
|||
'path' => 'user_id',
|
||||
],
|
||||
[
|
||||
'key' => 'description',
|
||||
'path' => 'description',
|
||||
'key' => 'message',
|
||||
'path' => 'message',
|
||||
],
|
||||
[
|
||||
'key' => 'comment',
|
||||
|
|
|
@ -49,6 +49,18 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'data_path' => 'created',
|
||||
'element' => 'datetime'
|
||||
],
|
||||
[
|
||||
'name' => 'severity',
|
||||
'sort' => 'severity',
|
||||
'data_path' => 'severity',
|
||||
'element' => 'function',
|
||||
'function' => function ($entry, $context) {
|
||||
return $context->Bootstrap->badge([
|
||||
'text' => $entry->severity_variant,
|
||||
'variant' => $entry->severity_variant,
|
||||
]);
|
||||
}
|
||||
],
|
||||
[
|
||||
'name' => 'scope',
|
||||
'sort' => 'scope',
|
||||
|
@ -71,14 +83,9 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'element' => 'user'
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description',
|
||||
],
|
||||
[
|
||||
'name' => 'comment',
|
||||
'sort' => 'comment',
|
||||
'data_path' => 'comment',
|
||||
'name' => 'message',
|
||||
'sort' => 'message',
|
||||
'data_path' => 'message',
|
||||
],
|
||||
],
|
||||
'title' => __('Outbox'),
|
||||
|
|
|
@ -29,8 +29,8 @@ echo $this->element(
|
|||
'path' => 'user_id',
|
||||
],
|
||||
[
|
||||
'key' => 'description',
|
||||
'path' => 'description',
|
||||
'key' => 'message',
|
||||
'path' => 'message',
|
||||
],
|
||||
[
|
||||
'key' => 'comment',
|
||||
|
|
Loading…
Reference in New Issue