Page 1 of 1

Having issues setting up permissions

PostPosted: Mon Dec 03, 2007 10:34 am
by shanehudg
I've got my application up and running successfully and have customized the template and now I'm ready to start setting up relationships and actions and fill the database but before I get any more sensitive information on a public website, I wanted to go ahead and get the permissions set up. (I know I'm doing things a bit out of order but I want to get the application live as soon as possible and then while real time testing, customize it in greater detail.)

Anyway, back on topic. I followed the instructions to the letter in the getting started section on permissions. When I load the site, the login comes up as it should and when I enter the correct username and password for Admin (I have double checked the settings in the user table), I get the following fatal error:
Fatal error: The role '' is not a registered role. in /home/tddatali/public_html/projects/dataface/Dataface/PermissionsTool.php on line 341


I've searched backwards from this point through all the code and I can't find what might be generating the error. I believe it may be one of two things. Either the user variable is not initialized or the call for permissions.ini is not properly retrieving the Roles permissions since I've checked that the role is defined there. Can you offer any further insight into this? I think I'm missing part of the execution path since I can not find the call for permissions.ini but I am very new to PHP and am teaching myself as I go.

Thank you for your time.
Shane

PostPosted: Mon Dec 03, 2007 5:12 pm
by shannah
Can you post your getPermissions() method?

PostPosted: Mon Dec 03, 2007 5:38 pm
by shanehudg
[quote="shannah"]Can you post your getPermissions() method?


Here it is:
Code: Select all
function getPermissions(&$record){
         $auth =& Dataface_AuthenticationTool::getInstance();
         $user =& $auth->getLoggedInUser();
         if ( !isset($user) ) return Dataface_PermissionsTool::NO_ACCESS();
             // if the user is null then nobody is logged in... no access.
             // This will force a login prompt.
         $role = $user->val('Role');
         return Dataface_PermissionsTool::getRolePermissions($role);
             // Returns all of the permissions for the user's current role.
      }

It is directly copied from the getting started tutorial.

PostPosted: Mon Dec 03, 2007 6:24 pm
by shannah
My best guess is that you have a user with a null role. The line:
Code: Select all
return Dataface_PermissionsTool::getRolePermissions($role);


tries to return the permissions for the current user's role, but if this role is empty, then it will be trying to get permissions for the '' role.

Workaround.

1. Handle the case where the user has no role.
2. Make sure that users always have a role assigned.

-Steve

PostPosted: Tue Dec 04, 2007 4:46 pm
by shanehudg
[quote="shannah"]My best guess is that you have a user with a null role. The line:
Code: Select all
return Dataface_PermissionsTool::getRolePermissions($role);


tries to return the permissions for the current user's role, but if this role is empty, then it will be trying to get permissions for the '' role.

Workaround.

1. Handle the case where the user has no role.
2. Make sure that users always have a role assigned.

-Steve



I've double checked the role assignments for the users (I only have two set up as a test right now: admin and guest) and both have roles assigned that are all uppercase and properly spelled. I can't find why it would be returning the current user's role as NULL. Any suggestions? I did notice that application delegate class and the permissionstool.php both have a function named getPermissions and they are different. Since these two files are closely related around the error event, could it be possible that the wrong function is being called by mistake?

PostPosted: Tue Dec 04, 2007 5:00 pm
by shannah
Have you tried adding some debugging code to see which role is causing the problems.
e.g.
Code: Select all
...
$role = $user->val('Role');
echo "Role: $role";
return Dataface_PermissionsTool::getRolePermissions($role);


Another thing that could confuse is that column names are case sensitive. If your field name is 'role' then you should be doing $user->val('role') rather than $user->val('Role'), etc...

-Steve

PostPosted: Tue Dec 04, 2007 6:47 pm
by shanehudg
Ok, I feel like an idiot now. I didn't think about the case sensitivity of the columns. That's exactly what the problem was. Thank you for your help. :)