<?xml version="1.0"?>
<record><wiki id="wiki?page_id=63">
	<page_name>How_to_granulate_permissions_on_each_field</page_name>
	<page_id>63</page_id>
	<page_title>How_to_granulate_permissions_on_each_field</page_title>
	<content>==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&apos;s role. For this, the method getUser() is added in the class :
&lt;code&gt;function getUser(&amp;$record){
  $auth =&amp; Dataface_AuthenticationTool::getInstance();
    $user =&amp; $auth-&gt;getLoggedInUser();
return $user;
}&lt;/code&gt;


===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 &apos;&apos;permissions&apos;&apos; :

&lt;code&gt;function fieldname__permissions(&amp;$record){

$the_user =$this-&gt;getUser($record);
$user=$the_user-&gt;val(&apos;identifiant&apos;);
if ( !$user) return Dataface_PermissionsTool::NO_ACCESS();

    if ( $user==&apos;demande&apos; ){
        return Dataface_PermissionsTool::ALL();
    } elseif ($user==&apos;admin&apos;){
 return Dataface_PermissionsTool::ALL();
}
else {
        return Dataface_PermissionsTool::READ_ONLY();
    }
}&lt;/code&gt;


=== Also See ===

* [[viewable_editable_fields]] - How to make a field editable for some users and only viewable for some other users  
* [[no_access_text]] - Replace the default NO ACCESS permission text with another text.
* [[__field__permissions]] - Returns the default permissions for a field of a given record.
* [[Delegate_class_methods#toc5|Permissions]] - other Delegate class methods</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki></record>