Account Module Modification.

All,

I've written code to allow edits certain edits to customer's info  in the accounts module based on admin or non-admin. I'm using Sugar Sell (Cloud) edition. Is there a way to modify/implement this without creating a new module? Most of my research says go to the root directory but I don't think that's necessary. 

Thanks in advance. 

Parents
  • Can you please restate your use cases?

    It sounds like you can use roles to restrict which fields are editable by users

  • Thanks for reaching out Jeff.

    I've added a check box in the other account tab in customer's account. The problem is it's not allowing non-admin users to edit/check the box. My understanding is that I can do this inside the account module. I'm not sure where to place the below code to update the module. 

    <?php
    // Prevent direct access to this file
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once('data/SugarACLStrategy.php');

    class SugarACLAccountTypeReadOnly extends SugarACLStrategy {

    protected $user_ids_to_allow = [];

    protected $allowed_fields = [
    'furniture_terms_and_conditions_signed_c',
    'Office Phone',

    ];

    protected function _canUserWrite($context) {
    global $current_user;

    if ($current_user->isAdmin() || in_array($current_user->id, $this->user_ids_to_allow)) {
    return true;
    }

    if (isset($context['action']) && $context['action'] == 'edit' && isset($context['field']) && in_array($context['field'], $this->allowed_fields)) {
    return true;
    }

    return false;
    }

    public function checkAccess($module, $view, $context) {
    if (!isset($context['bean'])) {
    return true;
    }

    $view = SugarACLStrategy::fixUpActionName($view);
    if ($this->_canUserWrite($context)) {
    return true;
    }

    return false;
    }

    public function getUserAccess($module, $access_list = array(), $context = array()) {
    $acl = parent::getUserAccess($module, $access_list, $context);

    if (!$this->_canUserWrite($context)) {
    foreach ($acl as $access => &$value) {
    $value = 0;
    }
    }

    return $acl;
    }
    }

Reply
  • Thanks for reaching out Jeff.

    I've added a check box in the other account tab in customer's account. The problem is it's not allowing non-admin users to edit/check the box. My understanding is that I can do this inside the account module. I'm not sure where to place the below code to update the module. 

    <?php
    // Prevent direct access to this file
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once('data/SugarACLStrategy.php');

    class SugarACLAccountTypeReadOnly extends SugarACLStrategy {

    protected $user_ids_to_allow = [];

    protected $allowed_fields = [
    'furniture_terms_and_conditions_signed_c',
    'Office Phone',

    ];

    protected function _canUserWrite($context) {
    global $current_user;

    if ($current_user->isAdmin() || in_array($current_user->id, $this->user_ids_to_allow)) {
    return true;
    }

    if (isset($context['action']) && $context['action'] == 'edit' && isset($context['field']) && in_array($context['field'], $this->allowed_fields)) {
    return true;
    }

    return false;
    }

    public function checkAccess($module, $view, $context) {
    if (!isset($context['bean'])) {
    return true;
    }

    $view = SugarACLStrategy::fixUpActionName($view);
    if ($this->_canUserWrite($context)) {
    return true;
    }

    return false;
    }

    public function getUserAccess($module, $access_list = array(), $context = array()) {
    $acl = parent::getUserAccess($module, $access_list, $context);

    if (!$this->_canUserWrite($context)) {
    foreach ($acl as $access => &$value) {
    $value = 0;
    }
    }

    return $acl;
    }
    }

Children
No Data