Horde_Perms_Base::getPermissions PHP Method

getPermissions() public method

Finds out what rights the given user has to this object.
public getPermissions ( mixed $permission, string $user, string $creator = null ) : mixed
$permission mixed The full permission name of the object to check the permissions of, or the Horde_Permissions object.
$user string The user to check for.
$creator string The user who created the event.
return mixed A bitmask of permissions the user has, false if there are none.
    public function getPermissions($permission, $user, $creator = null)
    {
        if (is_string($permission)) {
            try {
                $permission = $this->getPermission($permission);
            } catch (Horde_Perms_Exception $e) {
                /* Ignore not exists errors. */
                if ($this->_logger && $e->getCode() != Horde_Perms_Exception::NOT_EXIST) {
                    $this->_logger->log($e, 'DEBUG');
                }
                return false;
            }
        }
        // If this is a guest user, only check guest permissions.
        if (empty($user)) {
            return $permission->getGuestPermissions();
        }
        // Combine all other applicable permissions.
        $type = $permission->get('type');
        $composite_perm = $type == 'matrix' ? 0 : array();
        // If $creator was specified, check creator permissions.
        // If the user is the creator of the event see if there are creator
        // permissions.
        if (!is_null($creator) && strlen($user) && $user === $creator && ($perms = $permission->getCreatorPermissions()) !== null) {
            if ($type == 'matrix') {
                $composite_perm |= $perms;
            } else {
                $composite_perm[] = $perms;
            }
        }
        // Check user-level permissions.
        $userperms = $permission->getUserPermissions();
        if (isset($userperms[$user])) {
            if ($type == 'matrix') {
                $composite_perm |= $userperms[$user];
            } else {
                $composite_perm[] = $userperms[$user];
            }
        }
        // If no user permissions are found, try group permissions.
        if (isset($permission->data['groups']) && is_array($permission->data['groups']) && count($permission->data['groups'])) {
            $groups = $GLOBALS['injector']->getInstance('Horde_Group')->listGroups($user);
            foreach ($permission->data['groups'] as $group => $perms) {
                if (isset($groups[$group])) {
                    if ($type == 'matrix') {
                        $composite_perm |= $perms;
                    } else {
                        $composite_perm[] = $perms;
                    }
                }
            }
        }
        // If there are default permissions, return them.
        if (($perms = $permission->getDefaultPermissions()) !== null) {
            if ($type == 'matrix') {
                $composite_perm |= $perms;
            } else {
                $composite_perm[] = $perms;
            }
        }
        // Return composed permissions.
        if ($composite_perm) {
            return $composite_perm;
        }
        // Otherwise, deny all permissions to the object.
        return false;
    }

Usage Example

Esempio n. 1
0
File: Base.php Progetto: horde/horde
 /**
  * Finds out what rights the given user has to this object.
  *
  * @see Horde_Perms::getPermissions
  *
  * @param mixed $share  The share that should be checked for the users
  *                      permissions.
  * @param string $user  The user to check for.
  *
  * @return mixed  A bitmask of permissions, a permission value, or an array
  *                of permission values the user has, depending on the
  *                permission type and whether the permission value is
  *                ambiguous. False if there is no such permsission.
  */
 public function getPermissions($share, $user = null)
 {
     if (!$share instanceof Horde_Share_Object) {
         $share = $this->getShare($share);
     }
     return $this->_permsObject->getPermissions($share->getPermission(), $user);
 }
All Usage Examples Of Horde_Perms_Base::getPermissions