Just setting up permissions in my tables and need to setup scenario where only owners of the records can edit their own records, everyone else can just view.
I have a field in my table called owner_id which is the name a user logs in as.
I tried to get some tips from these two posts:
viewtopic.php?t=4132#27556
viewtopic.php?t=4726#23165
I am trying to establish where the value of 'user_id' is getting picked up from. Is this a system field?
In my case below, I have tried to setup the trigger to populate the record with the name of the user logged in and the getPermissions is setup to do the checks. Unfortunately what happens is no matter who is logged in, only Role2 (role REGISTERED) is being matched, and it can't match Role1 (Owner) even if the logged in user and the value of the record field in 'owner_id' matches. What might be wrong with my syntax?
What other debugging (echo) statements do you suggest I add in the 3 case statements?
- Code: Select all
function beforeInsert(&$record){
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$record->setValue('owner_id', $user->val('user_id'));
}
function getTitle(&$record){
return $record->val('ChangeNumber');
}
function titleColumn(){
return 'ChangeNumber';
}
function getPermissions(&$record){
$auth=& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( $record and $user and $record->val('owner_id') == $user->val('user_id') ){
$role = $user->val('Role');
echo "Role 1: $role";
return Dataface_PermissionsTool::getRolePermissions('OWNER');
} else if ( $auth->isLoggedIn() ){
$role = $user->val('Role');
echo "Role 2: $role";
return Dataface_PermissionsTool::getRolePermissions('REGISTERED');
} else {
# $role = $user->val('Role');
echo "Role 3";
return Dataface_PermissionsTool::getRolePermissions('READ ONLY');
}
}
}
?>
Thanks Steve.