Retrieve list of records accessible for a user in back-end

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • a.slyzhko
    Member
    • Oct 2023
    • 90

    Retrieve list of records accessible for a user in back-end

    I write custom php code and I need to know how to get all records of certain entity accassible for a current user? I injected User, EntityManager and Acl dependencies into my class.
    I know, that I can retrieve all not deleted records and iterate over them and check if some of them are accessible, but is there a faster way?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    PHP Code:
    $query = $this->selectBuilderFactory
        ->create()
        //->forUser($user) // possible to apply for any user, the current user will be applied by default
        ->from($entityType)
        ->withStrictAccessControl() // applies access control filter so that only records visible by the user will be returned
        ->build();
    
    $collection = $this->entityManager
        ->getRDBRepository($entityType)
        ->clone($query)
        ->where([]) // some additional where clause
        ->find(); 
    
    Example: https://github.com/espocrm/espocrm/b...inder.php#L133
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...