Esempio n. 1
0
 public function action_check()
 {
     $roles = GateKeeper::getRoles();
     if (!$roles || !count($roles)) {
         if (Controller::$debug) {
             Backend::addNotice('No roles setup, addings some');
         }
         $roles = $this->getDefaultRoles();
         if ($roles) {
             foreach ($roles as $role) {
                 GateKeeper::assign($role['role'], $role['access_type'], $role['access_id']);
                 if (Controller::$debug) {
                     Backend::addSuccess('Added role ' . $role['role']);
                 }
             }
         }
         $permits = $this->getDefaultPermissions();
         if ($permits) {
             foreach ($permits as $permit) {
                 GateKeeper::permit($permit['role'], $permit['control'], $permit['action'], $permit['subject'], $permit['subject_id']);
                 if (Controller::$debug) {
                     Backend::addSuccess('Added permission to ' . $role['action'] . ' to ' . $permit['role']);
                 }
             }
         }
     } else {
         if (Controller::$debug) {
             var_dump($roles);
         }
     }
 }
Esempio n. 2
0
 public static function install(array $options = array())
 {
     $options['drop_table'] = array_key_exists('drop_table', $options) ? $options['drop_table'] : true;
     $toret = parent::install($options);
     foreach (self::getDefaults() as $assignment) {
         if (GateKeeper::assign($assignment['role'], $assignment['access_type'], $assignment['access_id'])) {
             Backend::addSuccess('Added assignment to ' . $assignment['role']);
             $toret = $toret && true;
         } else {
             Backend::addError('Could not add assignment to ' . $assignment['role']);
             $toret = false;
         }
     }
     return $toret;
 }
Esempio n. 3
0
 public function post_roles($userId)
 {
     $roles = Controller::getVar('roles');
     if (is_array($roles)) {
         foreach ($roles as $role) {
             if (GateKeeper::assign($role, 'users', $userId)) {
                 Backend::addSuccess('Added User to ' . $role);
             } else {
                 Backend::addError('Could not add User to ' . $role);
             }
         }
     }
     Controller::redirect();
 }