@@ -23,6 +23,7 @@ class RelationService {
2323 private ViewMapper $ viewMapper ;
2424 private Row2Mapper $ row2Mapper ;
2525 private ColumnService $ columnService ;
26+ private PermissionsService $ permissionsService ;
2627 private LoggerInterface $ logger ;
2728 private ?string $ userId ;
2829
@@ -34,13 +35,15 @@ public function __construct(
3435 ViewMapper $ viewMapper ,
3536 Row2Mapper $ row2Mapper ,
3637 ColumnService $ columnService ,
38+ PermissionsService $ permissionsService ,
3739 LoggerInterface $ logger ,
3840 ?string $ userId ,
3941 ) {
4042 $ this ->columnMapper = $ columnMapper ;
4143 $ this ->viewMapper = $ viewMapper ;
4244 $ this ->row2Mapper = $ row2Mapper ;
4345 $ this ->columnService = $ columnService ;
46+ $ this ->permissionsService = $ permissionsService ;
4447 $ this ->logger = $ logger ;
4548 $ this ->userId = $ userId ;
4649 }
@@ -171,16 +174,23 @@ private function getRelationDataForTarget(string $target, Column $column): array
171174 }
172175
173176 $ settings = $ column ->getCustomSettingsArray ();
174- if (empty ($ settings [' relationType ' ]) || empty ($ settings [' targetId ' ]) || empty ($ settings [' labelColumn ' ])) {
177+ if (empty ($ settings [Column:: RELATION_TYPE ]) || empty ($ settings [Column:: RELATION_TARGET_ID ]) || empty ($ settings [Column:: RELATION_LABEL_COLUMN ])) {
175178 $ this ->cacheRelationData [$ cacheKey ] = [];
176179 return [];
177180 }
178181
179- $ isView = $ settings ['relationType ' ] === 'view ' ;
180- $ targetId = $ settings ['targetId ' ] ?? null ;
182+ if (!$ this ->permissionsService ->canReadRowsByElementId ($ settings [Column::RELATION_TARGET_ID ], $ settings [Column::RELATION_TYPE ], $ this ->userId )) {
183+ $ e = new \Exception ('Row not found. ' );
184+ $ this ->logger ->error ($ e ->getMessage (), ['exception ' => $ e ]);
185+ throw new NotFoundError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
186+ }
187+
188+
189+ $ isView = $ settings [Column::RELATION_TYPE ] === 'view ' ;
190+ $ targetId = $ settings [Column::RELATION_TARGET_ID ] ?? null ;
181191
182192 try {
183- $ targetColumn = $ this ->columnMapper ->find ($ settings [' labelColumn ' ]);
193+ $ targetColumn = $ this ->columnMapper ->find ($ settings [Column:: RELATION_LABEL_COLUMN ]);
184194 if ($ isView ) {
185195 $ view = $ this ->viewMapper ->find ($ targetId );
186196 $ rows = $ this ->row2Mapper ->findAll (
@@ -212,7 +222,7 @@ private function getRelationDataForTarget(string $target, Column $column): array
212222 foreach ($ rows as $ row ) {
213223 $ data = $ row ->getData ();
214224 $ displayFieldData = array_filter ($ data , function ($ item ) use ($ settings ) {
215- return $ item ['columnId ' ] === (int )$ settings [' labelColumn ' ];
225+ return $ item ['columnId ' ] === (int )$ settings [Column:: RELATION_LABEL_COLUMN ];
216226 });
217227 $ value = reset ($ displayFieldData )['value ' ] ?? null ;
218228
0 commit comments