ResourceControlController.php 26.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/

/**
* @brief Resource Control Controller
* @author dev@maarch.org
*/

namespace Resource\controllers;

use Contact\models\ContactModel;
18
use Convert\controllers\ConvertPdfController;
19
20
21
22
23
use Convert\models\AdrModel;
use CustomField\models\CustomFieldModel;
use Doctype\models\DoctypeModel;
use Entity\models\EntityModel;
use Folder\controllers\FolderController;
24
use Group\controllers\PrivilegeController;
25
26
27
28
29
use IndexingModel\models\IndexingModelFieldModel;
use IndexingModel\models\IndexingModelModel;
use Priority\models\PriorityModel;
use Resource\models\ResModel;
use Respect\Validation\Validator;
30
use SrcCore\controllers\CoreController;
31
32
33
34
35
36
37
38
39
40
use SrcCore\controllers\PreparedClauseController;
use Status\models\StatusModel;
use Tag\models\TagModel;
use User\models\UserGroupModel;
use User\models\UserModel;

class ResourceControlController
{
    protected static function controlResource(array $args)
    {
41
42
        $currentUser = UserModel::getById(['id' => $GLOBALS['id'], 'select' => ['mode']]);
        $isWebServiceUser = $currentUser['mode'] == 'rest';
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

        $body = $args['body'];

        if (empty($body)) {
            return ['errors' => 'Body is not set or empty'];
        } elseif (!Validator::intVal()->notEmpty()->validate($body['doctype'])) {
            return ['errors' => 'Body doctype is empty or not an integer'];
        } elseif (!Validator::intVal()->notEmpty()->validate($body['modelId'])) {
            return ['errors' => 'Body modelId is empty or not an integer'];
        } elseif ($isWebServiceUser && !Validator::stringType()->notEmpty()->validate($body['status'])) {
            return ['errors' => 'Body status is empty or not a string'];
        }

        $doctype = DoctypeModel::getById(['id' => $body['doctype'], 'select' => [1]]);
        if (empty($doctype)) {
            return ['errors' => 'Body doctype does not exist'];
        }

61
        $indexingModel = IndexingModelModel::getById(['id' => $body['modelId'], 'select' => ['master', 'enabled', 'mandatory_file']]);
62
63
64
65
66
67
        if (empty($indexingModel)) {
            return ['errors' => 'Body modelId does not exist'];
        } elseif (!$indexingModel['enabled']) {
            return ['errors' => 'Body modelId is disabled'];
        } elseif (!empty($indexingModel['master'])) {
            return ['errors' => 'Body modelId is not public'];
68
69
        } elseif (empty($body['encodedFile']) && $indexingModel['mandatory_file']) {
            return ['errors' => 'File is mandatory for this indexing model'];
70
71
72
73
74
75
76
        }

        $control = ResourceControlController::controlFileData(['body' => $body]);
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

77
        $control = ResourceControlController::controlAdjacentData(['body' => $body]);
78
79
80
81
82
83
84
85
86
87
88
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

        if (!$isWebServiceUser) {
            $control = ResourceControlController::controlIndexingModelFields(['body' => $body]);
            if (!empty($control['errors'])) {
                return ['errors' => $control['errors']];
            }

            if (!empty($body['initiator'])) {
89
                $userEntities = UserModel::getEntitiesById(['id' => $GLOBALS['id'], 'select' => ['entities.id']]);
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
                $userEntities = array_column($userEntities, 'id');
                if (!in_array($body['initiator'], $userEntities)) {
                    return ['errors' => "Body initiator does not belong to your entities"];
                }
            }
        }

        $control = ResourceControlController::controlDestination(['body' => $body]);
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }
        $control = ResourceControlController::controlDates(['body' => $body]);
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

        if (!empty($body['status'])) {
            $status = StatusModel::getById(['id' => $body['status'], 'select' => [1]]);
            if (empty($status)) {
                return ['errors' => 'Body status does not exist'];
            }
        }

        if (!empty($body['linkedResources'])) {
            if (!ResController::hasRightByResId(['resId' => [$body['linkedResources']], 'userId' => $GLOBALS['id']])) {
                return ['errors' => 'Body linkedResources out of perimeter'];
            }
        }

        return true;
    }

    protected static function controlUpdateResource(array $args)
    {
        $body = $args['body'];

126
127
128
129
        if (empty($body)) {
            return ['errors' => 'Body is not set or empty'];
        }

130
        $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['status', 'model_id', 'format', 'initiator', 'external_id->>\'signatureBookId\' as signaturebookid', 'filename']]);
131
132
133
134
135
136
137
138
        if (empty($resource['status'])) {
            return ['errors' => 'Resource status is empty. It can not be modified'];
        }
        $status = StatusModel::getById(['id' => $resource['status'], 'select' => ['can_be_modified']]);
        if ($status['can_be_modified'] != 'Y') {
            return ['errors' => 'Resource can not be modified because of status'];
        }

Damien's avatar
Damien committed
139
        if (!empty($body['modelId']) && $resource['model_id'] != $body['modelId']) {
140
            if (!PrivilegeController::isResourceInProcess(['userId' => $GLOBALS['id'], 'resId' => $args['resId'], 'canUpdateData' => true, 'canUpdateModel' => true])) {
141
142
                return ['errors' => 'Model can not be modified'];
            }
143
            $indexingModel = IndexingModelModel::getById(['id' => $body['modelId'], 'select' => ['master', 'enabled', 'mandatory_file']]);
144
145
146
147
148
149
            if (empty($indexingModel)) {
                return ['errors' => 'Body modelId does not exist'];
            } elseif (!$indexingModel['enabled']) {
                return ['errors' => 'Body modelId is disabled'];
            } elseif (!empty($indexingModel['master'])) {
                return ['errors' => 'Body modelId is not public'];
150
151
            } elseif (empty($resource['filename']) && $indexingModel['mandatory_file']) {
                return ['errors' => 'File is mandatory for this indexing model'];
152
153
154
            }
        }

155
156
157
        if ($args['onlyDocument'] && empty($body['encodedFile'])) {
            return ['errors' => 'Body encodedFile is not set or empty'];
        } elseif (!empty($body['encodedFile'])) {
158
            if (!empty($resource['signaturebookid'])) {
159
160
161
162
163
164
165
166
167
168
169
170
171
                return ['errors' => 'Resource is in external signature book, file can not be modified'];
            } elseif (ResourceControlController::isSigned(['resId' => $args['resId']])) {
                return ['errors' => 'Resource is signed, file can not be modified'];
            } elseif (!empty($resource['format']) && !ConvertPdfController::canConvert(['extension' => $resource['format']])) {
                return ['errors' => 'Resource is not convertible, file can not be modified'];
            }
            $control = ResourceControlController::controlFileData(['body' => $body]);
            if (!empty($control['errors'])) {
                return ['errors' => $control['errors']];
            }
            if ($args['onlyDocument']) {
                return true;
            }
172
173
        }

174
175
176
        if (!Validator::intVal()->notEmpty()->validate($body['doctype'])) {
            return ['errors' => 'Body doctype is empty or not an integer'];
        }
177
178
179
180
181
        $doctype = DoctypeModel::getById(['id' => $body['doctype'], 'select' => [1]]);
        if (empty($doctype)) {
            return ['errors' => 'Body doctype does not exist'];
        }

182
        $control = ResourceControlController::controlAdjacentData(['body' => $body]);
183
184
185
186
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

187
188
189
        if (empty($body['modelId'])) {
            $body['modelId'] = $resource['model_id'];
        }
ludo's avatar
ludo committed
190
        $control = ResourceControlController::controlIndexingModelFields(['body' => $body, 'isUpdating' => true, 'resId' => $args['resId']]);
191
192
193
194
195
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

        if (!empty($body['initiator'])) {
196
197
198
199
            $entity = EntityModel::getById(['id' => $body['initiator'], 'select' => ['entity_id']]);
            if (empty($entity)) {
                return ['errors' => "Body initiator does not exist"];
            }
Damien's avatar
Damien committed
200
            if ($resource['initiator'] != $entity['entity_id']) {
201
                $userEntities = UserModel::getEntitiesById(['id' => $GLOBALS['id'], 'select' => ['entities.id']]);
202
203
204
205
                $userEntities = array_column($userEntities, 'id');
                if (!in_array($body['initiator'], $userEntities)) {
                    return ['errors' => "Body initiator does not belong to your entities"];
                }
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
            }
        }

        $control = ResourceControlController::controlDestination(['body' => $body]);
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }
        $control = ResourceControlController::controlDates(['body' => $body, 'resId' => $args['resId']]);
        if (!empty($control['errors'])) {
            return ['errors' => $control['errors']];
        }

        return true;
    }

    private static function isSigned(array $args)
    {
        $signedDocument = AdrModel::getDocuments([
            'select'    => [1],
            'where'     => ['res_id = ?', 'type = ?'],
            'data'      => [$args['resId'], 'SIGN']
        ]);

        if (empty($signedDocument)) {
            return false;
        }

        return true;
    }

    private static function controlFileData(array $args)
    {
        $body = $args['body'];

        if (!empty($body['encodedFile'])) {
            if (!Validator::stringType()->notEmpty()->validate($body['format'])) {
                return ['errors' => 'Body format is empty or not a string'];
            }

            $file     = base64_decode($body['encodedFile']);
            $finfo    = new \finfo(FILEINFO_MIME_TYPE);
            $mimeType = $finfo->buffer($file);
            if (!StoreController::isFileAllowed(['extension' => $body['format'], 'type' => $mimeType])) {
                return ['errors' => "Format with this mimeType is not allowed : {$body['format']} {$mimeType}"];
            }
251

252
            $maximumSize = CoreController::getMaximumAllowedSizeFromPhpIni();
253
254
255
            if ($maximumSize > 0 && strlen($file) > $maximumSize) {
                return ['errors' => "Body encodedFile size is over limit"];
            }
256
257
        }

258
259
260
261
        if (!empty($body['originalFilename']) && !Validator::stringType()->length(1, 255)->validate($body['format'])) {
            return ['errors' => 'Body originalName is not a string or is more than 255 characters'];
        }

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
        return true;
    }

    private static function controlAdjacentData(array $args)
    {
        $body = $args['body'];

        if (!empty($body['customFields'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['customFields'])) {
                return ['errors' => 'Body customFields is not an array'];
            }
            $customFields = CustomFieldModel::get(['select' => ['count(1)'], 'where' => ['id in (?)'], 'data' => [array_keys($body['customFields'])]]);
            if (count($body['customFields']) != $customFields[0]['count']) {
                return ['errors' => 'Body customFields : One or more custom fields do not exist'];
            }
        }
        if (!empty($body['folders'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['folders'])) {
                return ['errors' => 'Body folders is not an array'];
            }
            if (!FolderController::hasFolders(['folders' => $body['folders'], 'userId' => $GLOBALS['id']])) {
                return ['errors' => 'Body folders : One or more folders do not exist or are out of perimeter'];
            }
        }
        if (!empty($body['tags'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['tags'])) {
                return ['errors' => 'Body tags is not an array'];
            }
            $tags = TagModel::get(['select' => ['count(1)'], 'where' => ['id in (?)'], 'data' => [$body['tags']]]);
            if (count($body['tags']) != $tags[0]['count']) {
                return ['errors' => 'Body tags : One or more tags do not exist'];
            }
        }
        if (!empty($body['senders'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['senders'])) {
                return ['errors' => 'Body senders is not an array'];
            }
            foreach ($body['senders'] as $key => $sender) {
                if (!Validator::arrayType()->notEmpty()->validate($sender)) {
                    return ['errors' => "Body senders[{$key}] is not an array"];
302
303
                } elseif (!Validator::intVal()->notEmpty()->validate($sender['id'])) {
                    return ['errors' => "Body senders[{$key}][id] is empty or not an integer"];
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
                }
                if ($sender['type'] == 'contact') {
                    $senderItem = ContactModel::getById(['id' => $sender['id'], 'select' => [1]]);
                } elseif ($sender['type'] == 'user') {
                    $senderItem = UserModel::getById(['id' => $sender['id'], 'select' => [1]]);
                } elseif ($sender['type'] == 'entity') {
                    $senderItem = EntityModel::getById(['id' => $sender['id'], 'select' => [1]]);
                } else {
                    return ['errors' => "Body senders[{$key}] type is not valid"];
                }
                if (empty($senderItem)) {
                    return ['errors' => "Body senders[{$key}] id does not exist"];
                }
            }
        }
        if (!empty($body['recipients'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['recipients'])) {
                return ['errors' => 'Body recipients is not an array'];
            }
            foreach ($body['recipients'] as $key => $recipient) {
                if (!Validator::arrayType()->notEmpty()->validate($recipient)) {
                    return ['errors' => "Body recipients[{$key}] is not an array"];
326
327
                } elseif (!Validator::intVal()->notEmpty()->validate($recipient['id'])) {
                    return ['errors' => "Body recipients[{$key}][id] is empty or not an integer"];
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
                }
                if ($recipient['type'] == 'contact') {
                    $recipientItem = ContactModel::getById(['id' => $recipient['id'], 'select' => [1]]);
                } elseif ($recipient['type'] == 'user') {
                    $recipientItem = UserModel::getById(['id' => $recipient['id'], 'select' => [1]]);
                } elseif ($recipient['type'] == 'entity') {
                    $recipientItem = EntityModel::getById(['id' => $recipient['id'], 'select' => [1]]);
                } else {
                    return ['errors' => "Body recipients[{$key}] type is not valid"];
                }
                if (empty($recipientItem)) {
                    return ['errors' => "Body recipients[{$key}] id does not exist"];
                }
            }
        }
        if (!empty($body['diffusionList'])) {
            if (!Validator::arrayType()->notEmpty()->validate($body['diffusionList'])) {
                return ['errors' => 'Body diffusionList is not an array'];
            }
            $destFound = false;
            foreach ($body['diffusionList'] as $key => $diffusion) {
349
350
351
352
353
                if (!Validator::arrayType()->notEmpty()->validate($diffusion)) {
                    return ['errors' => "Body diffusionList[{$key}] is not an array"];
                } elseif (!Validator::intVal()->notEmpty()->validate($diffusion['id'])) {
                    return ['errors' => "Body diffusionList[{$key}][id] is empty or not an integer"];
                }
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
                if ($diffusion['mode'] == 'dest') {
                    if ($destFound) {
                        return ['errors' => "Body diffusionList has multiple dest"];
                    }
                    $destFound = true;
                }
                if ($diffusion['type'] == 'user' || $diffusion['mode'] == 'dest') {
                    $item = UserModel::getById(['id' => $diffusion['id'], 'select' => [1]]);
                } else {
                    $item = EntityModel::getById(['id' => $diffusion['id'], 'select' => [1]]);
                }
                if (empty($item)) {
                    return ['errors' => "Body diffusionList[{$key}] id does not exist"];
                }
            }
            if (!$destFound) {
                return ['errors' => 'Body diffusion has no dest'];
            }
        }

        return true;
    }

    private static function controlIndexingModelFields(array $args)
    {
        $body = $args['body'];

        $indexingModelFields = IndexingModelFieldModel::get(['select' => ['identifier', 'mandatory'], 'where' => ['model_id = ?'], 'data' => [$body['modelId']]]);
        foreach ($indexingModelFields as $indexingModelField) {
            if (strpos($indexingModelField['identifier'], 'indexingCustomField_') !== false) {
                $customFieldId = explode('_', $indexingModelField['identifier'])[1];
                if ($indexingModelField['mandatory'] && empty($body['customFields'][$customFieldId])) {
                    return ['errors' => "Body customFields[{$customFieldId}] is empty"];
                }
                if (!empty($body['customFields'][$customFieldId])) {
                    $customField = CustomFieldModel::getById(['id' => $customFieldId, 'select' => ['type', 'values']]);
390
391
392
                    $possibleValues = empty($customField['values']) ? [] : json_decode($customField['values'], true);
                    if (!empty($possibleValues['table'])) {
                        $possibleValues = CustomFieldModel::getValuesSQL($possibleValues);
393
                        $possibleValues = array_column($possibleValues, 'key');
394
                    }
395
396
397
398
399
400
401
402
403
404
405
                    if (($customField['type'] == 'select' || $customField['type'] == 'radio') && !in_array($body['customFields'][$customFieldId], $possibleValues)) {
                        return ['errors' => "Body customFields[{$customFieldId}] has wrong value"];
                    } elseif ($customField['type'] == 'checkbox') {
                        if (!is_array($body['customFields'][$customFieldId])) {
                            return ['errors' => "Body customFields[{$customFieldId}] is not an array"];
                        }
                        foreach ($body['customFields'][$customFieldId] as $value) {
                            if (!in_array($value, $possibleValues)) {
                                return ['errors' => "Body customFields[{$customFieldId}] has wrong value"];
                            }
                        }
406
                    } elseif ($customField['type'] == 'banAutocomplete') {
407
408
409
                        if (empty($body['customFields'][$customFieldId][0]) || !is_array($body['customFields'][$customFieldId][0])) {
                            return ['errors' => "Body customFields[{$customFieldId}] is not an array"];
                        }
410
411
412
413
                        if (empty($body['customFields'][$customFieldId][0]['longitude'])) {
                            return ['errors' => "Body customFields[{$customFieldId}] longitude is empty"];
                        } elseif (empty($body['customFields'][$customFieldId][0]['latitude'])) {
                            return ['errors' => "Body customFields[{$customFieldId}] latitude is empty"];
414
415
416
417
418
                        } elseif (empty($body['customFields'][$customFieldId][0]['addressTown'])) {
                            return ['errors' => "Body customFields[{$customFieldId}] addressTown is empty"];
                        } elseif (empty($body['customFields'][$customFieldId][0]['addressPostcode'])) {
                            return ['errors' => "Body customFields[{$customFieldId}] addressPostcode is empty"];
                        }
419
420
                    } elseif ($customField['type'] == 'string' && !Validator::stringType()->notEmpty()->validate($body['customFields'][$customFieldId])) {
                        return ['errors' => "Body customFields[{$customFieldId}] is not a string"];
421
422
                    } elseif ($customField['type'] == 'integer' && !Validator::floatVal()->notEmpty()->validate($body['customFields'][$customFieldId])) {
                        return ['errors' => "Body customFields[{$customFieldId}] is not a number"];
423
424
425
426
                    } elseif ($customField['type'] == 'date' && !Validator::date()->notEmpty()->validate($body['customFields'][$customFieldId])) {
                        return ['errors' => "Body customFields[{$customFieldId}] is not a date"];
                    }
                }
427
            } elseif ($indexingModelField['identifier'] == 'destination' && !empty($args['isUpdating'])) {
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
                continue;
            } elseif ($indexingModelField['mandatory'] && !isset($body[$indexingModelField['identifier']])) {
                return ['errors' => "Body {$indexingModelField['identifier']} is not set"];
            }
        }

        return true;
    }

    private static function controlDates(array $args)
    {
        $body = $args['body'];

        if (!empty($body['documentDate'])) {
            if (!Validator::date()->notEmpty()->validate($body['documentDate'])) {
                return ['errors' => "Body documentDate is not a date"];
            }

446
447
448
449
450
            $model = IndexingModelModel::getById(['id' => $body['modelId'], 'select' => ['category']]);
            if ($model['category'] != 'outgoing') {
                $documentDate = new \DateTime($body['documentDate']);
                $tmr = new \DateTime('tomorrow');
                if ($documentDate > $tmr) {
451
                    return ['errors' => "Body documentDate cannot be a date in the future"];
452
                }
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
            }
        }
        if (!empty($body['arrivalDate'])) {
            if (!Validator::date()->notEmpty()->validate($body['arrivalDate'])) {
                return ['errors' => "Body arrivalDate is not a date"];
            }

            $arrivalDate = new \DateTime($body['arrivalDate']);
            $tmr = new \DateTime('tomorrow');
            if ($arrivalDate > $tmr) {
                return ['errors' => "Body arrivalDate is not a valid date"];
            }
        }
        if (!empty($body['departureDate'])) {
            if (!Validator::date()->notEmpty()->validate($body['departureDate'])) {
                return ['errors' => "Body departureDate is not a date"];
            }
            $departureDate = new \DateTime($body['departureDate']);
            if (!empty($documentDate) && $departureDate < $documentDate) {
                return ['errors' => "Body departureDate is not a valid date"];
            }
        }
        if (!empty($body['processLimitDate'])) {
            if (!Validator::date()->notEmpty()->validate($body['processLimitDate'])) {
                return ['errors' => "Body processLimitDate is not a date"];
            }

            if (!empty($args['resId'])) {
                $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['process_limit_date']]);
                if (!empty($resource['process_limit_date'])) {
                    $originProcessLimitDate = new \DateTime($resource['process_limit_date']);
                }
            }
            $processLimitDate = new \DateTime($body['processLimitDate']);
            if (empty($originProcessLimitDate) || $originProcessLimitDate != $processLimitDate) {
                $today = new \DateTime();
                $today->setTime(00, 00, 00);
                if ($processLimitDate < $today) {
                    return ['errors' => "Body processLimitDate is not a valid date"];
                }
            }
        } elseif (!empty($body['priority'])) {
495
496
497
            if (!Validator::stringType()->validate($body['priority'])) {
                return ['errors' => "Body priority is not a string"];
            }
ludo's avatar
ludo committed
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
            $priority = PriorityModel::getById(['id' => $body['priority'], 'select' => [1]]);
            if (empty($priority)) {
                return ['errors' => "Body priority does not exist"];
            }
        }

        return true;
    }

    private static function controlDestination(array $args)
    {
        $body = $args['body'];

        if (!empty($body['destination'])) {
            $groups = UserGroupModel::getWithGroups([
                'select'    => ['usergroups.indexation_parameters'],
                'where'     => ['usergroup_content.user_id = ?', 'usergroups.can_index = ?'],
                'data'      => [$GLOBALS['id'], true]
            ]);

            $clauseToProcess = '';
            $allowedEntities = [];
            foreach ($groups as $group) {
                $group['indexation_parameters'] = json_decode($group['indexation_parameters'], true);
                foreach ($group['indexation_parameters']['keywords'] as $keywordValue) {
524
525
                    if (!empty($clauseToProcess)) {
                        $clauseToProcess .= ', ';
526
                    }
527
                    $clauseToProcess .= IndexingController::KEYWORDS[$keywordValue];
528
529
530
531
532
533
                }
                $allowedEntities = array_merge($allowedEntities, $group['indexation_parameters']['entities']);
                $allowedEntities = array_unique($allowedEntities);
            }

            if (!empty($clauseToProcess)) {
534
                $preparedClause = PreparedClauseController::getPreparedClause(['clause' => $clauseToProcess, 'login' => $GLOBALS['login']]);
535
536
537
538
539
540
541
542
543
544
545
546
547
548
                $preparedEntities = EntityModel::get(['select' => ['id'], 'where' => ['enabled = ?', "entity_id in {$preparedClause}"], 'data' => ['Y']]);
                $preparedEntities = array_column($preparedEntities, 'id');
                $allowedEntities = array_merge($allowedEntities, $preparedEntities);
                $allowedEntities = array_unique($allowedEntities);
            }

            if (!in_array($body['destination'], $allowedEntities)) {
                return ['errors' => "Body destination is out of your indexing parameters"];
            }
        }

        return true;
    }
}