diff --git a/file/lib/system/command/commands/InviteCommand.class.php b/file/lib/system/command/commands/InviteCommand.class.php new file mode 100644 index 0000000..c0ef7e2 --- /dev/null +++ b/file/lib/system/command/commands/InviteCommand.class.php @@ -0,0 +1,69 @@ + + * @package be.bastelstu.chat + * @subpackage system.chat.command.commands + */ +class InviteCommand extends \chat\system\command\AbstractRestrictedCommand { + public $user = null; + public $link = ''; + public $room = null; + + public function __construct(\chat\system\command\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + $username = rtrim($commandHandler->getParameters(), ','); + $this->user = User::getUserByUsername($username); + if (!$this->user->userID) throw new \chat\system\command\UserNotFoundException($username); + + $acl = \wcf\system\acl\ACLHandler::getInstance(); + $permissions = $acl->getPermissions($acl->getObjectTypeID('be.bastelstu.chat.room'), array($this->room->roomID)); + + $newPermission = array(); + foreach ($permissions['options'] as $option) { + $newPermission[$option->optionID] = ($option->categoryName == 'user') ? 1 : 0; + } + + $_POST['aclValues'] = array( + 'user' => $permissions['user'][$this->room->roomID], + 'group' => $permissions['group'][$this->room->roomID] + ); + $_POST['aclValues']['user'][$this->user->userID] = $newPermission; + + $acl->save($this->room->roomID, $acl->getObjectTypeID('be.bastelstu.chat.room')); + \chat\system\permission\PermissionHandler::clearCache(); + $this->didInit(); + } + + /** + * @see \chat\system\command\IRestrictedChatCommand::checkPermission() + */ + public function checkPermission() { + parent::checkPermission(); + + $this->room = $this->commandHandler->getRoom(); + if ($this->room->owner != WCF::getUser()->userID) throw new \wcf\system\exception\PermissionDeniedException(); + } + + /** + * @see \chat\system\command\ICommand::getType() + */ + public function getType() { + return \chat\data\message\Message::TYPE_INFORMATION; + } + + /** + * @see \chat\system\command\ICommand::getMessage() + */ + public function getMessage() { + return 'invite derp'; + } +} diff --git a/file/lib/system/command/commands/TemproomCommand.class.php b/file/lib/system/command/commands/TemproomCommand.class.php index 881c33b..92a2f11 100644 --- a/file/lib/system/command/commands/TemproomCommand.class.php +++ b/file/lib/system/command/commands/TemproomCommand.class.php @@ -37,7 +37,8 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) )); // set permissions - $options = \wcf\data\acl\option\ACLOption::getOptions(\wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room'))->getObjects(); + $acl = \wcf\system\acl\ACLHandler::getInstance(); + $options = $acl->getOptions($acl->getObjectTypeID('be.bastelstu.chat.room'))->getObjects(); $_POST['aclValues'] = array( 'user' => array( // creators may do everything @@ -49,7 +50,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler) ) ); - \wcf\system\acl\ACLHandler::getInstance()->save($roomID, \wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room')); + $acl->save($roomID, $acl->getObjectTypeID('be.bastelstu.chat.room')); \chat\system\permission\PermissionHandler::clearCache(); $this->didInit(); }