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

FEAT #9207 NoteController add ResController

parent 26bb55c0
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ use Respect\Validation\Validator;
use Slim\Http\Request;
use Slim\Http\Response;
use History\controllers\HistoryController;
use Resource\controllers\ResController;
class NoteController
{
......@@ -39,12 +40,16 @@ class NoteController
public function create(Request $request, Response $response)
{
$data = $request->getParams();
if (!Validator::intVal()->validate($data['identifier']) || !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
$check = Validator::stringType()->notEmpty()->validate($data['note_text']);
$check = $check && Validator::intVal()->notEmpty()->validate($data['identifier']); //correspond to res_id
$check = $check && Validator::stringType()->notEmpty()->validate($data['user_id']);
$check = $check && Validator::stringType()->notEmpty()->validate($GLOBALS['userId']);
if(isset($data['entities_chosen'])) {
$check = $check && Validator::arrayType()->validate($data['entities_chosen']);
}
......
......@@ -68,7 +68,7 @@ abstract class NoteModelAbstract
public static function create(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['identifier', 'user_id', 'note_text']);
ValidatorModel::notEmpty($aArgs, ['identifier', 'note_text']);
ValidatorModel::intVal($aArgs, ['identifier']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'notes_seq']);
......@@ -79,7 +79,7 @@ abstract class NoteModelAbstract
'id' => $nextSequenceId,
'identifier' => $aArgs['identifier'],
'tablename' => 'res_letterbox',
'user_id' => $aArgs['user_id'],
'user_id' => $GLOBALS['userId'],
'date_note' => 'CURRENT_TIMESTAMP',
'note_text' => $aArgs['note_text'],
'coll_id' => 'letterbox_coll'
......
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