Page MenuHomePhabricator

WMFLockTaskEventListener.php

Authored By
epriestley
Jan 28 2016, 6:05 PM
Size
1 KB
Referenced Files
None
Subscribers
None

WMFLockTaskEventListener.php

<?php
final class WMFLockTaskEventListener extends PhabricatorEventListener {
public function register() {
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
}
public function handleEvent(PhutilEvent $event) {
switch ($event->getType()) {
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
$this->handleActionEvent($event);
break;
}
}
private function handleActionEvent($event) {
$viewer = $event->getUser();
$object = $event->getValue('object');
if (!$object || !($object instanceof ManiphestTask)) {
return;
}
// Figure out if the item will be enabled or disabled in the UI.
// This assumes any logged-in user can lock tasks (UI item always enabled),
// but you probably want to test for project membership or something
// instead.
$can_lock = $viewer->isLoggedIn();
// Figure out if the task is already locked, so we can either show
// "Lock This Task" or "This Task is Already Locked".
// This should read the custom "Security" field, or the policy, or you
// can just leave it like this to always shows "Lock This Task" and let
// users figure it out.
$is_locked = false;
// You can't re-lock an already-locked task.
$can_lock = ($can_lock && !$is_locked);
if ($is_locked) {
$lock_name = pht('Already Locked');
} else {
$lock_name = pht('Lock Security Issue');
}
$lock_action = id(new PhabricatorActionView())
->setHref('/wmf-extensions/lock-task/'.$object->getID().'/')
->setIcon('fa-lock')
->setName($lock_name)
->setWorkflow(true)
->setDisabled(!$can_lock);
$actions = $event->getValue('actions');
$actions[] = $lock_action;
$event->setValue('actions', $actions);
}
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31967
Default Alt Text
WMFLockTaskEventListener.php (1 KB)

Event Timeline