Is Owner?

You can use the access control file (acl.txt) to give object owners access to actions as well. For example, a record in a database. If you want to use the isOwner() method, you will need to extend the Solar_Access_Adapter_File class and write your own isOwner() method. Checking for ownership varies from application to application, so Solar allows you to overload the isOwner() method to suit your own needs.

Remember, if you extend the Solar_Access_Adapter_File class, be sure to update your config so that your access control is using the correct adapter.

Your acl.txt entry might look like this:

  allow owner * Vendor_App_Example edit

This means allow the edit action to the owner of the object in question (like a record in from a database) within the Vendor_App_Example class.

You could extend the access adapter like this to use your own isOwner($content) method:

<?php
class Vendor_Access_Adapter_File extends Solar_Access_Adapter_File
{
    public function isOwner($content)
    {
        // Assume $content is the user's handle of a record in your db
        // if it matches the handle of the person logged in, they are the owner
 
        if ($content == $this->_auth->handle) {
            return true;
        }
        return false;
    }
}
?>

Then, to use this method, you can do the following:

// Assume $some_handle is the "owner" of a record in the database
 
if (Solar_Registry::get('user')->access->isAllowed(get_class($this), 'edit', $some_handle)) {
    // edit logic here
}
 
// or just do the following (assuming they made it this far)
if (Solar_Registry::get('user')->access->isOwner($some_handle)) {
    // edit logic here
}
 
manual/access/owner.txt · Last modified: 2009/07/11 22:31 by jelofson