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:
parent
c82eea234f
commit
7bf99453f2
@ -26,7 +26,7 @@
|
|||||||
<acpmenuitem name="chat.acp.menu.link.suspension.list">
|
<acpmenuitem name="chat.acp.menu.link.suspension.list">
|
||||||
<controller><![CDATA[chat\acp\page\ChatSuspensionListPage]]></controller>
|
<controller><![CDATA[chat\acp\page\ChatSuspensionListPage]]></controller>
|
||||||
<parent>chat.acp.menu.link.chat</parent>
|
<parent>chat.acp.menu.link.chat</parent>
|
||||||
<permissions>mod.chat.canViewAllSuspensions</permissions>
|
<permissions>admin.chat.canManageSuspensions</permissions>
|
||||||
<showorder>1</showorder>
|
<showorder>1</showorder>
|
||||||
</acpmenuitem>
|
</acpmenuitem>
|
||||||
</import>
|
</import>
|
||||||
|
@ -20,7 +20,7 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
|
|||||||
/**
|
/**
|
||||||
* @see \wcf\page\AbstractPage::$neededPermissions
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
||||||
*/
|
*/
|
||||||
public $neededPermissions = array('mod.chat.canViewAllSuspensions');
|
public $neededPermissions = array('admin.chat.canManageSuspensions');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \wcf\page\SortablePage::$defaultSortField
|
* @see \wcf\page\SortablePage::$defaultSortField
|
||||||
|
@ -39,11 +39,18 @@ public function __toString() {
|
|||||||
public function canEnter(\wcf\data\user\User $user = null) {
|
public function canEnter(\wcf\data\user\User $user = null) {
|
||||||
if ($user === null) $user = WCF::getUser();
|
if ($user === null) $user = WCF::getUser();
|
||||||
if (!$user->userID) return false;
|
if (!$user->userID) return false;
|
||||||
|
$user = new \wcf\data\user\UserProfile($user);
|
||||||
|
|
||||||
$ph = new \chat\system\permission\PermissionHandler($user);
|
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
|
||||||
$suspensions = Suspension::getSuspensionsForUser($user);
|
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');
|
$canEnter = $ph->getPermission($this, 'user.canEnter');
|
||||||
|
|
||||||
|
$suspensions = Suspension::getSuspensionsForUser($user->getDecoratedObject());
|
||||||
// room suspension
|
// room suspension
|
||||||
if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) {
|
if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) {
|
||||||
if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->isValid()) {
|
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) {
|
public function canWrite(\wcf\data\user\User $user = null) {
|
||||||
if ($user === null) $user = WCF::getUser();
|
if ($user === null) $user = WCF::getUser();
|
||||||
if (!$user->userID) return false;
|
if (!$user->userID) return false;
|
||||||
|
$user = new \wcf\data\user\UserProfile($user);
|
||||||
|
|
||||||
$ph = new \chat\system\permission\PermissionHandler($user);
|
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
|
||||||
$suspensions = Suspension::getSuspensionsForUser($user);
|
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
|
// 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()) {
|
if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->isValid()) {
|
||||||
$canWrite = false;
|
$canWrite = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// global suspension
|
// 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()) {
|
if ($suspensions[null][Suspension::TYPE_MUTE]->isValid()) {
|
||||||
$canWrite = false;
|
$canWrite = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite');
|
return $canWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,10 +42,10 @@ public function isValid() {
|
|||||||
*/
|
*/
|
||||||
public function isVisible($user = null) {
|
public function isVisible($user = null) {
|
||||||
if ($user === null) $user = WCF::getUser();
|
if ($user === null) $user = WCF::getUser();
|
||||||
|
$user = new \wcf\data\user\UserProfile($user);
|
||||||
$ph = new \chat\system\permission\PermissionHandler($user);
|
$ph = new \chat\system\permission\PermissionHandler($user->getDecoratedObject());
|
||||||
if ($ph->getPermission($this->getRoom(), 'mod.canViewAllSuspensions')) return true;
|
if ($user->getPermission('admin.chat.canManageSuspensions')) return true;
|
||||||
if ($ph->getPermission($this->getRoom(), 'mod.canG'.$this->type)) return true;
|
if ($user->getPermission('mod.chat.canG'.$this->type)) return true;
|
||||||
if (!$this->room) return false;
|
if (!$this->room) return false;
|
||||||
if ($ph->getPermission($this->getRoom(), 'mod.can'.ucfirst($this->type))) return true;
|
if ($ph->getPermission($this->getRoom(), 'mod.can'.ucfirst($this->type))) return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -89,10 +89,19 @@ public function executeAction() {
|
|||||||
public function checkPermission() {
|
public function checkPermission() {
|
||||||
parent::checkPermission();
|
parent::checkPermission();
|
||||||
|
|
||||||
|
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return;
|
||||||
|
|
||||||
$this->room = $this->commandHandler->getRoom();
|
$this->room = $this->commandHandler->getRoom();
|
||||||
$ph = new \chat\system\permission\PermissionHandler();
|
$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) {
|
||||||
throw new \wcf\system\exception\PermissionDeniedException();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +58,19 @@ public function executeAction() {
|
|||||||
public function checkPermission() {
|
public function checkPermission() {
|
||||||
parent::checkPermission();
|
parent::checkPermission();
|
||||||
|
|
||||||
|
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return;
|
||||||
|
|
||||||
$this->room = $this->commandHandler->getRoom();
|
$this->room = $this->commandHandler->getRoom();
|
||||||
$ph = new \chat\system\permission\PermissionHandler();
|
$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) {
|
||||||
throw new \wcf\system\exception\PermissionDeniedException();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user