How to Create a Non-Removable Custom Filter for Portal Contact List View?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jacao
    Member
    • Mar 2024
    • 39

    #1

    How to Create a Non-Removable Custom Filter for Portal Contact List View?

    Hi,

    I'd like to configure a custom filter for the Contact list view in the portal. My goal is for logged-in portal users to see only the contacts that have the isShownInPortal field set to true. This filter should be the default and users should not be able to disable or bypass it.

    I tried using the accessControlFilter option with portalAll, but without success. I’ve searched the forum and half the internet ;-) but couldn’t find any guidance. Similar issues were mentioned in the following posts, but unfortunately without a solution.

    This tutorial describes how to apply a default filter to the list of entities displayed in a modal window when updating a link field. Background Information: In our application, we have an entity "CollectionsTracker", which we use to track payments received from rental units, and that entity is linked in a many-to


    I'm trying to hide meetings from the list view when a boolean called Private is true. My understanding is I should implement an AccessControlFilter class in custom/Espo/Custom/Select/Meeting/AccessControlFilters, but it doesn't seem to be working. Here are my files: custom/Espo/Custom/Classes/Select/Meeting/AccessControlFilters


    I’d really appreciate any advice.

    Best regards,
    Jacek
    Last edited by jacao; 05-27-2025, 07:41 AM.
  • yuri
    Member
    • Mar 2014
    • 9054

    #2
    portalAll access control filter will work when read access level is set to "all" for portal users. Maybe you did some mistake
    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

    • jacao
      Member
      • Mar 2024
      • 39

      #3
      I have a custom boolean field of Contact called cHasPortalAccess (Has Portal Access) - but it could be whatever eg. eyesColor Some contacts has is set to true:

      Click image for larger version  Name:	{9F43C675-B20C-4650-A117-6BEB96C53131}.png Views:	0 Size:	27.8 KB ID:	118096

      Portal Users have access rights set to the Contact entity by Account level. Roles are apply directly with to Portal configuration:

      Click image for larger version  Name:	image.png Views:	0 Size:	12.4 KB ID:	118095

      I’d like to limit list of Contact shown for Portal Users only to the records with cHasPortalAccess = true.

      As I understand I should create two files with my Custom configuration:

      custom/Espo/Custom/Classes/Select/Contact/AccessControlFilters/isHasPortalAccess.php

      PHP Code:
      <?php

      namespace Espo\Custom\Classes\Select\Contact\AccessControlFilters;

      use 
      Espo\Core\Select\AccessControl\Filter;
      use 
      Espo\ORM\Query\SelectBuilder as QueryBuilder;

      class 
      IsHasPortalAccess implements Filter
      {
      public function 
      apply(QueryBuilder $queryBuilder): void
      {
      $queryBuilder->where(['cHasPortalAccess' => true]);
      }
      }

      custom/Espo/Custom/Resources/metadata/selectDefs/Contact.json

      Code:
      {
      "accessControlFilterClassNameMap": {
      "isHasPortalAccess": "Espo\\Custom\\Classes\\Select\\Contact\\AccessCon trolFilters\\IsHasPortalAccess"
      }
      }

      I tried with custom/Espo/Custom/Classes/Select/Contact/AccessControlFilters/isHasPortalAccess.php based on Espo\Core\Select\AccessControl\Filters\portalOnlyA ccount.php with:

      Code:
      if ($this->entityType === Contact::ENTITY_TYPE) {
      $queryBuilder->andWhere([
      'cHasPortalAccess' => true
      ]);
      }
      placed after line with: $queryBuilder->where($orGroup);


      Unfortunatelley both doesn't works for me Please help!

      Regards, Jacek
      Attached Files
      Last edited by jacao; 05-26-2025, 03:16 PM.

      Comment

      • yuri
        Member
        • Mar 2014
        • 9054

        #4
        You the 'mandatory' filter. Not 'cHasPortalAccess'. Such a key is not supported.

        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

        • jacao
          Member
          • Mar 2024
          • 39

          #5
          Okay, now I get it Thak you Yuri for direction. The mandatory filter works for all users (both: regular and portal) but if someone would like set it only for portal usres then should use portalOnlyAccount filter if rights are set to the entity by Account scope. Below working files:

          custom/Espo/Custom/Classes/Select/Contact/AccessControlFilters/PortalOnlyAccount.php
          PHP Code:
          <?php

          namespace Espo\Custom\Classes\Select\Contact\AccessControlFilters;

          use 
          Espo\Core\Select\AccessControl\Filter;
          use 
          Espo\ORM\Query\SelectBuilder as QueryBuilder;

          class 
          PortalOnlyAccount implements Filter
          {
          public function 
          apply(QueryBuilder $queryBuilder): void
          {
          $queryBuilder->where(['cHasPortalAccess' => true]);
          }
          }

          custom/Espo/Custom/Resources/metadata/selectDefs/Contact.json
          Code:
          {
          "accessControlFilterClassNameMap": {
          "portalOnlyAccount": "Espo\\Custom\\Classes\\Select\\Contact\\AccessControlFilters\\PortalOnlyAccount"
          }
          }

          Regards! Jacek
          Last edited by jacao; 05-27-2025, 10:14 AM.

          Comment

          Working...