Skip to content

Commit

Permalink
Allow tool admins to disable the ability to appeal
Browse files Browse the repository at this point in the history
  • Loading branch information
stwalkerster committed Dec 27, 2024
1 parent 60eac7d commit a4537b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions includes/Helpers/PreferenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class PreferenceManager
const PREF_SKIN = 'skin';
const PREF_DEFAULT_DOMAIN = 'defaultDomain';
const PREF_QUEUE_HELP = 'showQueueHelp';

const ADMIN_PREF_PREVENT_REACTIVATION = 'preventReactivation';

const CREATION_MANUAL = 0;
const CREATION_OAUTH = 1;
const CREATION_BOT = 2;
Expand Down
4 changes: 4 additions & 0 deletions includes/Pages/PageUserManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ protected function editUser()

$prefs->setLocalPreference(PreferenceManager::PREF_CREATION_MODE, WebRequest::postInt('creationmode'));

$prefs->setLocalPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION, WebRequest::postBoolean('preventReactivation'));

$user->setUpdateVersion(WebRequest::postInt('updateversion'));

$user->save();
Expand All @@ -515,6 +517,8 @@ protected function editUser()
$this->assign('preferredCreationMode', (int)$prefs->getPreference(PreferenceManager::PREF_CREATION_MODE));
$this->assign('emailSignature', $prefs->getPreference(PreferenceManager::PREF_EMAIL_SIGNATURE));

$this->assign('preventReactivation', $prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false);

$this->assign('canManualCreate',
$this->barrierTest(PreferenceManager::CREATION_MANUAL, $user, 'RequestCreation'));
$this->assign('canOauthCreate',
Expand Down
13 changes: 13 additions & 0 deletions includes/Pages/UserAuth/PageUserReactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
namespace Waca\Pages\UserAuth;

use Exception;
use Waca\DataObjects\Domain;
use Waca\DataObjects\User;
use Waca\Exceptions\ApplicationLogicException;
use Waca\Fragments\LogEntryLookup;
use Waca\Helpers\Logger;
use Waca\Helpers\PreferenceManager;
use Waca\SessionAlert;
use Waca\Tasks\InternalPageBase;
use Waca\WebRequest;
Expand All @@ -38,12 +40,22 @@ protected function main()
return;
}

$ableToAppeal = true;
$prefs = new PreferenceManager($db, $currentUser->getId(), Domain::getCurrent($db)->getId());
if ($prefs->getPreference(PreferenceManager::ADMIN_PREF_PREVENT_REACTIVATION) ?? false) {
$ableToAppeal = false;
}

if (WebRequest::wasPosted()) {
$this->validateCSRFToken();

$reason = WebRequest::postString('reason');
$updateVersion = WebRequest::postInt('updateVersion');

if(!$ableToAppeal) {
throw new ApplicationLogicException('Appeal is disabled');
}

if ($reason == '') {
throw new ApplicationLogicException('The reason field cannot be empty.');
}
Expand All @@ -59,6 +71,7 @@ protected function main()
$this->assignCSRFToken();
$this->assign('deactivationReason', $this->getLogEntry('DeactivatedUser', $currentUser, $db));
$this->assign('updateVersion', $currentUser->getUpdateVersion());
$this->assign('ableToAppeal', $ableToAppeal);
$this->setTemplate('reactivate.tpl');
}
}
Expand Down
8 changes: 6 additions & 2 deletions templates/reactivate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</div>
</div>

{if !$ableToAppeal}
{include file="alert.tpl" alertblock="true" alerttype="alert-danger" alertclosable=false alertmessage="Your account is unable to appeal through this interface."}
{/if}

<form method="post">
{include file="security/csrf.tpl"}

Expand All @@ -22,15 +26,15 @@
<label class="col-form-label" for="reason">Please explain why you believe your account should be reactivated:</label>
</div>
<div class="col-12">
<textarea required="required" class="form-control" rows="4" name="reason" id="reason" maxlength="65535"></textarea>
<textarea required="required" class="form-control" rows="4" name="reason" id="reason" maxlength="65535" {if !$ableToAppeal}readonly{/if}></textarea>
</div>
</div>

<input type="hidden" name="updateVersion" value="{$updateVersion}"/>

<div class="form-group row">
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-primary">Request Reactivation</button>
<button type="submit" class="btn btn-block btn-primary" {if !$ableToAppeal}disabled{/if}>Request Reactivation</button>
</div>
</div>

Expand Down
14 changes: 14 additions & 0 deletions templates/usermanagement/edituser.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@
</div>
</div>

<div class="form-group row">

<div class="offset-lg-2 col-md-3 col-lg-2">
<span class="col-form-label">Account reactivation</span>
</div>
<div class="col-md-9 col-lg-7 col-xl-6">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" id="preventReactivation" name="preventReactivation"{if $preventReactivation} checked{/if}>
<label class="custom-control-label" for="preventReactivation">Prevent this user from appealing deactivation</label>
</div>
</div>
</div>



<input type="hidden" name="updateversion" value="{$user->getUpdateVersion()}"/>

Expand Down

0 comments on commit a4537b0

Please sign in to comment.