1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +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"> <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>
<!--TODO: <permissions></permissions> --> <permissions>mod.chat.canViewAllSuspensions</permissions>
<showorder>1</showorder> <showorder>1</showorder>
</acpmenuitem> </acpmenuitem>
</import> </import>

View File

@ -118,7 +118,7 @@
<td id="columnTime">{$suspension->time|plainTime}</td> <td id="columnTime">{$suspension->time|plainTime}</td>
<td id="columnExpires"> <td id="columnExpires">
<p>{$suspension->expires|plainTime}{if $suspension->expires > TIME_NOW} ({$suspension->expires|dateDiff}){/if}</p> <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>
<td id="columnIssuer"><a href="{link application='chat' controller='ChatSuspensionList'}issuerUserID={$suspension->issuer}{/link}">{$suspension->issuerUsername}</a></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> <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 * @see \wcf\page\AbstractPage::$neededPermissions
*/ */
// TODO: Permissions public $neededPermissions = array('mod.chat.canViewAllSuspensions');
public $neededPermissions = array();
/** /**
* @see \wcf\page\SortablePage::$defaultSortField * @see \wcf\page\SortablePage::$defaultSortField
@ -148,7 +147,7 @@ protected function initObjectList() {
LEFT JOIN wcf".WCF_N."_user user_table2 LEFT JOIN wcf".WCF_N."_user user_table2
ON suspension.issuer = user_table2.userID ON suspension.issuer = user_table2.userID
LEFT JOIN wcf".WCF_N."_user user_table3 LEFT JOIN wcf".WCF_N."_user user_table3
ON suspension.issuer = user_table3.userID"; ON suspension.issuer = user_table3.userID";
$conditionJoins = " LEFT JOIN chat".WCF_N."_room room_table $conditionJoins = " LEFT JOIN chat".WCF_N."_room room_table
ON suspension.roomID = room_table.roomID"; ON suspension.roomID = room_table.roomID";
$this->objectList->sqlConditionJoins .= $conditionJoins; $this->objectList->sqlConditionJoins .= $conditionJoins;

View File

@ -22,8 +22,8 @@ class Suspension extends \chat\data\CHATDatabaseObject {
*/ */
protected static $databaseTableIndexName = 'suspensionID'; protected static $databaseTableIndexName = 'suspensionID';
const TYPE_MUTE = 1; const TYPE_MUTE = 'mute';
const TYPE_BAN = 2; const TYPE_BAN = 'ban';
/** /**
* Returns whether the suspension still is valid. * Returns whether the suspension still is valid.
@ -34,6 +34,34 @@ public function isValid() {
return $this->expires > TIME_NOW; 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). * Returns all the suspensions for the specified user (current user if no user was specified).
* *

View File

@ -91,7 +91,7 @@ public function checkPermission() {
$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::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 @@ public function getMessage() {
return serialize(array( return serialize(array(
'link' => $this->link, 'link' => $this->link,
'expires' => $this->expires, 'expires' => $this->expires,
'type' => static::IDENTIFIER, 'type' => (static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE,
'reason' => $this->reason 'reason' => $this->reason
)); ));
} }

View File

@ -60,7 +60,7 @@ public function checkPermission() {
$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::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 @@ public function getType() {
public function getMessage() { public function getMessage() {
return serialize(array( return serialize(array(
'link' => $this->link, 'link' => $this->link,
'type' => 'un'.static::IDENTIFIER 'type' => 'un'.(static::IS_GLOBAL ? 'g' : '').static::SUSPENSION_TYPE,
)); ));
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,6 @@
* @subpackage system.chat.command.commands * @subpackage system.chat.command.commands
*/ */
class UnmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand { class UnmuteCommand extends \chat\system\command\AbstractUnsuspensionCommand {
const IDENTIFIER = 'mute';
const IS_GLOBAL = false; const IS_GLOBAL = false;
const SUSPENSION_TYPE = \chat\data\suspension\Suspension::TYPE_MUTE; 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, suspensionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
userID INT(10) NOT NULL, userID INT(10) NOT NULL,
roomID INT(10) DEFAULT NULL, roomID INT(10) DEFAULT NULL,
type TINYINT(3) NOT NULL, type VARCHAR(15) NOT NULL,
expires INT(10) NOT NULL, expires INT(10) NOT NULL,
time INT(10) NOT NULL, time INT(10) NOT NULL,
issuer INT(10) DEFAULT NULL, issuer INT(10) DEFAULT NULL,

View File

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

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription> <packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription> <packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication> <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> <date>2011-11-26</date>
<license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license> <license><![CDATA[Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>]]></license>
</packageinformation> </packageinformation>

View File

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