From 13f432af8575d2ea4574d5894b3aaca405739ec5 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Fri, 17 Jan 2020 11:05:14 +0100
Subject: [PATCH] FEAT #10633 TIME 0:10 added check on opinion limit date +
 note in preprocess opinion circuit

---
 .../controllers/PreProcessActionController.php   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/app/action/controllers/PreProcessActionController.php b/src/app/action/controllers/PreProcessActionController.php
index e3f7ef3eff1..2ec191690b5 100755
--- a/src/app/action/controllers/PreProcessActionController.php
+++ b/src/app/action/controllers/PreProcessActionController.php
@@ -1052,11 +1052,25 @@ class PreProcessActionController
 
         $resourcesInformation = [];
         foreach ($body['resources'] as $resId) {
-            $resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier']]);
+            $resource = ResModel::getById(['resId' => $resId, 'select' => ['alt_identifier', 'opinion_limit_date']]);
+
             if (empty($resource['alt_identifier'])) {
                 $resource['alt_identifier'] = _UNDEFINED;
             }
 
+            if (empty($resource['opinion_limit_date'])) {
+                return $response->withStatus(400)->withJson(['errors' => 'No opinion limit date for resource ' . $resource['alt_identifier']]);
+            }
+
+            $opinionNote = NoteModel::get([
+                'where'  => ['identifier = ?', "note_text like '[" . _TO_AVIS . "]%'"],
+                'data'   => [$resId]
+            ]);
+
+            if (empty($opinionNote)) {
+                return $response->withStatus(400)->withJson(['errors' => 'No opinion note for resource ' . $resource['alt_identifier']]);
+            }
+
             $isSignatory = ListInstanceModel::get([
                 'select'  => [1],
                 'where'   => ['res_id = ?', 'difflist_type = ?', 'process_date is null'],
-- 
GitLab