diff --git a/bin/scheduler.php b/bin/scheduler.php index 287aa80c02230fef2c4bb68737c90282b8467a23..2b14ea7ebebc8c4ab409a6d1b2d72a8439679add 100644 --- a/bin/scheduler.php +++ b/bin/scheduler.php @@ -1,12 +1,13 @@ <?php +use Configuration\models\ConfigurationModel; use Document\models\DocumentModel; use Email\controllers\EmailController; use Notification\models\NotificationsScheduleModel; use Notification\models\NotificationStackModel; use SrcCore\controllers\LanguageController; -use SrcCore\controllers\UrlController; use SrcCore\models\DatabasePDO; +use SrcCore\models\ValidatorModel; use User\models\UserModel; require './vendor/autoload.php'; @@ -16,16 +17,23 @@ $configPath = $argv[1]; DatabasePDO::reset(); new DatabasePDO(['configPath' => $configPath]); -// TODO set which user to use through config ? $restUser = UserModel::get(['select' => ['id'], 'where' => ['"isRest" = ?'], 'data' => ['true']]); if (empty($restUser[0])) { - echo "User not found"; + echo "User not found\n"; exit(1); } $restUser = $restUser[0]; $GLOBALS['id'] = $restUser['id']; -$applicationUrl = UrlController::getCoreUrl(); // TODO get url from configuration +$configuration = ConfigurationModel::getByIdentifier(['identifier' => 'customization']); +$configuration = $configuration[0]; +$configuration = json_decode($configuration['value'], true); +$applicationUrl = $configuration['applicationUrl']; + +if (empty($applicationUrl)) { + echo "Cannot run scheduler : no applicationUrl defined\n"; + exit(1); +} $schedules = NotificationsScheduleModel::get(); @@ -106,6 +114,10 @@ foreach ($schedules as $schedule) { function sendNotifications(array $args) { + ValidatorModel::notEmpty($args, ['stack', 'restUser', 'type', 'applicationUrl']); + ValidatorModel::arrayType($args, ['stack', 'restUser']); + ValidatorModel::stringType($args, ['type', 'applicationUrl']); + $notificationStack = $args['stack']; $restUser = $args['restUser']; @@ -118,9 +130,6 @@ function sendNotifications(array $args) } elseif ($args['type'] == 'typist_INT') { $subjectKey = 'notificationInterruptsSubject'; $bodyKey = 'notificationInterruptsBody'; - } elseif ($args['type'] == 'typist_DEL') { - $subjectKey = 'notificationInterruptsSubject'; - $bodyKey = 'notificationDeletedUsersBody'; } elseif ($args['type'] == 'typist_REF') { $subjectKey = 'notificationRefusedWorkflowsSubject'; $bodyKey = 'notificationDeletedUsersBody'; @@ -167,11 +176,11 @@ function sendNotifications(array $args) ]); } -// $stackIds = array_column($notificationStack, 'id'); -// NotificationsScheduleModel::delete([ -// 'where' => ['id in (?)'], -// 'data' => [$stackIds] -// ]); + $stackIds = array_column($notificationStack, 'id'); + NotificationStackModel::delete([ + 'where' => ['id in (?)'], + 'data' => [$stackIds] + ]); return true; } diff --git a/lang/fr.json b/lang/fr.json index 28a2df062ee1b4fe2e1fc4c42f7d9c3a33658b6c..3919782ab22fe292c813813eab280989a78ed792 100755 --- a/lang/fr.json +++ b/lang/fr.json @@ -586,7 +586,6 @@ "notificationEndOfWorkflowsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié se sont terminés avec succès.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>", "notificationInterruptsSubject": "[Maarch Parapheur] Circuits de visa interrompus", "notificationInterruptsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>", - "notificationDeletedUsersBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu car un utilisateur a été supprimé.<br/><br/>Cliquez sur les lien ci-dessous pour les consulter :<br/>", "notificationRefusedWorkflowsSubject": "[Maarch Parapheur] Circuits de visa refusés", "notificationRefusedWorkflowsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu car un utilisateur a fait une action de refus.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>", "scheduledNotifications": "Notifications", diff --git a/sql/structure.sql b/sql/structure.sql index 2a59c28f2245c4a45b4fd997fe30f48533d30220..341dbdad6481460ec5972eefc2423b88db92ea97 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -307,7 +307,6 @@ CREATE TABLE notifications_stack id serial NOT NULL, main_document_id int NOT NULL, type character varying(256) NOT NULL, - sender_id int, recipient_id INTEGER, CONSTRAINT notifications_stack_pkey PRIMARY KEY (id) ) diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php index 99ecb01e2fec56f5acfa881787f3332d44c669dc..5eca8813a32b74489a75966ef06c14a0aa5d36f1 100644 --- a/src/app/email/controllers/EmailController.php +++ b/src/app/email/controllers/EmailController.php @@ -247,7 +247,7 @@ class EmailController if (in_array($summary, $schedule)) { NotificationStackModel::create([ 'mainDocumentId' => $args['documentId'], - 'type' => 'typist_' . $args['mode'], + 'type' => 'typist_' . ($args['mode'] == 'DEL' ? 'INT' : $args['mode']), 'recipientId' => $args['recipientId'] ]); break; diff --git a/src/app/notifications/controllers/NotificationsScheduleController.php b/src/app/notifications/controllers/NotificationsScheduleController.php index bde55bf4912e36c8f837989c22e81f73c84e3431..85ff0f03fc5326fcbddd893c47e1f4f04c1c0fb2 100644 --- a/src/app/notifications/controllers/NotificationsScheduleController.php +++ b/src/app/notifications/controllers/NotificationsScheduleController.php @@ -75,10 +75,6 @@ class NotificationsScheduleController public function get(Request $request, Response $response) { - if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_notifications'])) { - return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); - } - $rawNotificationsSchedule = NotificationsScheduleModel::get(); $notificationsSchedule = []; @@ -104,6 +100,9 @@ class NotificationsScheduleController public function getById(Request $request, Response $response, array $args) { + if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_notifications'])) { + return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); + } if (!Validator::intVal()->notEmpty()->validate($args['id'])) { return $response->withStatus(400)->withJson(['errors' => 'Route id must be an integer']); } @@ -121,7 +120,7 @@ class NotificationsScheduleController 'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']), 'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']), 'startTime' => (new \DateTime($rawNotificationsScheduleItem['start_time']))->format('H:i'), - 'endTime' => (new \DateTime($rawNotificationsScheduleItem['end_time']))->format('H:i'), + 'endTime' => !empty($rawNotificationsScheduleItem['end_time']) ? (new \DateTime($rawNotificationsScheduleItem['end_time']))->format('H:i') : null, 'frequency' => $rawNotificationsScheduleItem['frequency'], 'frequencyMode' => $rawNotificationsScheduleItem['frequency_mode'], 'status' => $rawNotificationsScheduleItem['status'], diff --git a/src/app/search/controllers/SearchController.php b/src/app/search/controllers/SearchController.php index 8efee6f15206640acc6fea90e0bda9b251fc8d5f..d7e1a654039b7716e765d7a1e4da29271ea5c577 100755 --- a/src/app/search/controllers/SearchController.php +++ b/src/app/search/controllers/SearchController.php @@ -107,7 +107,7 @@ class SearchController $where[] = 'reference ilike ?'; $data[] = "%{$body['reference']}%"; } - if (Validator::numeric()->notEmpty()->validate($body['documentId'] ?? null)) { + if (Validator::numericVal()->notEmpty()->validate($body['documentId'] ?? null)) { $where[] = 'id = ?'; $data[] = $body['documentId']; } diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 3a7f2f007a760972c7c35ffa4ab05e4b22af5726..2f080f1a7df516c56ec0dde88c6745ceb44abdf5 100755 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -60,7 +60,8 @@ class AuthenticationController 'instanceId' => $hashedPath, 'coreUrl' => $coreUrl, 'mailServerOnline' => $mailServerOnline, - 'loginMessage' => $customization['loginMessage'] + 'loginMessage' => $customization['loginMessage'], + 'applicationUrl' => $customization['applicationUrl'] ]); }