1313
1414namespace Pimcore \Bundle \StudioBackendBundle \Element \Service ;
1515
16+ use Pimcore \Bundle \StudioBackendBundle \DataObject \Service \RelationNormalizationContext ;
1617use Pimcore \Bundle \StudioBackendBundle \Element \Schema \RelatedElementData ;
18+ use Pimcore \Bundle \StudioBackendBundle \Exception \Api \UserNotFoundException ;
19+ use Pimcore \Bundle \StudioBackendBundle \Security \Service \SecurityServiceInterface ;
1720use Pimcore \Bundle \StudioBackendBundle \Util \Trait \ElementProviderTrait ;
1821use Pimcore \Model \DataObject \Concrete ;
1922use Pimcore \Model \Document ;
2023use Pimcore \Model \Element \ElementInterface ;
24+ use Pimcore \Model \User ;
2125
2226/**
2327 * @internal
2428 */
25- final readonly class ElementDataService implements ElementDataServiceInterface
29+ readonly class ElementDataService implements ElementDataServiceInterface
2630{
2731 use ElementProviderTrait;
2832
33+ public function __construct (
34+ protected SecurityServiceInterface $ securityService ,
35+ protected RelationNormalizationContext $ normalizationContext ,
36+ ) {
37+ }
38+
2939 public function getRelatedElementData (ElementInterface $ element ): RelatedElementData
3040 {
41+ $ hasAccess = true ;
42+ $ canEdit = true ;
43+ try {
44+ $ user = $ this ->securityService ->getCurrentUser ();
45+ /** @var User $user */
46+ $ hasAccess = $ element ->isAllowed ('view ' , $ user );
47+ $ parent = $ this ->normalizationContext ->getParent ();
48+ if ($ parent !== null ) {
49+ $ canEdit = $ parent ->isAllowed ('save ' , $ user ) || $ parent ->isAllowed ('publish ' , $ user );
50+ }
51+ } catch (UserNotFoundException ) {
52+ $ hasAccess = false ;
53+ $ canEdit = false ;
54+ }
55+
3156 return new RelatedElementData (
3257 $ element ->getId (),
3358 $ this ->getElementType ($ element , true ),
3459 $ this ->getSubType ($ element ),
3560 $ element ->getRealFullPath (),
36- $ this ->getPublished ($ element )
61+ $ this ->getPublished ($ element ),
62+ $ hasAccess ,
63+ $ canEdit ,
3764 );
3865 }
3966
40- private function getSubType (ElementInterface $ element ): string
67+ protected function getSubType (ElementInterface $ element ): string
4168 {
4269 if ($ element instanceof Concrete) {
4370 return $ element ->getClassName ();
@@ -46,7 +73,7 @@ private function getSubType(ElementInterface $element): string
4673 return $ element ->getType ();
4774 }
4875
49- private function getPublished (ElementInterface $ element ): ?bool
76+ protected function getPublished (ElementInterface $ element ): ?bool
5077 {
5178 if ($ element instanceof Concrete || $ element instanceof Document) {
5279 return $ element ->getPublished ();
0 commit comments