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

Don't delete expired suspensions

This commit is contained in:
Tim Düsterhus 2013-06-22 14:40:54 +02:00
parent c6e146a038
commit 08451f44fe
13 changed files with 85 additions and 32 deletions

View File

@ -19,6 +19,12 @@
<fieldset> <fieldset>
<legend>{lang}wcf.global.filter{/lang}</legend> <legend>{lang}wcf.global.filter{/lang}</legend>
<dl>
<dd>
<label><input type="checkbox" id="displayRevoked" name="displayRevoked" value="1"{if $displayRevoked} checked="checked"{/if} /> {lang}chat.acp.suspension.displayRevoked{/lang}</label>
</dd>
</dl>
<dl> <dl>
<dt><label for="username">{lang}wcf.user.username{/lang}</label></dt> <dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
<dd> <dd>

View File

@ -80,6 +80,13 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
*/ */
public $filterRoomID = null; public $filterRoomID = null;
/**
* display revoked suspensions
*
* @var integer
*/
public $displayRevoked = 0;
/** /**
* @see \wcf\page\IPage::readParameters() * @see \wcf\page\IPage::readParameters()
*/ */
@ -105,6 +112,9 @@ public function readParameters() {
// get room IDs by request // get room IDs by request
if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] != -1) $this->filterRoomID = intval($_REQUEST['roomID']); if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] != -1) $this->filterRoomID = intval($_REQUEST['roomID']);
if (isset($_REQUEST['suspensionType']) && !empty($_REQUEST['suspensionType'])) $this->filterSuspensionType = intval($_REQUEST['suspensionType']); if (isset($_REQUEST['suspensionType']) && !empty($_REQUEST['suspensionType'])) $this->filterSuspensionType = intval($_REQUEST['suspensionType']);
// display revoked
if (isset($_REQUEST['displayRevoked'])) $this->displayRevoked = intval($_REQUEST['displayRevoked']);
} }
/** /**
@ -120,7 +130,8 @@ public function assignVariables() {
'issuerUsername' => $this->filterIssuerUsername, 'issuerUsername' => $this->filterIssuerUsername,
'suspensionType' => $this->filterSuspensionType, 'suspensionType' => $this->filterSuspensionType,
'userID' => $this->filterUserID, 'userID' => $this->filterUserID,
'issuerUserID' => $this->filterIssuerUserID 'issuerUserID' => $this->filterIssuerUserID,
'displayRevoked' => $this->displayRevoked
)); ));
} }
@ -141,7 +152,10 @@ protected function initObjectList() {
$this->objectList->sqlConditionJoins .= $conditionJoins; $this->objectList->sqlConditionJoins .= $conditionJoins;
$this->objectList->sqlJoins .= $conditionJoins; $this->objectList->sqlJoins .= $conditionJoins;
if (!$this->displayRevoked) {
$this->objectList->getConditionBuilder()->add('expires >= ?', array(TIME_NOW)); $this->objectList->getConditionBuilder()->add('expires >= ?', array(TIME_NOW));
$this->objectList->getConditionBuilder()->add('revoked = ?', array(0));
}
$this->objectList->getConditionBuilder()->add('(room_table.permanent = ? OR suspension.roomID IS NULL)', array(1)); $this->objectList->getConditionBuilder()->add('(room_table.permanent = ? OR suspension.roomID IS NULL)', array(1));
if ($this->filterSuspensionType !== null) $this->objectList->getConditionBuilder()->add('suspension.type = ?', array($this->filterSuspensionType)); if ($this->filterSuspensionType !== null) $this->objectList->getConditionBuilder()->add('suspension.type = ?', array($this->filterSuspensionType));
if ($this->filterUserID !== null) $this->objectList->getConditionBuilder()->add('suspension.userID = ?', array($this->filterUserID)); if ($this->filterUserID !== null) $this->objectList->getConditionBuilder()->add('suspension.userID = ?', array($this->filterUserID));

View File

@ -31,7 +31,7 @@ class Suspension extends \chat\data\CHATDatabaseObject {
* @return boolean * @return boolean
*/ */
public function isValid() { public function isValid() {
return $this->expires > TIME_NOW; return $this->expires > TIME_NOW && !$this->revoked;
} }
/** /**
@ -53,15 +53,18 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
if ($suspensions === false) throw new \wcf\system\exception\SystemException(); if ($suspensions === false) throw new \wcf\system\exception\SystemException();
} }
catch (\wcf\system\exception\SystemException $e) { catch (\wcf\system\exception\SystemException $e) {
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
$condition->add('userID = ?', array($user->userID));
$condition->add('expires > ?', array(TIME_NOW));
$condition->add('revoked = ?', array(0));
$sql = "SELECT $sql = "SELECT
* *
FROM FROM
chat".WCF_N."_suspension chat".WCF_N."_suspension
WHERE ".$condition;
userID = ?
AND expires > ?";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($user->userID, TIME_NOW)); $stmt->execute($condition->getParameters());
$suspensions = array(); $suspensions = array();
while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) { while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) {
@ -76,7 +79,7 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
/** /**
* Returns the appropriate suspension for user, room and type. * Returns the appropriate suspension for user, room and type.
* Returns false if no suspension was found. * Returns false if no active suspension was found.
* *
* @param \wcf\data\user\User $user * @param \wcf\data\user\User $user
* @param \chat\data\room\Room $room * @param \chat\data\room\Room $room
@ -84,23 +87,22 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
* @return \chat\data\suspension\Suspension * @return \chat\data\suspension\Suspension
*/ */
public static function getSuspensionByUserRoomAndType(\wcf\data\user\User $user, \chat\data\room\Room $room, $type) { public static function getSuspensionByUserRoomAndType(\wcf\data\user\User $user, \chat\data\room\Room $room, $type) {
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
$condition->add('userID = ?', array($user->userID));
$condition->add('type = ?', array($type));
$condition->add('expires > ?', array(TIME_NOW));
$condition->add('revoked = ?', array(0));
if ($room->roomID) $condition->add('roomID = ?', array($room->roomID));
else $condition->add('roomID IS NULL');
$sql = "SELECT $sql = "SELECT
* *
FROM FROM
chat".WCF_N."_suspension chat".WCF_N."_suspension
WHERE ".$condition;
userID = ?
AND type = ?";
$parameter = array($user->userID, $type);
if ($room->roomID) {
$sql .= " AND roomID = ?";
$parameter[] = $room->roomID;
}
else $sql .= " AND roomID IS NULL";
$statement = WCF::getDB()->prepareStatement($sql); $statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($parameter); $statement->execute($condition->getParameters());
$row = $statement->fetchArray(); $row = $statement->fetchArray();
if (!$row) return false; if (!$row) return false;

View File

@ -17,9 +17,9 @@ class SuspensionAction extends \wcf\data\AbstractDatabaseObjectAction {
protected $className = '\chat\data\suspension\SuspensionEditor'; protected $className = '\chat\data\suspension\SuspensionEditor';
/** /**
* Deletes expired suspensions. * Revokes expired suspensions.
* *
* @return integer Number of deleted suspensions * @return array<integer> Revoked suspensions
*/ */
public function prune() { public function prune() {
$sql = "SELECT $sql = "SELECT
@ -34,6 +34,26 @@ public function prune() {
while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID; while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID;
return call_user_func(array($this->className, 'deleteAll'), $objectIDs); $suspensionAction = new self($objectIDs, 'revoke');
$suspensionAction->executeAction();
return $objectIDs;
}
/**
* Revokes suspensions.
*/
public function revoke() {
if (!isset($this->parameters['revoker'])) {
$this->parameters['revoker'] = null;
}
$objectAction = new self($this->objectIDs, 'update', array(
'data' => array(
'revoked' => 1,
'revoker' => $this->parameters['revoker']
)
));
$objectAction->executeAction();
} }
} }

View File

@ -23,7 +23,7 @@ public function executeAction() {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
} }
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke');
$action->executeAction(); $action->executeAction();
} }

View File

@ -22,7 +22,9 @@ public function executeAction() {
$room = new \chat\data\room\Room(null, array('roomID' => null)); $room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction(); $action->executeAction();
} }
else { else {

View File

@ -22,7 +22,9 @@ public function executeAction() {
$room = new \chat\data\room\Room(null, array('roomID' => null)); $room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction(); $action->executeAction();
} }
else { else {

View File

@ -61,7 +61,7 @@ public function executeAction() {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists')); throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
} }
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke');
$action->executeAction(); $action->executeAction();
} }

View File

@ -20,7 +20,9 @@ class UnbanCommand extends UnmuteCommand {
*/ */
public function executeAction() { public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction(); $action->executeAction();
} }
else { else {

View File

@ -41,7 +41,9 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
*/ */
public function executeAction() { public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) { if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete'); $action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction(); $action->executeAction();
} }
else { else {

View File

@ -51,8 +51,10 @@ CREATE TABLE chat1_suspension (
time INT(10) NOT NULL, time INT(10) NOT NULL,
issuer INT(10) DEFAULT NULL, issuer INT(10) DEFAULT NULL,
reason VARCHAR(255) NOT NULL DEFAULT '', reason VARCHAR(255) NOT NULL DEFAULT '',
revoked TINYINT(1) NOT NULL DEFAULT 0,
revoker INT(10) DEFAULT NULL,
UNIQUE KEY suspension (userID, roomID, type), KEY suspension (userID, roomID, type),
KEY (roomID), KEY (roomID),
KEY (type), KEY (type),
KEY (expires) KEY (expires)
@ -74,6 +76,7 @@ ALTER TABLE chat1_room ADD FOREIGN KEY (owner) REFERENCES wcf1_user (userID) ON
ALTER TABLE chat1_suspension ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE; ALTER TABLE chat1_suspension ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (roomID) REFERENCES chat1_room (roomID) ON DELETE CASCADE; ALTER TABLE chat1_suspension ADD FOREIGN KEY (roomID) REFERENCES chat1_room (roomID) ON DELETE CASCADE;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (issuer) REFERENCES wcf1_user (userID) ON DELETE SET NULL; ALTER TABLE chat1_suspension ADD FOREIGN KEY (issuer) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (revoker) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
ALTER TABLE wcf1_user ADD FOREIGN KEY (chatRoomID) REFERENCES chat1_room (roomID) ON DELETE SET NULL; ALTER TABLE wcf1_user ADD FOREIGN KEY (chatRoomID) REFERENCES chat1_room (roomID) ON DELETE SET NULL;

View File

@ -66,7 +66,7 @@
</category> </category>
<category name="chat.error"> <category name="chat.error">
<item name="chat.error.notFound"><![CDATA[Der Befehl wurde nicht gefunden.]]></item> <item name="chat.error.notFound"><![CDATA[Der Befehl „{$exception->getCommand()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item> <item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item> <item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item>
<item name="chat.error.duplicateTab"><![CDATA[Der Chat wurde in einem weiteren Tab geöffnet.]]></item> <item name="chat.error.duplicateTab"><![CDATA[Der Chat wurde in einem weiteren Tab geöffnet.]]></item>

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 55</version><!-- Codename: Codenames are overrated --> <version>3.0.0 Alpha 59</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date> <date>2011-11-26</date>
</packageinformation> </packageinformation>