<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>How_to_granulate_permissions_on_each_field[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D63&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Sat, 25 May 2013 05:04:55 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>How_to_granulate_permissions_on_each_field</title>
            <link>http://www.xataface.com/wiki/How_to_granulate_permissions_on_each_field</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;How_to_granulate_permissions_on_each_field&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;63&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;How_to_granulate_permissions_on_each_field&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;
&lt;h2 id=&quot;toc0&quot;&gt;How to granulate permissions on each field&lt;/h2&gt;
&lt;p&gt;To reach this aim, there is the method fieldname__permissions to place into the delegate class of the table.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Getting the role&lt;/h3&gt;
&lt;p&gt;First it is necessary to know the user's role. For this, the method getUser() is added in the class : 
&lt;pre&gt;&lt;code&gt;function getUser(&amp;amp;$record){
  $auth =&amp;amp; Dataface_AuthenticationTool::getInstance();
    $user =&amp;amp; $auth-&amp;gt;getLoggedInUser();
return $user;
}&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Setting up the permissions for each field&lt;/h3&gt;
&lt;p&gt;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 &lt;em&gt;permissions&lt;/em&gt; :&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;function fieldname__permissions(&amp;amp;$record){

$the_user =$this-&amp;gt;getUser($record);
$user=$the_user-&amp;gt;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();
    }
}&lt;/code&gt;&lt;/pre&gt;


&lt;h3 id=&quot;toc3&quot;&gt;Also See&lt;/h3&gt;
&lt;ul&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/viewable_editable_fields&quot;&gt;viewable_editable_fields&lt;/a&gt; - How to make a field editable for some users and only viewable for some other users  &lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/no_access_text&quot;&gt;no_access_text&lt;/a&gt; - Replace the default NO ACCESS permission text with another text.&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/__field__permissions&quot;&gt;__field__permissions&lt;/a&gt; - Returns the default permissions for a field of a given record.&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/Delegate_class_methods%23toc5&quot;&gt;Permissions&lt;/a&gt; - other Delegate class methods&lt;/li&gt;
&lt;/ul&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>How_to_granulate_permissions_on_each_field</author>
        </item>
    </channel>
</rss>
