AnsweredAssumed Answered

Restrict access for regular users (not Admins) to edit some fields at User Profile

Question asked by Oleg Sh on May 16, 2017
Latest reply on May 18, 2017 by Oleg Sh

I need to restrict access for regular users (not Admins) to edit some fields at User Profile.

For example, I do not want the regular user to edit the field 'graduation_date_c' in his profile. But it should be possible for admins to edit this field via User Management.

 

I created custom formula function

<?php
require_once("include/Expressions/Expression/Boolean/BooleanExpression.php");

class AdminExpression extends BooleanExpression {

    function evaluate() {
        global $current_user;

        if($current_user->is_admin){
            return AbstractExpression::$FALSE;
        } else {
            return AbstractExpression::$TRUE;
        }
    }

    static function getJSEvaluate() {
        return <<<EOQ
            var isAdmin = SUGAR.App.user.get('type') == 'admin';
           
            if(isAdmin){
                return SUGAR.expressions.Expression.FALSE;
            } else {
                return SUGAR.expressions.Expression.TRUE;
            }
EOQ;
    }

    static function getOperationName() {
        return "admin";
    }

    static function getParamCount() {
        return 0;
    }

    function toString() {
        return "admin";
    }
}

 

and use it in the ReadOnly Dependency Actions

<?php

$dependencies['Users']['readonly_fields'] = array(
    'hooks' => array("edit"),
    'trigger' => 'true',
    'onload' => true,
    'actions' => array(
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'graduation_date_c',
                'value' => 'admin'
            ),
        ),
    ),
);

But it does not work...
Fragment  of the manifest file:

'copy' => array(
    array(
        'from' => '<basepath>/custom_name_read_only.php',
        'to' => 'custom/Extension/modules/Users/Ext/Dependencies/custom_name_read_only.php',
    ),
    array(
        'from' => '<basepath>/AdminExpression.php',
        'to' => 'custom/include/Expressions/Expression/Boolean/AdminExpression.php',
    ),

What is wrong with it?

Is it possible?!

Outcomes