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

FEAT #9901 Entities restriction

parent 4228fdfb
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,16 @@ class NoteController ...@@ -42,7 +42,16 @@ class NoteController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
} }
$aNotes = NoteModel::getByResId(['select' => ['notes.id', 'firstname', 'lastname', 'entity_label', 'note_text', 'creation_date'], 'resId' => $aArgs['resId'], 'orderBy' => ['creation_date DESC']]); $user = UserModel::getByLogin(['select' => ['id'], 'login' => $GLOBALS['userId']]);
$aNotes = NoteModel::getByUserIdForResource(['select' => ['*'], 'resId' => $aArgs['resId'], 'userId' => $user['id']]);
foreach($aNotes as $key => $aNote) {
$aUser = UserModel::getByLogin(['select' => ['firstname', 'lastname'], 'login' => $aNote['user_id']]);
$primaryEntity = UserModel::getPrimaryEntityByUserId(['userId' => $aNote['user_id']]);
$aNotes[$key]['firstname'] = $aUser['firstname'];
$aNotes[$key]['lastname'] = $aUser['lastname'];
$aNotes[$key]['entity_label'] = $primaryEntity['entity_label'];
}
return $response->withJson($aNotes); return $response->withJson($aNotes);
} }
......
...@@ -49,4 +49,19 @@ class NoteEntityModel ...@@ -49,4 +49,19 @@ class NoteEntityModel
return true; return true;
} }
public static function getWithEntityInfo(array $aArgs = [])
{
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']);
$noteEntities = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['note_entities', 'entities'],
'left_join' => ['note_entities.item_id = entities.entity_id'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data']
]);
return $noteEntities;
}
} }
\ No newline at end of file
...@@ -196,21 +196,24 @@ class NoteModel ...@@ -196,21 +196,24 @@ class NoteModel
$notes = []; $notes = [];
foreach ($allNotes as $note) { foreach ($allNotes as $note) {
$allowed = false; $allowed = false;
if ($note['user_id'] == $user['user_id']) { if ($note['user_id'] == $user['user_id']) {
$allowed = true; $allowed = true;
} else { }
$noteEntities = NoteEntityModel::get(['select' => ['item_id'], 'where' => ['note_id = ?'], 'data' => [$note['id']]]);
if (!empty($noteEntities)) { $noteEntities = NoteEntityModel::getWithEntityInfo(['select' => ['item_id', 'short_label'], 'where' => ['note_id = ?'], 'data' => [$note['id']]]);
foreach ($noteEntities as $noteEntity) { if (!empty($noteEntities)) {
if (in_array($noteEntity['item_id'], $userEntities)) { foreach ($noteEntities as $noteEntity) {
$allowed = true; $note['entities_restriction'][] = ['short_label' => $noteEntity['short_label'], 'item_id' => [$noteEntity['item_id']]];
break;
} if (in_array($noteEntity['item_id'], $userEntities)) {
$allowed = true;
} }
} else {
$allowed = true;
} }
} else {
$allowed = true;
} }
if ($allowed) { if ($allowed) {
$notes[] = $note; $notes[] = $note;
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
{{note.note_text}} {{note.note_text}}
</p> </p>
<span *ngFor="let entity of note.entities_restriction" class="label label-default" style="background-color:rgba(0,0,0,0.4);white-space:normal;display:inline-block;margin-right: 5px;" <span *ngFor="let entity of note.entities_restriction" class="label label-default" style="background-color:rgba(0,0,0,0.4);white-space:normal;display:inline-block;margin-right: 5px;"
title="Entité restreinte"><i class="fa fa-sitemap"></i> {{entity}}</span> title="Entité restreinte"><i class="fa fa-sitemap"></i> {{entity.short_label}}</span>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
</ng-container> </ng-container>
\ 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