public function securityChecks() { //Check if superuser already assigned if ($this->getGroup() === Group::$superUserGroupName) { $tUserGroup = new UserGroup(); $tUserGroup->setGroup(Group::$superUserGroupName); if ($tUserGroup->read() !== null) { throw new GraphException('Super user group was already assigned', 400); } } //Check if already assigned if ($this->read() !== null) { throw new GraphException('user ' . $this->getUserId() . ' already assigned at ' . $this->getGroup(), 400); } }
public function run() { $userId = $this->request->getPar('userId'); $group = new UserGroup(); $group->setUserId($userId); $userGroups = $group->read(true); $ret = array(); $ret[] = Group::$everyoneGroupName; if ($userGroups !== null) { foreach ($userGroups as $userGr) { $ret[] = $userGr->getGroup(); } } $this->response->setBody(json_encode(array('UserGroups' => $ret))); }
public function run() { $userGroup = UserGroup::getByRequest(); $res = $this->forward('/users/user/' . $userGroup->getUserId()); if ($res->getStatusCode() !== 200) { throw new GraphException('user id is not valid', 400); } $this->sendModel($userGroup->create()); }
public function run() { $group = Group::standardizeGroupName($this->request->getPar('group')); $userGroup = new UserGroup(); $userGroup->setGroup($group); $userGroups = $userGroup->read(true); $ret = array(); if ($userGroups !== null) { foreach ($userGroups as $uGroup) { $res = $this->forward('/users/user/' . $uGroup->getUserId()); if ($res->getStatusCode() !== 200) { Log::err('user: '******' not found'); } else { $ret[] = json_decode($res->getBody(), true)['User']['username']; } } } $this->response->setBody(json_encode(array('GroupUsers' => array('group' => $group, 'users' => $ret)), JSON_PRETTY_PRINT)); }
public function onDelete() { $this->standardize(); //Controllo gruppi di sistema if ($this->getName() === Group::$superUserGroupName) { throw new GraphException('cannot delete system group: ' . self::$superUserGroupName, 400); } if ($this->getName() === Group::$everyoneGroupName) { throw new GraphException('cannot delete system group: ' . self::$everyoneGroupName, 400); } //Controllo esistenza gruppo $fGroup = new Group(); $fGroup->setName($this->getName()); $readedGroup = $fGroup->read(); if ($readedGroup === null) { throw new GraphException('Group ' . $this->getName() . ' not found'); } //Controllo gruppi figlio di questo gruppo $cGroup = new Group(); $cGroup->setParent($this->getName()); if ($cGroup->read(true) !== null) { throw new GraphException('Cannot delete group ' . $this->getName() . ' with child groups'); } //Controllo esistenza utenti assegnati al gruppo $uGroup = new UserGroup(); $uGroup->setGroup($this->getName()); if ($uGroup->read(true) !== null) { throw new GraphException('Cannot delete group ' . $this->getName() . ' with users'); } $this->setContent($readedGroup->getContent()); }