Override Visibility Strategy while initializing Sugar Bean

Hello Folks,

I wanted to override visibility strategy defined in module bean class definition while initializing that bean.

For eg: I have a module called Test and I have defined following visibility in bean class.

class Test extends SugarBean

{

    public function __construct()

    {

         $this->addVisibilityStrategy("OwnerVisibility");

         parent::__construct();

    }

}

Now, while initializing bean, I wanted to override this strategy in some scenarios.

$testBean = BeanFactory::newBean("Test");

$testBean->addVisibilityStrategy("OwnerOrAdminVisibility");

But the above line is not working. I am not sure how to override the visibility already defined in bean definition.

Any help or idea would be greatly appreciated.

Regards.

Hats

Parents
  • Hi hats 

    I believe the best way is to create a custom visibility which adds either OwnerVisibility or OwnerOrAdminVisibility depends on $this->bean/user attributes.

    We have done that very frequently without big deal.

    Kind regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi hats,

    First of all, Admin users do not have visibility applied to them. My recommendation for that specific scenario would be to use Admin users only for Administrative actions and not for normal users.

    Non-admin users can leverage the custom visibility rules you produce. Remember that whatever filtering you apply to the database layer, you also have to apply it to the search layer.

    A good example from our last uncon can be found here: uncon/custom_visibility at 2016 · sugarcrm/uncon · GitHub 

    Custom visibilities are applied to objects through extended vardefs as per the example as well.

    Also remember that the visibility layer applies to single record loads and most importantly to listviews with real-time queries. Be really mindful at the performance impact a non-optimised query might have. Make sure to profile the queries and the application correctly with production like large data sets, before going live with your changes.

    Hope my pointers help you with your objective

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

Reply
  • Hi hats,

    First of all, Admin users do not have visibility applied to them. My recommendation for that specific scenario would be to use Admin users only for Administrative actions and not for normal users.

    Non-admin users can leverage the custom visibility rules you produce. Remember that whatever filtering you apply to the database layer, you also have to apply it to the search layer.

    A good example from our last uncon can be found here: uncon/custom_visibility at 2016 · sugarcrm/uncon · GitHub 

    Custom visibilities are applied to objects through extended vardefs as per the example as well.

    Also remember that the visibility layer applies to single record loads and most importantly to listviews with real-time queries. Be really mindful at the performance impact a non-optimised query might have. Make sure to profile the queries and the application correctly with production like large data sets, before going live with your changes.

    Hope my pointers help you with your objective

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

Children
No Data