Announcement

Collapse
No announcement yet.

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

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

  • 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?

  • #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

    Comment

    Working...
    X