Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1932
WMFLockTaskEventListener.php
Active
Public
Actions
Authored by
epriestley
on Jan 28 2016, 6:05 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F1079090: WMFLockTaskEventListener.php
Jan 28 2016, 6:05 PM
2016-01-28 18:05:58 (UTC+0)
Subscribers
None
<?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
);
}
}
Event Timeline
epriestley
created this paste.
Jan 28 2016, 6:05 PM
2016-01-28 18:05:58 (UTC+0)
Log In to Comment