diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php index ff3b0e2bf26daf6aef4877b3bf64e53b94555fec..a1878a856c27077e20ee7cfb2eaa47fa172860a2 100755 --- a/src/app/note/controllers/NoteController.php +++ b/src/app/note/controllers/NoteController.php @@ -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']); } diff --git a/src/app/note/models/NoteModelAbstract.php b/src/app/note/models/NoteModelAbstract.php index f48d851c28078349ee6f16835b97936a78e4f38a..0dee049b8d53eb8e5c906f92b6dc290e52474726 100755 --- a/src/app/note/models/NoteModelAbstract.php +++ b/src/app/note/models/NoteModelAbstract.php @@ -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'