Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1079090
WMFLockTaskEventListener.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
epriestley
Jan 28 2016, 6:05 PM
2016-01-28 18:05:58 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
WMFLockTaskEventListener.php
View Options
<?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
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31967
Default Alt Text
WMFLockTaskEventListener.php (1 KB)
Attached To
Mode
P1932 WMFLockTaskEventListener.php
Attached
Detach File
Event Timeline
Log In to Comment