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
- 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.
- Permissions - other Delegate class methods
var disqus_identifier = ‘xataface.com/wiki/How_to_granulate_permissions_on_each_field’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘http://xataface.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })(); blog comments powered by Disqus
//<![CDATA[ (function() { var links = document.getElementsByTagName(‘a’); var query = ‘?’; for(var i = 0; i < links.length; i++) { if(links[i].href.indexOf(‘#disqus_thread’) >= 0) { query += ‘url’ + i + ‘=’ + encodeURIComponent(links[i].href) + ‘&’; } } document.write(‘