Announcement

Collapse
No announcement yet.

Get "assignedUserID" from entity

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get "assignedUserID" from entity

    Hello,

    we've got a ACL function "checkAccessToPrivateEvents" which works very well. But we've got also an SelectManagers function "access" which doesn't allow "Entity $entity", so we can't call the "checkAccessToPrivateEvents" function from here. Is there another way to get the "assignedUserID" for the "checkAccessToPrivateEvents" function, so we haven't pass the entity by function?

    Besuch.php in custom\Espo\Custom\Acl ==> WORKS

    PHP Code:
    <?php
    namespace Espo\Custom\Acl;

    use 
    \Espo\Entities\User as EntityUser;
    use 
    \Espo\ORM\Entity;
    use 
    \Espo\Core\Exceptions\Forbidden;

    class 
    Besuch extends \Espo\Core\Acl\Base {

        public function 
    checkEntityRead(EntityUser $userEntity $entity) {
        
        if (
    $entity->get('privateEvent')) {
          return 
    $this->checkAccessToPrivateEvents($user);
        }
        return 
    true;
      }

      public function 
    checkAccessToPrivateEvents(EntityUser $userEntity $entity) {
            if(
    $user->isAdmin()) {
              return 
    true;
            }
            
           
    $owner $entity->get('assignedUserID');
            
            if (
    $user->id === $owner) {
              return 
    true;
            }
            
            return 
    false;
      }
    }

    Besuch.php in custom\Espo\Custom\ServiceManagers ==> DOESN'T WORK

    PHP Code:
    <?php
    namespace Espo\Custom\SelectManagers;

    use 
    \Espo\ORM\Entity;

    class 
    Besuch extends \Espo\Core\SelectManagers\Base
    {
        protected function 
    access(Entity $entity, &$result) {
            
    $user $this->user;

            if (
    $this->getSeed()->hasAttribute('privateEvent')) {  
              if(! 
    $this->getAclManager()->getImplementation('Besuch')->checkAccessToPrivateEvents($user$entity)) {
                
    $result['whereClause'][] = array(
                    
    'privateEvent' => false
                
    );
              }
            }
            
    parent::access($entity$result);
        }
    }

  • #2
    The error message is:

    [2018-06-19 12:17:23] Espo.WARNING: E_WARNING: Declaration of Espo\Custom\SelectManagers\Besuch::access(Espo\ORM \Entity $entity, &$result) should be compatible with Espo\Core\SelectManagers\Base::access(&$result) {"code":2,"message":"Declaration of Espo\\Custom\\SelectManagers\\Besuch::access(Espo\ \ORM\\Entity $entity, &$result) should be compatible with Espo\\Core\\SelectManagers\\Base::access(&$result) ","file":"/var/www/vhosts/XXXXXXXXXX/httpdocs/custom/Espo/Custom/SelectManagers/Besuch.php","line":7,"context":{"file":"/var/www/vhosts/XXXXXXXXXX/httpdocs/custom/Espo/Custom/SelectManagers/Besuch.php"}} []

    Comment


    • #3


      this method has only one parameter

      Comment


      • #4
        Yes, I know, but how can I get the assignedUserID within the "checkAccessToPrivateEvents" function if I can't call the function with the parameter from the access function?

        Comment


        • #5

          Comment


          • #6
            Thanks Tanya, this works! :-)

            Comment

            Working...
            X