public function hasCredential($credential, $useAnd = true)
 {
     if (!$this->getPhpbbUser()) {
         return false;
     }
     return parent::hasCredential($credential, $useAnd);
 }
 public function hasCredential($credential, $useAnd = true)
 {
     if (!$this->getGuardUser()) {
         return false;
     }
     if ($this->getGuardUser()->getIsSuperAdmin()) {
         return true;
     }
     return parent::hasCredential($credential, $useAnd);
 }
示例#3
0
 /**
  * Returns whether or not the user has the given credential.
  *
  * @param string $credential The credential name
  * @param boolean $useAnd Whether or not to use an AND condition
  * @return boolean
  */
 public function hasCredential($credential, $useAnd = true)
 {
     if (empty($credential)) {
         return true;
     }
     if ($this->isSuperAdmin) {
         return true;
     }
     return parent::hasCredential($credential, $useAnd);
 }
示例#4
0
 /**
  * Returns whether or not the user has the given credential.
  *
  * @param string $credential The credential name
  * @param boolean $useAnd Whether or not to use an AND condition
  * @return boolean
  */
 public function hasCredential($credential, $useAnd = true)
 {
     if (empty($credential)) {
         return true;
     }
     if (!$this->getGuardUser()) {
         return false;
     }
     return parent::hasCredential($credential, $useAnd);
 }
 /**
  * Returns whether or not the user has the given credential.
  *
  * @param string $credential The credential name
  * @param boolean $useAnd Whether or not to use an AND condition
  * @return boolean
  */
 public function hasCredential($credential, $useAnd = true)
 {
     if (empty($credential)) {
         return true;
     }
     if (!$this->getAccount()) {
         return false;
     }
     if ($this->getAccount()->getIsSuperAdmin()) {
         return true;
     }
     return parent::hasCredential($credential, $useAnd);
 }
 /**
  * Returns whether or not inline editing should be enabled.
  *
  * This method can be called "in general" (no $obj passed) or answered
  * for a very specific object being modified.
  *
  * @param Object $object The Object being edited - could be a Doctrine_Record, Doctrine_Collection 
  * @return boolean
  */
 public function shouldShowEditor($obj = null, $forceRefresh = false)
 {
     $key = $obj === null ? 'generic' : spl_object_hash($obj);
     if (!isset($this->_shouldShowEditor[$key]) || $forceRefresh) {
         $credential = $this->getOption('admin_credential');
         if ($credential) {
             $shouldShow = $this->_user->hasCredential($credential);
         } else {
             // even if no credential were passed, still require a login at least
             $shouldShow = $this->_user->isAuthenticated();
         }
         $event = new sfEvent($this, 'editable_content.should_show_editor', array('user' => $this->_user, 'object' => $obj));
         $this->_dispatcher->filter($event, $shouldShow);
         $this->_shouldShowEditor[$key] = $event->getReturnValue();
     }
     return $this->_shouldShowEditor[$key];
 }
 /**
  * Returns whether or not the user has the given credential.
  *
  * @param string  $credential The credential name
  * @param boolean $useAnd     Whether or not to use an AND condition
  *
  * @return boolean
  */
 public function hasCredential($credential, $useAnd = true)
 {
     if (empty($credential)) {
         return true;
     }
     if (!$this->getGuardUser()) {
         return false;
     }
     if ($this->getGuardUser()->getIsSuperAdmin()) {
         return true;
     }
     // Not very well.
     // Used by the OcariMenu to check if a user don't have a credential
     if (!is_array($credential) && 0 === strpos($credential, '!')) {
         return !in_array(substr($credential, 1), $this->credentials);
     }
     return parent::hasCredential($credential, $useAnd);
 }
 /**
  * Create a ncbtMenuItem element from a configuration array, or null if the item should not be visible.
  *
  * @static
  *
  * @param  ncbtMenuItemConfig  $config The configuration for the item.
  * @param  sfBasicSecurityUser $user   The user to test condition and/or credential against.
  *
  * @return ncbtMenuItem
  */
 public static function createFromConfig(ncbtMenuItemConfig $config, sfBasicSecurityUser $user)
 {
     if ($credentials = $config->get('credentials')) {
         if (false === $user->hasCredential($credentials)) {
             return;
         }
     }
     if ($condition = $config->get('condition')) {
         $condition_args = $config->get('condition_args', array());
         $condition_is_met = call_user_func_array(array($user, $condition), $condition_args);
         if (false === $condition_is_met) {
             return;
         }
     }
     $children = array();
     foreach ($config->get('children', array()) as $key => $child) {
         $child_config = new ncbtMenuItemConfig($key, $child);
         $child_item = self::createFromConfig($child_config, $user);
         if (null !== $child_item) {
             $children[] = $child_item;
         }
     }
     return new self($config->get('title'), $children, $config);
 }
$user->addCredential('foo');
$t->isnt($id, $id = $storage->getSessionId(), '->addCredential() regenerates the session id if a new credential is added');
$t->is($id, $storage->getSessionId(), '->addCredential() does not regenerate the session id if the credential already exists');
$user->removeCredential('foo');
$t->isnt($id, $id = $storage->getSessionId(), '->removeCredential() regenerates the session id if a credential is removed');
$t->is($id, $storage->getSessionId(), '->removeCredential() does not regenerate the session id if the credential does not exist');
// ->setTimedOut() ->getTimedOut()
$user = new sfBasicSecurityUser($dispatcher, $storage);
$t->diag('->setTimedOut() ->isTimedOut()');
$t->is($user->isTimedOut(), false, '->isTimedOut() returns false if the session is not timed out');
$user->setTimedOut();
$t->is($user->isTimedOut(), true, '->isTimedOut() returns true if the session is timed out');
// ->hasCredential()
$t->diag('->hasCredential()');
$user->clearCredentials();
$t->is($user->hasCredential('admin'), false, '->hasCredential() returns false if user has not the credential');
$user->addCredential('admin');
$t->is($user->hasCredential('admin'), true, '->addCredential() takes a credential as its first argument');
// admin AND user
$t->is($user->hasCredential(array('admin', 'user')), false, '->hasCredential() can takes an array of credential as a parameter');
// admin OR user
$t->is($user->hasCredential(array(array('admin', 'user'))), true, '->hasCredential() can takes an array of credential as a parameter');
// (admin OR user) AND owner
$t->is($user->hasCredential(array(array('admin', 'user'), 'owner')), false, '->hasCredential() can takes an array of credential as a parameter');
$user->addCredential('owner');
$t->is($user->hasCredential(array(array('admin', 'user'), 'owner')), true, '->hasCredential() can takes an array of credential as a parameter');
// [[root, admin, editor, [supplier, owner], [supplier, group], accounts]]
// root OR admin OR editor OR (supplier AND owner) OR (supplier AND group) OR accounts
$user->clearCredentials();
$credential = array(array('root', 'admin', 'editor', array('supplier', 'owner'), array('supplier', 'group'), 'accounts'));
$t->is($user->hasCredential($credential), false, '->hasCredential() can takes an array of credential as a parameter');
 public function hasCredential($credential, $useAnd = true)
 {
     if (!$this->getGuardUser()) {
         return false;
     }
     if ($this->getGuardUser()->getIsSuperAdmin()) {
         return true;
     }
     if (!is_array($credential)) {
         $credentialParts = explode('/', $credential);
         if (1 == count($credentialParts)) {
             $credentialParts = array(self::CREDENTIAL_GLOBAL_NAMESPACE, $credentialParts[0]);
         }
         if (self::CREDENTIAL_GLOBAL_NAMESPACE == $credentialParts[0]) {
             $table = Doctrine::getTable('sfObjectGuardUserGroup');
         } else {
             $table = $this->getTableOfCredential($credentialParts[0]);
         }
         if (!is_null($table)) {
             if (!$this->isCredentialsLoadedForTable($table)) {
                 $this->loadCredentialsForTable($table);
             }
             if (3 == count($credentialParts)) {
                 $ownerCredential = $credentialParts[0] . '/' . $credentialParts[1] . '/owner';
                 if (in_array($ownerCredential, $this->getCredentials())) {
                     return true;
                 }
             }
         } else {
             throw new sfException(sprintf('The model "%s" not found', $credentialParts[0]));
         }
     }
     return parent::hasCredential($credential, $useAnd);
 }