Skip to content
Snippets Groups Projects
Commit 97355f76 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FIX #9685 add restriced note model by destination

parent 264b5cb8
No related branches found
No related tags found
No related merge requests found
...@@ -214,7 +214,8 @@ $app->get('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplat ...@@ -214,7 +214,8 @@ $app->get('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplat
$app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':updateTypeRoles'); $app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':updateTypeRoles');
//Notes //Notes
$app->get('/notes/templates', \Note\controllers\NoteController::class . ':getTemplateList'); $app->get('/res/{resId}/notes/templates', \Note\controllers\NoteController::class . ':getTemplateListByResId');
$app->get('/notes/templates', \Note\controllers\NoteController::class . ':getAllTemplateList');
$app->get('/res/{resId}/notes', \Note\controllers\NoteController::class . ':getByResId'); $app->get('/res/{resId}/notes', \Note\controllers\NoteController::class . ':getByResId');
$app->post('/res/{resId}/notes', \Note\controllers\NoteController::class . ':create'); $app->post('/res/{resId}/notes', \Note\controllers\NoteController::class . ':create');
......
...@@ -26,6 +26,8 @@ use History\controllers\HistoryController; ...@@ -26,6 +26,8 @@ use History\controllers\HistoryController;
use Resource\controllers\ResController; use Resource\controllers\ResController;
use SrcCore\models\ValidatorModel; use SrcCore\models\ValidatorModel;
use User\models\UserModel; use User\models\UserModel;
use Template\models\TemplateModel;
use Resource\models\ResModel;
class NoteController class NoteController
{ {
...@@ -124,15 +126,37 @@ class NoteController ...@@ -124,15 +126,37 @@ class NoteController
return ['encodedDocument' => base64_encode($fileContent)]; return ['encodedDocument' => base64_encode($fileContent)];
} }
public static function getTemplateList(Request $request, Response $response, array $aArgs) public static function getTemplateListByResId(Request $request, Response $response, array $aArgs)
{ {
//get user entities $check = Validator::intVal()->notEmpty()->validate($aArgs['resId']);
$userEntities = UserModel::getEntitiesById(['userId' => $GLOBALS['userId']]); if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'resId is empty or not an integer']);
}
if (!empty($aArgs['resId']) && !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$userEntities = array_column($userEntities, 'entity_id'); //get all templates note
$tmpAllNotes = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_id', 'template_label', 'template_content']]);
//get templates note //get entity resource
$aReturn = NoteModel::getTemplateList(['entityIds' => $userEntities, 'select' => ['template_label', 'template_content']]); $resEntity = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['destination']]);
if (!empty($resEntity['destination'])) {
//get retricted templates note
$aReturn = TemplateModel::getWithAssociation(['select' => ['DISTINCT(templates.template_id), template_label', 'template_content'], 'where' => ['template_target = ?', 'value_field = ?', 'templates.template_id = templates_association.template_id'], 'data' => ['notes', $resEntity['destination']], 'orderBy' => ['template_label']]);
} else {
$aReturn = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]);
}
return $response->withJson($aReturn);
}
public static function getAllTemplateList(Request $request, Response $response)
{
//get all templates note
$aReturn = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]);
return $response->withJson($aReturn); return $response->withJson($aReturn);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<div class="alert-message alert-message-success" role="alert" style="margin-top: 30px;" [innerHTML]="lang.updateClosingDate"></div> <div class="alert-message alert-message-success" role="alert" style="margin-top: 30px;" [innerHTML]="lang.updateClosingDate"></div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<app-note-editor #noteEditor></app-note-editor> <app-note-editor #noteEditor [resIds]="data.selectedRes"></app-note-editor>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -18,7 +18,7 @@ export class NoteEditorComponent implements AfterViewInit { ...@@ -18,7 +18,7 @@ export class NoteEditorComponent implements AfterViewInit {
content: string = ''; content: string = '';
@Input('mode') mode: any; @Input('resIds') resIds: any[];
constructor(public http: HttpClient) { } constructor(public http: HttpClient) { }
...@@ -49,10 +49,18 @@ export class NoteEditorComponent implements AfterViewInit { ...@@ -49,10 +49,18 @@ export class NoteEditorComponent implements AfterViewInit {
getTemplatesNote() { getTemplatesNote() {
if (this.templatesNote.length == 0) { if (this.templatesNote.length == 0) {
this.http.get("../../rest/notes/templates") if (this.resIds.length == 1) {
.subscribe((data: any) => { this.http.get("../../rest/res/" + this.resIds[0] + "/notes/templates")
this.templatesNote = data; .subscribe((data: any) => {
}); this.templatesNote = data;
});
} else {
this.http.get("../../rest/notes/templates")
.subscribe((data: any) => {
this.templatesNote = data;
});
}
} }
} }
} }
\ No newline at end of file
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