Page 1 of 1

getPermissions not matching owner

PostPosted: Sat Jul 02, 2011 6:36 pm
by rleyba
Hi Steve,

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.

Re: getPermissions not matching owner

PostPosted: Sun Jul 03, 2011 1:34 pm
by shannah
I am trying to establish where the value of 'user_id' is getting picked up from. Is this a system field?


No. In that example, $user is a Dataface_Record object representing a row from the users table (as specified in the [_auth] section of your conf.ini file). It assumes that that table contains a field named 'user_id'.

_Steve

Re: getPermissions not matching owner

PostPosted: Mon Jul 04, 2011 7:18 am
by rleyba
Yes, perfect....did some re-coding and application is working properly now.
Thanks for all the help.