Current Record: viewable_editable_fields #180

If we want only some users to edit a field and some other users only to view that field, then we need to define a fieldX__permissions() meth...

Current Record: viewable_editable_fields #180

If we want only some users to edit a field and some other users only to view that field, then we need to define a fieldX__permissions() meth...

How to make a field editable for some users and only viewable for some other users

[Permalink]

If we want only some users to edit a field and some other users only to view that field, then we need to define a fieldX__permissions() method for that field which gives desired permissions for specific users.

One solution is as below.

permissions.ini

[Field Viewer]
view=1
edit=0
new=0

[Field Editor extends Field Viewer]
new=1
edit=1

TableX.php (Delegate class of TableX)

function fieldX__permissions(&$record) {
    $user=&Dataface_AuthenticationTool::getInstance()->getLoggedInUser();
    
    if($user) {
        if($user->val('usernameField')=="UserX")
            $role='Field Viewer';
        else if($user->val('usernameField')=="UserY")
            $role='Field Editor';                

            return Dataface_PermissionsTool::getRolePermissions($role);
    }
        
    return Dataface_PermissionsTool::NO_ACCESS();
}
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2024 All rights reserved