<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://sugarclub.sugarcrm.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Is extending SugarACLStrategy working properly in Sugar 11?</title><link>https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/5380/is-extending-sugaraclstrategy-working-properly-in-sugar-11</link><description>: 
 In the past, I have been able to follow this guide https://enricosimonetti.com/powerful-customisations-with-sugars-acl/ . I am trying to make individual rows in a module ReadOnly based upon the values of fields in a Bean. It doesn&amp;#39;t appear that the</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Is extending SugarACLStrategy working properly in Sugar 11?</title><link>https://sugarclub.sugarcrm.com/thread/25669?ContentTypeID=1</link><pubDate>Thu, 13 Jan 2022 22:59:10 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:e7526b94-6158-4be2-94db-8d9550a40c5e</guid><dc:creator>Enrico Simonetti</dc:creator><description>&lt;p&gt;Thanks&amp;nbsp;&lt;a href="/members/francescas"&gt;Francesca Shiekh&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;This is quite cool!&amp;nbsp;I keep seeing the same code in more and more instances I touch, which gives me a warm and fuzzy feeling&amp;nbsp;&lt;span class="emoticon" data-url="https://sugarclub.sugarcrm.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Yes&amp;nbsp;&lt;a href="/members/jeffbickart21808"&gt;Jeff Bickart&lt;/a&gt;&amp;nbsp;it still works today. But.. acl can be finicky, it is easy to &amp;quot;mess it up&amp;quot; or create a performance nightmare.&lt;/p&gt;
&lt;p&gt;There are some parts of ACL that are cached when a user logs in (eg: module level permissions), and some part that happen for every piece of data/field. If you leverage the correct parts of the acl, you should be able to achieve what you are asking.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is extending SugarACLStrategy working properly in Sugar 11?</title><link>https://sugarclub.sugarcrm.com/thread/25668?ContentTypeID=1</link><pubDate>Thu, 13 Jan 2022 21:48:04 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:304c9b5a-e6df-4961-9c03-1ac11186fad8</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;FWIW I am using&amp;nbsp;an ACLLock based on that guide by&amp;nbsp;&amp;nbsp;&lt;a href="/members/enricosimonetti"&gt;Enrico Simonetti&lt;/a&gt;&amp;nbsp;and it still works in 11.0.2 Pro&lt;br /&gt;In my implementation I make records read only for regular users (Admin can still edit) in a custom module based on a date field.&lt;/p&gt;
&lt;p&gt;FrancescaS&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="php"&gt;&amp;lt;?php
class SugarACLLockSalesGoals extends SugarACLStrategy
{
    // allowed user ids
    protected $user_ids_to_allow = array(
    );
    // denied actions
    protected $denied_actions = array(
        &amp;#39;edit&amp;#39;,
        &amp;#39;delete&amp;#39;,
        &amp;#39;massupdate&amp;#39;,
        &amp;#39;import&amp;#39;,
    );
    // our custom method to check permissions
    protected function _canUserWrite($context)
    {
        $date = new DateTime(&amp;quot;now&amp;quot;,new DateTimeZone(&amp;#39;UTC&amp;#39;)); //now in UTC
        $today = $date-&amp;gt;format(&amp;#39;Y-m-d H:i:s&amp;#39;);
        // retrieve user from context
        $user = $this-&amp;gt;getCurrentUser($context);
        if($user-&amp;gt;isAdmin() || in_array($user-&amp;gt;id, $this-&amp;gt;user_ids_to_allow)) {
            return true;
        } else {
            // check additional beans conditions here
            // is there a bean?
            if(!empty($context[&amp;#39;bean&amp;#39;]) &amp;amp;&amp;amp; is_object($context[&amp;#39;bean&amp;#39;]) &amp;amp;&amp;amp; !empty($context[&amp;#39;bean&amp;#39;]-&amp;gt;id)) {
                // do we have a mapped known object instance?
                if($context[&amp;#39;bean&amp;#39;] instanceof SugarBean &amp;amp;&amp;amp; !empty($context[&amp;#39;bean&amp;#39;]-&amp;gt;module_dir) &amp;amp;&amp;amp; $context[&amp;#39;bean&amp;#39;]-&amp;gt;module_dir == &amp;#39;sgoal_SalesGoals&amp;#39;) {
                    // retrieve the full bean as in some occastions (like listviews), not all fields are available on the context
                    $bean = BeanFactory::getBean($context[&amp;#39;bean&amp;#39;]-&amp;gt;module_dir, $context[&amp;#39;bean&amp;#39;]-&amp;gt;id);

                    if($bean-&amp;gt;goal_end_date_c &amp;gt;= $today){
                      //if the goal end date is in the future, proceed and give permission
                      return true;
                    }
                    // default do not allow once here
                    return false;
                }
            }
            return true;
        }
    }
    // runtime access check
    public function checkAccess($module, $view, $context)
    {
        $view = SugarACLStrategy::fixUpActionName($view);
        // if it is not a blocked action, or there is no bean, allow it
        if(!in_array($view, $this-&amp;gt;denied_actions) || !isset($context[&amp;#39;bean&amp;#39;])) {
            return true;
        }
        // can user write?
        if($this-&amp;gt;_canUserWrite($context)) return true;
        // everyone else for everything else is denied
        return false;
    }
    // mostly for front-end access checks (cached on the application, per user)
    public function getUserAccess($module, $access_list = array(), $context = array())
    {
        // retrieve original ACL
        $acl = parent::getUserAccess($module, $access_list, $context);
        // if user can&amp;#39;t write
        if(!$this-&amp;gt;_canUserWrite($context)) {
            // override access, disable access where required if not admin and not special user
            foreach($acl as $access =&amp;gt; $value) {
                if(in_array($access, $this-&amp;gt;denied_actions)) {
                    $acl[$access] = 0;
                }
            }
        }
        // return modified acl  
        return $acl;
    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>