Announcement

Collapse
No announcement yet.

Extend getScopeForbiddenAttributeList logic

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

  • Extend getScopeForbiddenAttributeList logic

    Hello,

    In our project, we are currently facing a challenge where we need to modify the getScopeForbiddenAttributeList function in AclManager. We require access to the Entity within this function to implement custom logic based on the Entity ID.

    We have a custom binding for AclManager and Acl as follows:

    PHP Code:
    $binder
    ->bindImplementation(
    'Espo\\Core\\AclManager',
    'Espo\\Custom\\AclManager'
    );

    $binder
    ->bindImplementation(
    'Espo\\Core\\Acl',
    'Espo\\Custom\\Acl'
    ); 

    Our issue lies in overriding the prepareEntityForOutput function in Espo\\Core\\Record\\Service (link to function).

    We attempted to create a binding for it as well, but it did not work. Could someone please assist us with potential solutions?

  • #2
    AclManager is a service, hence you need to either bind another custom service or specify a custom loader for the aclManager service.




    containerServices.json:


    Code:
    {
        "aclManager": {
            "loaderClassName": "Espo\\Modules\\MyModule\\Core\\AclManagerLoader"
        }
    }

    Comment


    • yuri
      yuri commented
      Editing a comment
      This loader, should return your extended AclManager instance. In the loader, you can instantiate it using $this->injectableFactory->create($yourClass);

    • tomasrotek
      tomasrotek commented
      Editing a comment
      I am not sure if I understand this correctly. My issue is that I need to override the prepareEntityForOutput function in Espo\\Core\\Record\\Service, so that it can pass the Entity object into Acl, and from there, into AclManager.

      I successfully used the binder to override the necessary functions in Acl and AclManager, but I am unsure how to override the function in Espo\\Core\\Record\\Service.

  • #3
    It's not possible to override the Record\Service method. You can use "recordDefs > outputFilterClassNameList" as it's stated in the method docs.

    If you need it for every entity type in the system, you can use an additional builder for metadata. You can modify the metadata by adding definitions for all entity types. https://docs.espocrm.com/development...rclassnamelist

    Comment


    • tomasrotek
      tomasrotek commented
      Editing a comment
      The reason we want to do this is to add some additional logic in the AclManager function getScopeForbiddenAttributeList, based on the Entity ID. Specifically, we need to mark certain fields as forbidden depending on the Entity ID.

      Is this something that is not possible to achieve?

  • #4
    I do not recommend doing it. Modifying method signatures is breaking the application entirely.

    Comment


    • tomasrotek
      tomasrotek commented
      Editing a comment
      Thank you for your input. I understand that modifying method signatures can cause issues, but we still need to find a solution to our specific requirement. Our goal is to apply additional logic in the AclManager based on the Entity ID to restrict certain fields.

      Is there a way to achieve this, even if it's not ideal or recommended? We need to explore all options before making a final decision. Any guidance on possible workarounds or alternatives would be greatly appreciated.

    • yuri
      yuri commented
      Editing a comment
      Hello, In our project, we are currently facing a challenge where we need to modify the getScopeForbiddenAttributeList function in AclManager. We require access to the Entity within this function to implement custom logic based on the Entity ID. We have a custom binding for AclManager and Acl as follows: $binder


      recordDefs > outputFilterClassNameList

      + additionalBuilderClassNameList if you need it for all entity types.
Working...
X