Current Record: Permissions #52

News

Current Record: Permissions #52

News

Click to minimize this section Details

News id 52
Headline Permissions
Content So I've been doing a lot of research into the permission in dataface and I think I have a pretty good understanding. <br /><br />There is a global permission setting you can set for all tables in the conf/ApplicationDelegate.php class. So you can grant a particular user to say all the tables, or block them from all tables in this class. This is accomplished through the function getPermission() in the ApplicationDelegate.php class.<br /><br /><blockquote><br />function getPermissions(&$record){<br /> $auth =& Dataface_AuthenticationTool::getInstance();<br /> $user =& $auth->getLoggedInUser(); //grabs the logged in user<br /> if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS(); //if there is no user logged in, then they should not have access to anything.<br /> $role = $user->val('role'); //grab the role of the user. the val function just returns the value of the parameter<br /> if ( !$role ) return Dataface_PermissionsTool::NO_ACCESS(); //if no role, then they should get no permissions<br /> return Dataface_PermissionsTool::getRolePermissions($role); //return the permissions of that role. <br /> }<br /></blockquote><br /><br />Now if you want to block them for specific tables, these permission settings are to be set at the delegate class table level. For example,<br /><br /><blockquote><br />$auth =& Dataface_AuthenticationTool::getInstance();<br /><br /> $user =& $auth->getLoggedInUser();<br /><br /> //if user is not set and (no record OR no memberID) and action is new<br /> //give them person to edit. Enter information into the fields<br /> if ( !$user and ( !$record || !$record->val('memberid') ) and @$_GET['-action'] == 'new' ){<br /> <br /> return Dataface_PermissionsTool::getRolePermissions('EDIT');<br /><br /> //if there is just no user then they should have no acess<br /> } else if (!$user ) {<br /><br /> return Dataface_PermissionsTool::NO_ACCESS();<br /><br /> //if there is a user, then return the role permissions of that user<br /> } else {<br /><br /> return Dataface_PermissionsTool::getRolePermissions($user->val('role'));<br /><br /> //return PEAR::raiseError('Let the app delegate class handle it', DATAFACE_E_REQUEST_NOT_HANDLED);<br /><br /> }<br /></blockquote><br /><br />And if we want even more fine grained, then we can do it was the field level. The field level is a little more tricky thou. To provide permissions for a given field, it must follow this syntax:<br /><br /><blockquote>function FIELDNAME__permissions(&$record)</blockquote><br /><br />The record represents the given record object in question (not 100% how this works...but it could mean a row in the database...but if it is a submission form is the row empty?). <br /><br />The function body could be:<br /><br /><blockquote><br />$auth =& Dataface_AuthenticationTool::getInstance();<br /><br /> $user =& $auth->getLoggedInUser();<br /><br /> if ( !$user or $user->val('role') != 'ADMIN'){<br /><br /> return Dataface_PermissionsTool::NO_ACCESS();<br /><br /> }<br /></blockquote><br /><br />Here we are getting the logged in user, and it doesn't exist, or if it does exist, but role is NOT admin, then they should have no access and thus it will not appear in the form.
Image (Empty)
Date posted Thu Apr 3 17:09:00 2008
Posted by noreply@blogger.com (Fong Chun Chan)
Status Approved
Categories Blog
Source id Fong's Blog
Source url http://fongxataface.blogspot.com/2008/04/permissions.html
Powered by Xataface
(c) 2005-2024 All rights reserved