Skip to content

Commit 26ec0b6

Browse files
committed
Merge branch 'develop'
2 parents d3f0820 + 76b682e commit 26ec0b6

File tree

10 files changed

+86
-25
lines changed

10 files changed

+86
-25
lines changed

src/Controller/Component/CRUDComponent.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function index(array $options): void
5151
$options['filters'][] = 'filteringTags';
5252
}
5353
$optionFilters = [];
54-
$optionFilters += empty($options['filters']) ? [] : $options['filters'];
54+
$optionFilters += array_map(function($filter) {
55+
return is_array($filter) ? $filter['name'] : $filter;
56+
}, empty($options['filters']) ? [] : $options['filters']);
5557
foreach ($optionFilters as $i => $filter) {
5658
$optionFilters[] = "{$filter} !=";
5759
$optionFilters[] = "{$filter} >=";
@@ -90,14 +92,17 @@ public function index(array $options): void
9092
if ($this->_validOrderFields($sort) && ($direction === 'asc' || $direction === 'desc')) {
9193
$sort = explode('.', $sort);
9294
if (count($sort) > 1) {
93-
$sort[0] = Inflector::camelize(Inflector::pluralize($sort[0]));
95+
if ($sort[0] != $this->Table->getAlias()) {
96+
$sort[0] = Inflector::camelize(Inflector::pluralize($sort[0]));
97+
}
9498
}
9599
$sort = implode('.', $sort);
96100
$query->order($sort . ' ' . $direction);
97101
}
98102
}
103+
$isRestOrCSV = $this->Controller->ParamHandler->isRest() || $this->request->is('csv');
99104
if ($this->metaFieldsSupported()) {
100-
$query = $this->includeRequestedMetaFields($query);
105+
$query = $this->includeRequestedMetaFields($query, $isRestOrCSV);
101106
}
102107

103108
if (!$this->Controller->ParamHandler->isRest()) {
@@ -107,7 +112,7 @@ public function index(array $options): void
107112
}
108113
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
109114
$totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count'];
110-
if ($this->Controller->ParamHandler->isRest() || $this->request->is('csv')) {
115+
if ($isRestOrCSV) {
111116
if (isset($options['hidden'])) {
112117
$data->each(function($value, $key) use ($options) {
113118
$hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']];
@@ -256,6 +261,13 @@ public function filtering(): void
256261
foreach ($filtersConfigRaw as $fieldConfig) {
257262
if (is_array($fieldConfig)) {
258263
$filtersConfig[$fieldConfig['name']] = $fieldConfig;
264+
if (!empty($fieldConfig['options'])) {
265+
if (is_string($fieldConfig['options'])) {
266+
$filtersConfig[$fieldConfig['name']]['options'] = $this->Table->{$fieldConfig['options']}($this->Controller->ACL->getUser());
267+
} else {
268+
$filtersConfig[$fieldConfig['name']]['options'] = $fieldConfig['options'];
269+
}
270+
}
259271
} else {
260272
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
261273
}
@@ -777,8 +789,11 @@ public function attachMetaTemplates($data, $metaTemplates, $pruneEmptyDisabled=t
777789
return $data;
778790
}
779791

780-
protected function includeRequestedMetaFields($query)
792+
protected function includeRequestedMetaFields($query, $isREST=false)
781793
{
794+
if (!empty($isREST)) {
795+
return $query->contain(['MetaFields']);
796+
}
782797
$user = $this->Controller->ACL->getUser();
783798
$tableSettings = IndexSetting::getTableSetting($user, $this->Table);
784799
if (empty($tableSettings['visible_meta_column'])) {
@@ -1362,7 +1377,12 @@ protected function setNestedRelatedCondition($query, $filterParts, $filterValue)
13621377
protected function setRelatedCondition($query, $modelName, $fieldName, $filterValue)
13631378
{
13641379
return $query->matching($modelName, function (\Cake\ORM\Query $q) use ($fieldName, $filterValue) {
1365-
return $this->setValueCondition($q, $fieldName, $filterValue);
1380+
if (is_array($filterValue)) {
1381+
$query = $this->setInCondition($q, $fieldName, $filterValue);
1382+
} else {
1383+
$query = $this->setValueCondition($q, $fieldName, $filterValue);
1384+
}
1385+
return $query;
13661386
});
13671387
}
13681388

src/Controller/InboxController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
class InboxController extends AppController
1818
{
19-
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', 'Users.username',];
19+
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', ['name' => 'Users.username', 'multiple' => true, 'options' => 'getAllUsername', 'select2' => true],];
2020
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true], 'origin'];
2121
public $containFields = ['Users'];
2222

2323
public $paginate = [
2424
'order' => [
2525
'Inbox.created' => 'desc'
26-
]
26+
],
2727
];
2828

2929
public function beforeFilter(EventInterface $event)

src/Model/Behavior/NotifyAdminsBehavior.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function afterDelete(EventInterface $event, EntityInterface $entity, Arra
7373
public function isNotificationAllowed(EventInterface $event, EntityInterface $entity, ArrayObject $options): bool
7474
{
7575
$loggedUser = Configure::read('loggedUser');
76-
if (empty($loggedUser) || !empty($loggedUser['role']['perm_admin']) || !empty($loggedUser['role']['perm_sync'])) {
76+
if (
77+
empty(Configure::read('inbox.data_change_notify_for_all', false)) &&
78+
(empty($loggedUser) || !empty($loggedUser['role']['perm_admin']) || !empty($loggedUser['role']['perm_sync']))
79+
) {
7780
return false;
7881
}
7982
return true;
@@ -322,7 +325,7 @@ protected function _serializeFields($fields): array
322325
} else if (is_object($fieldValue)) {
323326
switch (get_class($fieldValue)) {
324327
case 'Cake\I18n\FrozenTime':
325-
return $fieldValue->i18nFormat('yyyy-mm-dd HH:mm:ss');
328+
return $fieldValue->i18nFormat('yyyy-MM-dd HH:mm:ss');
326329
}
327330
} else {
328331
return strval($fieldValue);

src/Model/Entity/AppModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function rearrangeMetaFields(array $options = []): void
7878
$this->meta_fields[$i]['template_namespace'] = $templates[$templateDirectoryId]['namespace'];
7979
}
8080
}
81-
if (!empty($options['smartFlattenMetafields'])) {
81+
if (!empty($this->meta_fields) && !empty($options['smartFlattenMetafields'])) {
8282
$smartFlatten = [];
8383
foreach ($this->meta_fields as $metafield) {
8484
$key = "{$metafield['template_name']}_v{$metafield['template_version']}:{$metafield['field']}";

src/Model/Table/InboxTable.php

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace App\Model\Table;
33

44
use App\Model\Table\AppTable;
5+
use Cake\Utility\Hash;
56
use Cake\Database\Schema\TableSchemaInterface;
67
use Cake\Database\Type;
78
use Cake\ORM\Table;
@@ -72,6 +73,17 @@ public function buildRules(RulesChecker $rules): RulesChecker
7273
return $rules;
7374
}
7475

76+
public function getAllUsername($currentUser): array
77+
{
78+
$this->Users = \Cake\ORM\TableRegistry::getTableLocator()->get('Users');
79+
$conditions = [];
80+
if (empty($currentUser['role']['perm_admin'])) {
81+
$conditions['organisation_id IN'] = [$currentUser['organisation_id']];
82+
}
83+
$users = $this->Users->find()->where($conditions)->all()->extract('username')->toList();
84+
return Hash::combine($users, '{n}', '{n}');
85+
}
86+
7587
public function checkUserBelongsToBroodOwnerOrg($user, $entryData) {
7688
$this->Broods = \Cake\ORM\TableRegistry::getTableLocator()->get('Broods');
7789
$this->Individuals = \Cake\ORM\TableRegistry::getTableLocator()->get('Individuals');

src/Model/Table/IndividualsTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildRules(RulesChecker $rules): RulesChecker
5757
public function validationDefault(Validator $validator): Validator
5858
{
5959
$validator
60-
->notEmptyString('email')
60+
->email('email')
6161
->requirePresence(['email'], 'create');
6262
return $validator;
6363
}

src/Model/Table/SettingProviders/CerebrateSettingsProvider.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,20 @@ protected function generateSettingsConfiguration()
351351
],
352352
]
353353
]
354-
]
354+
],
355+
'Inbox' => [
356+
'Data change notification' => [
357+
'Data change notification' => [
358+
'inbox.data_change_notify_for_all' => [
359+
'name' => __('Notify data modification for all Users'),
360+
'type' => 'boolean',
361+
'description' => __('Turning this option ON will alert administrators whenever data is modified, irrespective of the user\'s role responsible for the modification.'),
362+
'default' => false,
363+
'severity' => 'warning',
364+
],
365+
],
366+
],
367+
],
355368
/*
356369
'Features' => [
357370
'Demo Settings' => [

src/VERSION.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "1.17",
2+
"version": "1.18",
33
"application": "Cerebrate"
44
}

templates/Inbox/index.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
'fields' => [
4545
[
4646
'name' => '#',
47-
'sort' => 'id',
47+
'sort' => 'Inbox.id',
4848
'data_path' => 'id',
4949
],
5050
[
5151
'name' => 'created',
52-
'sort' => 'created',
52+
'sort' => 'Inbox.created',
5353
'data_path' => 'created',
5454
'element' => 'datetime'
5555
],
@@ -87,7 +87,7 @@
8787
],
8888
[
8989
'name' => 'user',
90-
'sort' => 'user_id',
90+
'sort' => 'Inbox.user_id',
9191
'data_path' => 'user',
9292
'element' => 'user'
9393
],

templates/genericTemplates/filters.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,22 @@
5656
'label' => '',
5757
'class' => 'fieldValue form-control-sm'
5858
];
59-
if (!empty($filtersConfig[$fieldName]['multiple'])) {
60-
$fieldData['type'] = 'dropdown';
61-
$fieldData['multiple'] = true;
62-
$fieldData['select2'] = [
63-
'tags' => true,
64-
'tokenSeparators' => [',', ' '],
65-
];
59+
if (!empty($filtersConfig[$fieldName])) {
60+
if (!empty($filtersConfig[$fieldName]['options'])) {
61+
$fieldData['options'] = $filtersConfig[$fieldName]['options'];
62+
}
63+
if (!empty($filtersConfig[$fieldName]['select2'])) {
64+
$fieldData['type'] = 'dropdown';
65+
$fieldData['select2'] = true;
66+
}
67+
if (!empty($filtersConfig[$fieldName]['multiple'])) {
68+
$fieldData['type'] = 'dropdown';
69+
$fieldData['multiple'] = true;
70+
$fieldData['select2'] = [
71+
'tags' => true,
72+
'tokenSeparators' => [',', ' '],
73+
];
74+
}
6675
}
6776
$this->Form->setTemplates([
6877
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
@@ -187,6 +196,7 @@ function setFilteringValues($filteringTable, field, value, operator) {
187196
$row = $filteringTable.find('td > span.fieldName').filter(function() {
188197
return $(this).data('fieldname') == field
189198
}).closest('tr')
199+
$row.addClass('table-warning')
190200
$row.find('.fieldOperator').val(operator)
191201
const $formElement = $row.find('.fieldValue');
192202
if ($formElement.attr('type') === 'datetime-local') {
@@ -195,7 +205,10 @@ function setFilteringValues($filteringTable, field, value, operator) {
195205
let newOptions = [];
196206
value.forEach(aValue => {
197207
const existingOption = $formElement.find('option').filter(function() {
198-
return $(this).val() === aValue
208+
if ($(this).val() === aValue) {
209+
$(this).prop('selected', true)
210+
return true
211+
}
199212
})
200213
if (existingOption.length == 0) {
201214
newOptions.push(new Option(aValue, aValue, true, true))

0 commit comments

Comments
 (0)