Skip to content
Snippets Groups Projects
Commit d9e01634 authored by Vinciane's avatar Vinciane
Browse files

FEAT #9207 NoteController correction + add lang

parent ecf478c7
No related branches found
No related tags found
No related merge requests found
...@@ -41,16 +41,12 @@ class NoteController ...@@ -41,16 +41,12 @@ class NoteController
{ {
$data = $request->getParams(); $data = $request->getParams();
if (!Validator::intVal()->validate($data['identifier']) || !ResController::hasRightByResId(['resId' => $data['identifier'], 'userId' => $GLOBALS['userId']])) { //Check data
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
//Insert note in notes table and recover last insert ID
$check = Validator::stringType()->notEmpty()->validate($data['note_text']); $check = Validator::stringType()->notEmpty()->validate($data['note_text']);
$check = $check && Validator::intVal()->notEmpty()->validate($data['identifier']); //correspond to res_id $check = $check && Validator::intVal()->notEmpty()->validate($data['identifier']); //correspond to res_id
$check = $check && Validator::stringType()->notEmpty()->validate($GLOBALS['userId']); $check = $check && Validator::stringType()->notEmpty()->validate($GLOBALS['userId']);
if(isset($data['entities_chosen'])) { if (isset($data['entities_chosen'])) {
$check = $check && Validator::arrayType()->validate($data['entities_chosen']); $check = $check && Validator::arrayType()->validate($data['entities_chosen']);
} }
...@@ -58,26 +54,31 @@ class NoteController ...@@ -58,26 +54,31 @@ class NoteController
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
$data['note_id'] = NoteModel::create($data); if (!ResController::hasRightByResId(['resId' => $data['identifier'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
//Insert note in notes table and recover last insert ID
$noteId = NoteModel::create($data);
//Insert relation note with entities in note_entities_table //Insert relation note with entities in note_entities_table
if (!empty($data['note_id']) && !empty($data['entities_chosen'])) { if (!empty($noteId) && !empty($data['entities_chosen'])) {
foreach($data['entities_chosen'] as $entity) { foreach($data['entities_chosen'] as $entity) {
$entity = NoteEntityModel::create( ['item_id' => $entity, 'note_id' => $data['note_id'] ]); NoteEntityModel::create( ['item_id' => $entity, 'note_id' => $noteId ]);
} }
} }
//Insert in history //Insert in history
HistoryController::add( [ HistoryController::add( [
'tableName' => "notes", 'tableName' => "notes",
'recordId' => $data['note_id'], 'recordId' => $noteId,
'eventType' => "ADD", 'eventType' => "ADD",
'userId' => $GLOBALS['userId'], 'userId' => $GLOBALS['userId'],
'info' => "Annotation ajoutée (" . $data['note_id'] . ")", 'info' => _NOTE_ADDED . " (" . $noteId . ")",
'moduleId' => 'notes', 'moduleId' => 'notes',
'eventId' => 'noteadd'] 'eventId' => 'noteadd']
); );
return $response->withJson(['noteId' => $data['note_id']]); return $response->withJson(['noteId' => $noteId]);
} }
} }
...@@ -32,5 +32,7 @@ abstract class NoteEntityModelAbstract ...@@ -32,5 +32,7 @@ abstract class NoteEntityModelAbstract
'item_id' => $aArgs['item_id'] 'item_id' => $aArgs['item_id']
] ]
]); ]);
return true;
} }
} }
...@@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'back from vacation'); ...@@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'back from vacation');
define('_DOC_DISPLAYING', 'Displaying document'); define('_DOC_DISPLAYING', 'Displaying document');
define('_DOC_ADDED', 'Document added'); define('_DOC_ADDED', 'Document added');
define('_ATTACH_DISPLAYING', 'Displaying attachment'); define('_ATTACH_DISPLAYING', 'Displaying attachment');
define('_NOTE_ADDED', 'Note added');
// LISTS // LISTS
define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'List with filters and responses'); define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'List with filters and responses');
......
...@@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'de retour de son absence'); ...@@ -132,6 +132,7 @@ define('_BACK_FROM_VACATION', 'de retour de son absence');
define('_DOC_DISPLAYING', 'Visualisation du document'); define('_DOC_DISPLAYING', 'Visualisation du document');
define('_DOC_ADDED', 'Document ajouté'); define('_DOC_ADDED', 'Document ajouté');
define('_ATTACH_DISPLAYING', 'Visualisation de la pièce jointe'); define('_ATTACH_DISPLAYING', 'Visualisation de la pièce jointe');
define('_NOTE_ADDED', 'Annotation ajoutée');
// LISTS // LISTS
define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'Liste avec filtres et réponses'); define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'Liste avec filtres et réponses');
......
...@@ -408,3 +408,4 @@ define('_REDACTOR', 'Opsteller'); ...@@ -408,3 +408,4 @@ define('_REDACTOR', 'Opsteller');
define('_ASSIGNEE', 'Toegekende persoon'); define('_ASSIGNEE', 'Toegekende persoon');
define('_SENDMAIL_PARAM', '_TO_TRANSLATE'); define('_SENDMAIL_PARAM', '_TO_TRANSLATE');
define('_SENDMAIL_PARAM_DESC', '_TO_TRANSLATE'); define('_SENDMAIL_PARAM_DESC', '_TO_TRANSLATE');
define('_NOTE_ADDED', 'note added _TO_TRANSLATE');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment