mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Update Phlux for handleRequest
Summary: Ref T8628. Updates Phlux Test Plan: New var, list vars, edit vars Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T8628 Differential Revision: https://secure.phabricator.com/D14267
This commit is contained in:
parent
a8e9da4a56
commit
057d62d570
3 changed files with 24 additions and 37 deletions
|
@ -2,35 +2,29 @@
|
||||||
|
|
||||||
final class PhluxEditController extends PhluxController {
|
final class PhluxEditController extends PhluxController {
|
||||||
|
|
||||||
private $key;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$key = $request->getURIData('key');
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
$is_new = ($key === null);
|
||||||
$this->key = idx($data, 'key');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$is_new = ($this->key === null);
|
|
||||||
if ($is_new) {
|
if ($is_new) {
|
||||||
$var = new PhluxVariable();
|
$var = new PhluxVariable();
|
||||||
$var->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
$var->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
||||||
$var->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
$var->setEditPolicy(PhabricatorPolicies::POLICY_USER);
|
||||||
} else {
|
} else {
|
||||||
$var = id(new PhluxVariableQuery())
|
$var = id(new PhluxVariableQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
))
|
))
|
||||||
->withKeys(array($this->key))
|
->withKeys(array($key))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$var) {
|
if (!$var) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
$view_uri = $this->getApplicationURI('/view/'.$this->key.'/');
|
$view_uri = $this->getApplicationURI('/view/'.$key.'/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$e_key = ($is_new ? true : null);
|
$e_key = ($is_new ? true : null);
|
||||||
|
@ -67,7 +61,7 @@ final class PhluxEditController extends PhluxController {
|
||||||
|
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$editor = id(new PhluxVariableEditor())
|
$editor = id(new PhluxVariableEditor())
|
||||||
->setActor($user)
|
->setActor($viewer)
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContentSourceFromRequest($request);
|
->setContentSourceFromRequest($request);
|
||||||
|
|
||||||
|
@ -110,12 +104,12 @@ final class PhluxEditController extends PhluxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$policies = id(new PhabricatorPolicyQuery())
|
$policies = id(new PhabricatorPolicyQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->setObject($var)
|
->setObject($var)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setValue($var->getVariableKey())
|
->setValue($var->getVariableKey())
|
||||||
|
@ -161,7 +155,7 @@ final class PhluxEditController extends PhluxController {
|
||||||
$title = pht('Create Variable');
|
$title = pht('Create Variable');
|
||||||
$crumbs->addTextCrumb($title, $request->getRequestURI());
|
$crumbs->addTextCrumb($title, $request->getRequestURI());
|
||||||
} else {
|
} else {
|
||||||
$title = pht('Edit %s', $this->key);
|
$title = pht('Edit %s', $key);
|
||||||
$crumbs->addTextCrumb($title, $request->getRequestURI());
|
$crumbs->addTextCrumb($title, $request->getRequestURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
|
|
||||||
final class PhluxListController extends PhluxController {
|
final class PhluxListController extends PhluxController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$request = $this->getRequest();
|
$viewer = $this->getViewer();
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$pager = new AphrontCursorPagerView();
|
$pager = new AphrontCursorPagerView();
|
||||||
$pager->readFromRequest($request);
|
$pager->readFromRequest($request);
|
||||||
$query = id(new PhluxVariableQuery())
|
$query = id(new PhluxVariableQuery())
|
||||||
->setViewer($user);
|
->setViewer($viewer);
|
||||||
|
|
||||||
$vars = $query->executeWithCursorPager($pager);
|
$vars = $query->executeWithCursorPager($pager);
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ final class PhluxListController extends PhluxController {
|
||||||
$item->setHref($this->getApplicationURI('/view/'.$key.'/'));
|
$item->setHref($this->getApplicationURI('/view/'.$key.'/'));
|
||||||
$item->addIcon(
|
$item->addIcon(
|
||||||
'none',
|
'none',
|
||||||
phabricator_datetime($var->getDateModified(), $user));
|
phabricator_datetime($var->getDateModified(), $viewer));
|
||||||
|
|
||||||
$view->addItem($item);
|
$view->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
final class PhluxViewController extends PhluxController {
|
final class PhluxViewController extends PhluxController {
|
||||||
|
|
||||||
private $key;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
public function willProcessRequest(array $data) {
|
$key = $request->getURIData('key');
|
||||||
$this->key = $data['key'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$var = id(new PhluxVariableQuery())
|
$var = id(new PhluxVariableQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->withKeys(array($this->key))
|
->withKeys(array($key))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$var) {
|
if (!$var) {
|
||||||
|
@ -29,16 +23,16 @@ final class PhluxViewController extends PhluxController {
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
->setHeader($title)
|
->setHeader($title)
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setPolicyObject($var);
|
->setPolicyObject($var);
|
||||||
|
|
||||||
$actions = id(new PhabricatorActionListView())
|
$actions = id(new PhabricatorActionListView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setObjectURI($request->getRequestURI())
|
->setObjectURI($request->getRequestURI())
|
||||||
->setObject($var);
|
->setObject($var);
|
||||||
|
|
||||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
$user,
|
$viewer,
|
||||||
$var,
|
$var,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT);
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
@ -53,7 +47,7 @@ final class PhluxViewController extends PhluxController {
|
||||||
$display_value = json_encode($var->getVariableValue());
|
$display_value = json_encode($var->getVariableValue());
|
||||||
|
|
||||||
$properties = id(new PHUIPropertyListView())
|
$properties = id(new PHUIPropertyListView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setObject($var)
|
->setObject($var)
|
||||||
->setActionList($actions)
|
->setActionList($actions)
|
||||||
->addProperty(pht('Value'), $display_value);
|
->addProperty(pht('Value'), $display_value);
|
||||||
|
|
Loading…
Reference in a new issue