getPermissions not matching owner

A place for users and developers of the Xataface to discuss and receive support.

getPermissions not matching owner

Postby rleyba » Sat Jul 02, 2011 6:36 pm

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.
rleyba
 
Posts: 53
Joined: Sat Dec 04, 2010 3:50 pm

Re: getPermissions not matching owner

Postby shannah » Sun Jul 03, 2011 1:34 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: getPermissions not matching owner

Postby rleyba » Mon Jul 04, 2011 7:18 am

Yes, perfect....did some re-coding and application is working properly now.
Thanks for all the help.
rleyba
 
Posts: 53
Joined: Sat Dec 04, 2010 3:50 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 16 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved