public function __construct($mode, $session, $accessObjectMapper, $groupManager, $remote = FALSE, $refreshDelay = -1)
 {
     if (!is_string($mode) || !GK::checkMode($mode)) {
         throw new \Exception("Mode {$mode} is invalid");
     }
     if (!GK::checkMode($mode)) {
         throw new \Exception("Mode {$mode} is not valid", 1);
     }
     $this->whiteListMode = $mode === GK::WHITELIST_MODE;
     $this->blackListMode = $mode === GK::BLACKLIST_MODE;
     $this->minimalMode = $mode === GK::MINIMAL_MODE;
     if (!$this->minimalMode) {
         $this->groupType = GK::modeToInt($mode);
     }
     $this->session = $session;
     $this->accessObjectMapper = $accessObjectMapper;
     $this->groupManager = $groupManager;
     $this->cache = array();
     $this->remote = $remote;
     $this->refreshDelay = intval($refreshDelay);
 }
 /**
  * @Ajax
  */
 public function manageGroup()
 {
     \OC_Util::checkAdminUser();
     $params = $this->request->post;
     $id = isset($params['group']) ? $params['group'] : null;
     $name = isset($params['name']) ? $params['name'] : null;
     $action = isset($params['action']) ? $params['action'] : null;
     $groupType = isset($params['gt']) ? $params['gt'] : null;
     if (is_null($action) || is_null($groupType)) {
         return new JSONResponse(array("msg" => "Not specified action or group type"), Http::STATUS_BAD_REQUEST);
     }
     if (!GK::checkGroupType($groupType)) {
         return new JSONResponse(array("msg" => "Group type {$groupType} is not valid"), Http::STATUS_BAD_REQUEST);
     }
     switch ($action) {
         case 'rm':
             if (is_null($id)) {
                 return new JSONResponse(array("msg" => "Not specified id"), Http::STATUS_BAD_REQUEST);
             }
             $ao = AccessObject::fromParams(array('id' => $id));
             $this->accessObjectMapper->delete($ao);
             break;
         case 'add':
             if (is_null($name)) {
                 return new JSONResponse(array("msg" => "Not specified name"), Http::STATUS_BAD_REQUEST);
             }
             if ($this->accessObjectMapper->isGroupInMode($name, $groupType)) {
                 return new JSONResponse(array("msg" => "Group {$name} already exists in this list"), Http::STATUS_BAD_REQUEST);
             } else {
                 $ao = AccessObject::fromParams(array('name' => $name, 'mode' => $groupType));
                 $this->accessObjectMapper->insert($ao);
                 $id = $ao->getId();
             }
             break;
         default:
             # code...
             break;
     }
     return new JSONResponse(array('id' => $id));
 }
 public function testCheckMode()
 {
     $this->assertTrue(!GK::checkMode('foo'));
 }