Certain tables visible to certain users?

A place to discuss development of the Xataface core.

Certain tables visible to certain users?

Postby rlevin » Thu Apr 14, 2011 9:04 am

I can set the permissions like view, edit, delete etc, but how do I set permissions to make a specific table available to a user depending on the user logged in? When the user logs in how do I set that specific table as the default table? What about the table tabs, can I disable the table tabs the user has no access to?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Thu Apr 14, 2011 9:35 am

If you're using 1.3+ you can use the getNavItem() and isNavItemSelected() application delegate class methods.
http://xataface.com/wiki/getNavItem

If you're on a previous version, you may want to look at this discussion for some strategies:
viewtopic.php?t=5201#25312

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Certain tables visible to certain users?

Postby rlevin » Thu Apr 14, 2011 9:50 am

I read through the link but it describes the case, admin vs regular user rights. In my case, I have 3 regular users but I want them to only see tables they are allowed to see. User A can see Table A but not Table B. User B can see Table B but not Table A. In the link it uses the isadmin() function, what would I need to use here to distinguish User A from B?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Thu Apr 14, 2011 2:07 pm

This is a permissions issue. You need to define a permissions strategy for your system. The isAdmin() is a custom function made for the particular application that was being developed. Different applications will have different criteria for who is an admin and who is not an admin. If you define your permissions then you can use those permissions in either of these strategies in order to decide who sees which tabs.

For information on permissions read the section in the getting started tutorial, and there are many documents in the wiki regarding setting up permissions.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Certain tables visible to certain users?

Postby rlevin » Tue Apr 19, 2011 10:25 am

I looked at some alternatives and come across the unset method.

I tried this out but it didn't quite work out for me.
Code: Select all
function beforeHandleRequest() {
        $user =& Dataface_AuthenticationTool::getInstance()->getLoggedInUser()
             if ( $user and $user->val('role') == 'UserARole'
            {
         $app =& Dataface_Application::getInstance();
       
        unset($app->_conf['_tables']['TableB']);
         }
         else
        {
        //display all tables
        $query =& Dataface_Application::getInstance()->getQuery();
        }
        
    }


What would be the drawbacks of using unset() rather than getnavitem()?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Tue Apr 19, 2011 10:29 am

No drawback. Just make sure you're also disallowing access to the table using permissions. unsetting an element of the conf->_tables array will only remove the navigation tab to the table. If they have permission to access the table then they will still be able to enter the URL to the table directly.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Certain tables visible to certain users?

Postby rlevin » Thu Apr 21, 2011 7:40 am

Still having problems. Here's my code in the class delegate file

Code: Select all
    function isValid(){
    $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if ( $user and $user->val('role') == 'UserARole' ) return true;
    return false;
}
      function isLoggedIn(){
      $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if(isset($user)) return true;
    return false;
      }
      
    function init(&$table) { 
        if (isLoggedIn()){        
            if (isValid()){
               $app =& Dataface_Application::getInstance();
               unset($app->_conf['_tables']['TableB']);
            }
         }
     }


Taking off the isValid() and isLoggedIn() methods from the init() function works, but returns the same results for everyone. My problem is in those 2 functions.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Thu Apr 21, 2011 8:32 am

If isValid and isLoggedIn are defined as methods of the delegate class then they'll need to be called like:
Code: Select all
$this->isValid() and $this->isLoggedIn() respectively


Also are you showing the whole delegate class file here or only a snippet? I don't see the class definition here, just some functions.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Certain tables visible to certain users?

Postby rlevin » Thu Apr 21, 2011 8:49 am

Here's the whole class:

Code: Select all
<?PHP
class tables_TableA{
   
    function isValid(){
    $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if ( $user and $user->val('role') == 'UserARole' ) return true;
    return false;
}

      function isLoggedIn()
      {
      $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if(isset($user)) return true;
    return false;
      }
      
    function init(&$table)
     {         
       if ($this->isLoggedIn())
                {
          if($this->isValid())
                  {
               $app =& Dataface_Application::getInstance();
               unset($app->_conf['_tables']['TableB']);
            }      
         }      
     }                 
}
?>


I made the changes to isLoggedIn() and isValid() as you mentioned but I get the same results.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Thu Apr 21, 2011 9:07 am

What are those results? Are you getting an error message of some kind?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Certain tables visible to certain users?

Postby rlevin » Thu Apr 21, 2011 10:08 am

I found the problem. It was a simple syntax error. Thank you!

Say I wanted to enable the unset tables, whats the vice versa method of unset()?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Certain tables visible to certain users?

Postby shannah » Thu Apr 21, 2011 3:08 pm

Opposite of unset() is to just set the value. i.e.:

Code: Select all
$app->_conf['_tables']['foo'] = 'Foo';
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 1 guest

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