1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2025-01-18 01:20:40 +00:00

Add permissions for suspension viewing

This commit is contained in:
Tim Düsterhus 2013-06-22 17:40:24 +02:00
parent 6d539e7f0a
commit 0025fc63ee
19 changed files with 50 additions and 25 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>
<!--TODO: <permissions></permissions> -->
<permissions>mod.chat.canViewAllSuspensions</permissions>
<showorder>1</showorder>
</acpmenuitem>
</import>

View File

@ -118,7 +118,7 @@
<td id="columnTime">{$suspension->time|plainTime}</td>
<td id="columnExpires">
<p>{$suspension->expires|plainTime}{if $suspension->expires > TIME_NOW} ({$suspension->expires|dateDiff}){/if}</p>
{if $suspension->revoker}<p><small>{lang}chat.acp.suspension.revokedBy{/lang}</small></p>{/if}
{if $suspension->revoker && $suspension->expires <= TIME_NOW}<p><small>{lang}chat.acp.suspension.revokedBy{/lang}</small></p>{/if}
</td>
<td id="columnIssuer"><a href="{link application='chat' controller='ChatSuspensionList'}issuerUserID={$suspension->issuer}{/link}">{$suspension->issuerUsername}</a></td>
<td id="columnMessage"{if $suspension->reason != $suspension->reason|truncate:30} class="jsTooltip" title="{$suspension->reason}"{/if}>{$suspension->reason|truncate:30}</a></td>

View File

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

View File

@ -22,8 +22,8 @@ class Suspension extends \chat\data\CHATDatabaseObject {
*/
protected static $databaseTableIndexName = 'suspensionID';
const TYPE_MUTE = 1;
const TYPE_BAN = 2;
const TYPE_MUTE = 'mute';
const TYPE_BAN = 'ban';
/**
* Returns whether the suspension still is valid.
@ -34,6 +34,34 @@ class Suspension extends \chat\data\CHATDatabaseObject {
return $this->expires > TIME_NOW;
}
/**
* Returns whether the given user may view this suspension.
*
* @param \wcf\data\user\User $user
* @return boolean
*/
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;
if (!$this->room) return false;
if ($ph->getPermission($this->getRoom(), 'mod.can'.ucfirst($this->type))) return true;
return false;
}
/**
* Returns the room of this suspension.
*
* @return \chat\data\room\Room
*/
public function getRoom() {
if (!$this->roomID) return new \chat\data\room\Room(null, array('roomID' => null));
return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID);
}
/**
* Returns all the suspensions for the specified user (current user if no user was specified).
*

View File

@ -91,7 +91,7 @@ abstract class AbstractSuspensionCommand extends AbstractRestrictedCommand {
$this->room = $this->commandHandler->getRoom();
$ph = new \chat\system\permission\PermissionHandler();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::IDENTIFIER))) throw new \wcf\system\exception\PermissionDeniedException();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst((static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE))) throw new \wcf\system\exception\PermissionDeniedException();
}
/**
@ -108,7 +108,7 @@ abstract class AbstractSuspensionCommand extends AbstractRestrictedCommand {
return serialize(array(
'link' => $this->link,
'expires' => $this->expires,
'type' => static::IDENTIFIER,
'type' => (static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE,
'reason' => $this->reason
));
}

View File

@ -60,7 +60,7 @@ abstract class AbstractUnsuspensionCommand extends AbstractRestrictedCommand {
$this->room = $this->commandHandler->getRoom();
$ph = new \chat\system\permission\PermissionHandler();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst(static::IDENTIFIER))) throw new \wcf\system\exception\PermissionDeniedException();
if (!$ph->getPermission($this->room, 'mod.can'.ucfirst((static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE))) throw new \wcf\system\exception\PermissionDeniedException();
}
/**
@ -76,7 +76,7 @@ abstract class AbstractUnsuspensionCommand extends AbstractRestrictedCommand {
public function getMessage() {
return serialize(array(
'link' => $this->link,
'type' => 'un'.static::IDENTIFIER
'type' => 'un'.(static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE,
));
}
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class BanCommand extends \chat\system\command\AbstractSuspensionCommand {
const IDENTIFIER = 'ban';
const IS_GLOBAL = false;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN;
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class GbanCommand extends \chat\system\command\AbstractSuspensionCommand {
const IDENTIFIER = 'gban';
const IS_GLOBAL = true;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN;
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class GmuteCommand extends \chat\system\command\AbstractSuspensionCommand {
const IDENTIFIER = 'gmute';
const IS_GLOBAL = true;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE;
}

View File

@ -45,11 +45,11 @@ class InfoCommand extends \chat\system\command\AbstractCommand {
}
// Suspensions
// TODO: Permissions
$suspensions = \chat\data\suspension\Suspension::getSuspensionsForUser($this->user);
foreach ($suspensions as $roomSuspensions) {
foreach ($roomSuspensions as $typeSuspension) {
if (!$typeSuspension->isValid()) continue;
if (!$typeSuspension->isVisible()) continue;
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
$name = WCF::getLanguage()->getDynamicVariable('chat.general.information.suspension', array(

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class MuteCommand extends \chat\system\command\AbstractSuspensionCommand {
const IDENTIFIER = 'mute';
const IS_GLOBAL = false;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE;
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class UnbanCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IDENTIFIER = 'ban';
const IS_GLOBAL = false;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN;
}

View File

@ -10,8 +10,7 @@ namespace chat\system\command\commands;
* @package be.bastelstu.chat
* @subpackage system.chat.command.commands
*/
class GunbanCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IDENTIFIER = 'gban';
class UngbanCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IS_GLOBAL = true;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_BAN;
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class UngmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IDENTIFIER = 'gmute';
const IS_GLOBAL = true;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE;
}

View File

@ -11,7 +11,6 @@ namespace chat\system\command\commands;
* @subpackage system.chat.command.commands
*/
class UnmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IDENTIFIER = 'mute';
const IS_GLOBAL = false;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE;
}

View File

@ -46,7 +46,7 @@ CREATE TABLE chat1_suspension (
suspensionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
userID INT(10) NOT NULL,
roomID INT(10) DEFAULT NULL,
type TINYINT(3) NOT NULL,
type VARCHAR(15) NOT NULL,
expires INT(10) NOT NULL,
time INT(10) NOT NULL,
issuer INT(10) DEFAULT NULL,

View File

@ -144,8 +144,8 @@
</category>
<category name="chat.suspension">
<item name="chat.suspension.1"><![CDATA[Knebel]]></item>
<item name="chat.suspension.2"><![CDATA[Bann]]></item>
<item name="chat.suspension.mute"><![CDATA[Knebel]]></item>
<item name="chat.suspension.ban"><![CDATA[Bann]]></item>
</category>
<!-- I18N Values -->

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication>
<version>3.0.0 Alpha 66</version><!-- Codename: Codenames are overrated -->
<version>3.0.0 Alpha 80</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date>
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
</packageinformation>

View File

@ -56,6 +56,12 @@
<defaultvalue>0</defaultvalue>
<admindefaultvalue>1</admindefaultvalue>
</option>
<option name="mod.chat.canViewAllSuspensions">
<categoryname>mod.chat</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
<admindefaultvalue>1</admindefaultvalue>
</option>
<option name="mod.chat.canMute">
<categoryname>mod.chat</categoryname>
<optiontype>boolean</optiontype>