1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Fix permissions for suspensions

This commit is contained in:
Tim Düsterhus 2013-06-22 17:57:33 +02:00
parent c82eea234f
commit 7bf99453f2
6 changed files with 52 additions and 20 deletions

View File

@ -26,7 +26,7 @@
<acpmenuitem name="chat.acp.menu.link.suspension.list">
<controller><![CDATA[chat\acp\page\ChatSuspensionListPage]]></controller>
<parent>chat.acp.menu.link.chat</parent>
<permissions>mod.chat.canViewAllSuspensions</permissions>
<permissions>admin.chat.canManageSuspensions</permissions>
<showorder>1</showorder>
</acpmenuitem>
</import>

View File

@ -20,7 +20,7 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
/**
* @see \wcf\page\AbstractPage::$neededPermissions
*/
public $neededPermissions = array('mod.chat.canViewAllSuspensions');
public $neededPermissions = array('admin.chat.canManageSuspensions');
/**
* @see \wcf\page\SortablePage::$defaultSortField

View File

@ -39,11 +39,18 @@ public function __toString() {
public function canEnter(\wcf\data\user\User $user = null) {
if ($user === null) $user = WCF::getUser();
if (!$user->userID) return false;
$user = new \wcf\data\user\UserProfile($user);
$ph = new \chat\system\permission\PermissionHandler($user);
$suspensions = Suspension::getSuspensionsForUser($user);
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
if ($user->getPermission('mod.chat.canGban')) return true;
$ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject());
if ($ph->getPermission($this, 'mod.canAlwaysEnter')) return true;
if ($ph->getPermission($this, 'mod.canBan')) return true;
$canEnter = $ph->getPermission($this, 'user.canEnter');
$suspensions = Suspension::getSuspensionsForUser($user->getDecoratedObject());
// room suspension
if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) {
if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->isValid()) {
@ -58,7 +65,7 @@ public function canEnter(\wcf\data\user\User $user = null) {
}
}
return $canEnter || $ph->getPermission($this, 'mod.canAlwaysEnter');
return $canEnter;
}
/**
@ -70,26 +77,33 @@ public function canEnter(\wcf\data\user\User $user = null) {
public function canWrite(\wcf\data\user\User $user = null) {
if ($user === null) $user = WCF::getUser();
if (!$user->userID) return false;
$user = new \wcf\data\user\UserProfile($user);
$ph = new \chat\system\permission\PermissionHandler($user);
$suspensions = Suspension::getSuspensionsForUser($user);
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
if ($user->getPermission('mod.chat.canGmute')) return true;
$canWrite = $ph->getPermission($this, 'user.canWrite');
$ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject());
if ($ph->getPermission($this, 'mod.canAlwaysWrite')) return true;
if ($ph->getPermission($this, 'mod.canMute')) return true;
$canEnter = $ph->getPermission($this, 'user.canWrite');
$suspensions = Suspension::getSuspensionsForUser($user->getDecoratedObject());
// room suspension
if ($canWrite && isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) {
if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) {
if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->isValid()) {
$canWrite = false;
}
}
// global suspension
if ($canWrite && isset($suspensions[null][Suspension::TYPE_MUTE])) {
if ($canEnter && isset($suspensions[null][Suspension::TYPE_MUTE])) {
if ($suspensions[null][Suspension::TYPE_MUTE]->isValid()) {
$canWrite = false;
}
}
return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite');
return $canWrite;
}
/**

View File

@ -42,10 +42,10 @@ public function isValid() {
*/
public function isVisible($user = null) {
if ($user === null) $user = WCF::getUser();
$ph = new \chat\system\permission\PermissionHandler($user);
if ($ph->getPermission($this->getRoom(), 'mod.canViewAllSuspensions')) return true;
if ($ph->getPermission($this->getRoom(), 'mod.canG'.$this->type)) return true;
$user = new \wcf\data\user\UserProfile($user);
$ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject());
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
if ($user->getPermission('mod.chat.canG'.$this->type)) return true;
if (!$this->room) return false;
if ($ph->getPermission($this->getRoom(), 'mod.can'.ucfirst($this->type))) return true;
return false;

View File

@ -89,12 +89,21 @@ public function executeAction() {
public function checkPermission() {
parent::checkPermission();
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return;
$this->room = $this->commandHandler->getRoom();
$ph = new \chat\system\permission\PermissionHandler();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst((static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE)) && $ph->getPermission($this->room, 'mod.canG'.static::SUSPENSION_TYPE)) {
if (static::IS_GLOBAL) {
WCF::getSession()->checkPermission('mod.chat.canG'.static::SUSPENSION_TYPE);
}
else {
if (!WCF::getSession()->checkPermission('mod.chat.canG'.static::SUSPENSION_TYPE)) {
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::SUSPENSION_TYPE))) {
throw new \wcf\system\exception\PermissionDeniedException();
}
}
}
}
/**
* @see \chat\system\command\ICommand::getType()

View File

@ -58,12 +58,21 @@ public function executeAction() {
public function checkPermission() {
parent::checkPermission();
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return;
$this->room = $this->commandHandler->getRoom();
$ph = new \chat\system\permission\PermissionHandler();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst((static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE)) && $ph->getPermission($this->room, 'mod.canG'.static::SUSPENSION_TYPE)) {
if (static::IS_GLOBAL) {
WCF::getSession()->checkPermission('mod.chat.canG'.static::SUSPENSION_TYPE);
}
else {
if (!WCF::getSession()->checkPermission('mod.chat.canG'.static::SUSPENSION_TYPE)) {
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::SUSPENSION_TYPE))) {
throw new \wcf\system\exception\PermissionDeniedException();
}
}
}
}
/**
* @see \chat\system\command\ICommand::getType()