Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. symfony - sfDoctrineGuard - restricting user creation based on group credentials
  2. config:
  3.   list:
  4.     object_actions:
  5.       _delete:
  6.         confirm: Вы уверены, что хотите удалить пользователя?
  7.         credentials: superuser
  8.     actions:
  9.       _new:
  10.         credentails: moderator
  11.        
  12. class sfGuardUserForm extends PluginsfGuardUserForm
  13. {
  14.   public function configure()
  15.   {
  16.     //groups_list
  17.     $this->getWidget('groups_list')->setOption('expanded', true);
  18.     $this->getWidget('groups_list')->setOption('table_method', 'getListForAdmin');
  19.     $this->getValidator('groups_list')->setOption('query', Doctrine::getTable('sfGuardGroup')->getListForAdmin());
  20.   }
  21. }
  22.  
  23. class sfGuardGroupTable extends PluginsfGuardGroupTable
  24. {
  25.   /**
  26.    * Builds list query based on credentials
  27.    *
  28.    */
  29.   public function getListForAdmin()
  30.   {
  31.     $user = sfContext::getInstance()->getUser();
  32.  
  33.     $q = $this->createQuery('g');
  34.  
  35.     if (!$user->isSuperAdmin() && $user->hasCredential('moderator'))
  36.     {
  37.       $q->addWhere('g.name IN (?)', array('editor'));
  38.     }
  39.     else if ($user->hasCredential('editor'))
  40.     {
  41.       $q->addWhere('g.name IN (?)', array('editor'));
  42.     }        
  43.     return $q;
  44.   }
  45. }