Current Record: How_to_granulate_permissions_on_each_field #63

How to granulate permissions on each field To reach this aim, there is the method fieldname__permissions to place into the delegate class o...

Current Record: How_to_granulate_permissions_on_each_field #63

How to granulate permissions on each field To reach this aim, there is the method fieldname__permissions to place into the delegate class o...

How_to_granulate_permissions_on_each_field

[Permalink]

How to granulate permissions on each field

To reach this aim, there is the method fieldname__permissions to place into the delegate class of the table.

Getting the role

First it is necessary to know the user's role. For this, the method getUser() is added in the class :

function getUser(&$record){
  $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
return $user;
}

Setting up the permissions for each field

Next, the permissions are built for each column or field where they are needed, like in this example where the method name is formed with the field name, followed by 2 underscores then by permissions :

function fieldname__permissions(&$record){

$the_user =$this->getUser($record);
$user=$the_user->val('identifiant');
if ( !$user) return Dataface_PermissionsTool::NO_ACCESS();

    if ( $user=='demande' ){
        return Dataface_PermissionsTool::ALL();
    } elseif ($user=='admin'){
 return Dataface_PermissionsTool::ALL();
}
else {
        return Dataface_PermissionsTool::READ_ONLY();
    }
}

Also See

blog comments powered by Disqus
Powered by Xataface
(c) 2005-2024 All rights reserved