1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 18:52:42 +01:00

Update Legalpad for handleRequest

Summary: Updates Legalpad for handleRequest instead of processRequest

Test Plan: New Document, Sign Document, Add exemption, view signatures.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13756
This commit is contained in:
Chad Little 2015-07-29 17:02:10 -07:00
parent cdf03b0f7a
commit 77ababadcb
8 changed files with 63 additions and 98 deletions

View file

@ -2,23 +2,17 @@
final class LegalpadDocumentCommentController extends LegalpadController { final class LegalpadDocumentCommentController extends LegalpadController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if (!$request->isFormPost()) { if (!$request->isFormPost()) {
return new Aphront400Response(); return new Aphront400Response();
} }
$document = id(new LegalpadDocumentQuery()) $document = id(new LegalpadDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needDocumentBodies(true) ->needDocumentBodies(true)
->executeOne(); ->executeOne();
@ -48,7 +42,7 @@ final class LegalpadDocumentCommentController extends LegalpadController {
} }
$editor = id(new LegalpadDocumentEditor()) $editor = id(new LegalpadDocumentEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect($request->isContinueRequest()) ->setContinueOnNoEffect($request->isContinueRequest())
->setIsPreview($is_preview); ->setIsPreview($is_preview);
@ -67,7 +61,7 @@ final class LegalpadDocumentCommentController extends LegalpadController {
if ($request->isAjax() && $is_preview) { if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse()) return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user) ->setViewer($viewer)
->setTransactions($xactions) ->setTransactions($xactions)
->setIsPreview($is_preview); ->setIsPreview($is_preview);
} else { } else {

View file

@ -6,9 +6,8 @@ final class LegalpadDocumentDoneController extends LegalpadController {
return true; return true;
} }
public function processRequest() { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest(); $viewer = $request->getViewer();
$viewer = $request->getUser();
return $this->newDialog() return $this->newDialog()
->setTitle(pht('Verify Signature')) ->setTitle(pht('Verify Signature'))

View file

@ -3,25 +3,25 @@
final class LegalpadDocumentEditController extends LegalpadController { final class LegalpadDocumentEditController extends LegalpadController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
if (!$id) { if (!$id) {
$is_create = true; $is_create = true;
$this->requireApplicationCapability( $this->requireApplicationCapability(
LegalpadCreateDocumentsCapability::CAPABILITY); LegalpadCreateDocumentsCapability::CAPABILITY);
$document = LegalpadDocument::initializeNewDocument($user); $document = LegalpadDocument::initializeNewDocument($viewer);
$body = id(new LegalpadDocumentBody()) $body = id(new LegalpadDocumentBody())
->setCreatorPHID($user->getPHID()); ->setCreatorPHID($viewer->getPHID());
$document->attachDocumentBody($body); $document->attachDocumentBody($body);
$document->setDocumentBodyPHID(PhabricatorPHIDConstants::PHID_VOID); $document->setDocumentBodyPHID(PhabricatorPHIDConstants::PHID_VOID);
} else { } else {
$is_create = false; $is_create = false;
$document = id(new LegalpadDocumentQuery()) $document = id(new LegalpadDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->needDocumentBodies(true) ->needDocumentBodies(true)
->requireCapabilities( ->requireCapabilities(
array( array(
@ -94,7 +94,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
$v_require_signature = $request->getBool('requireSignature', 0); $v_require_signature = $request->getBool('requireSignature', 0);
if ($v_require_signature) { if ($v_require_signature) {
if (!$user->getIsAdmin()) { if (!$viewer->getIsAdmin()) {
$errors[] = pht('Only admins may require signature.'); $errors[] = pht('Only admins may require signature.');
} }
$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL; $individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
@ -104,7 +104,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
'signing to use Phabricator.'); 'signing to use Phabricator.');
} }
} }
if ($user->getIsAdmin()) { if ($viewer->getIsAdmin()) {
$xactions[] = id(new LegalpadTransaction()) $xactions[] = id(new LegalpadTransaction())
->setTransactionType(LegalpadTransaction::TYPE_REQUIRE_SIGNATURE) ->setTransactionType(LegalpadTransaction::TYPE_REQUIRE_SIGNATURE)
->setNewValue($v_require_signature); ->setNewValue($v_require_signature);
@ -114,7 +114,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
$editor = id(new LegalpadDocumentEditor()) $editor = id(new LegalpadDocumentEditor())
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setActor($user); ->setActor($viewer);
$xactions = $editor->applyTransactions($document, $xactions); $xactions = $editor->applyTransactions($document, $xactions);
@ -130,7 +130,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setID('document-title') ->setID('document-title')
@ -162,7 +162,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
$form $form
->appendChild( ->appendChild(
id(new AphrontFormCheckboxControl()) id(new AphrontFormCheckboxControl())
->setDisabled(!$user->getIsAdmin()) ->setDisabled(!$viewer->getIsAdmin())
->setLabel(pht('Require Signature')) ->setLabel(pht('Require Signature'))
->addCheckbox( ->addCheckbox(
'requireSignature', 'requireSignature',
@ -175,7 +175,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($viewer)
->setID('preamble') ->setID('preamble')
->setLabel(pht('Preamble')) ->setLabel(pht('Preamble'))
->setValue($v_preamble) ->setValue($v_preamble)
@ -184,7 +184,7 @@ final class LegalpadDocumentEditController extends LegalpadController {
pht('Optional help text for users signing this document.'))) pht('Optional help text for users signing this document.')))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($viewer)
->setID('document-text') ->setID('document-text')
->setLabel(pht('Document Body')) ->setLabel(pht('Document Body'))
->setError($e_text) ->setError($e_text)
@ -193,21 +193,21 @@ final class LegalpadDocumentEditController extends LegalpadController {
->setName('text')); ->setName('text'));
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($user) ->setViewer($viewer)
->setObject($document) ->setObject($document)
->execute(); ->execute();
$form $form
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW) ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($document) ->setPolicyObject($document)
->setPolicies($policies) ->setPolicies($policies)
->setName('can_view')) ->setName('can_view'))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($document) ->setPolicyObject($document)
->setPolicies($policies) ->setPolicies($policies)

View file

@ -2,19 +2,15 @@
final class LegalpadDocumentListController extends LegalpadController { final class LegalpadDocumentListController extends LegalpadController {
private $queryKey;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->queryKey = idx($data, 'queryKey'); $querykey = $request->getURIData('queryKey');
}
public function processRequest() {
$controller = id(new PhabricatorApplicationSearchController()) $controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey) ->setQueryKey($querykey)
->setSearchEngine(new LegalpadDocumentSearchEngine()) ->setSearchEngine(new LegalpadDocumentSearchEngine())
->setNavigation($this->buildSideNav()); ->setNavigation($this->buildSideNav());

View file

@ -2,21 +2,15 @@
final class LegalpadDocumentManageController extends LegalpadController { final class LegalpadDocumentManageController extends LegalpadController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
// NOTE: We require CAN_EDIT to view this page. // NOTE: We require CAN_EDIT to view this page.
$document = id(new LegalpadDocumentQuery()) $document = id(new LegalpadDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needDocumentBodies(true) ->needDocumentBodies(true)
->needContributors(true) ->needContributors(true)
->requireCapabilities( ->requireCapabilities(
@ -35,7 +29,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
$document_body = $document->getDocumentBody(); $document_body = $document->getDocumentBody();
$engine = id(new PhabricatorMarkupEngine()) $engine = id(new PhabricatorMarkupEngine())
->setViewer($user); ->setViewer($viewer);
$engine->addObject( $engine->addObject(
$document_body, $document_body,
LegalpadDocumentBody::MARKUP_FIELD_TEXT); LegalpadDocumentBody::MARKUP_FIELD_TEXT);
@ -48,7 +42,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($title) ->setHeader($title)
->setUser($user) ->setUser($viewer)
->setPolicyObject($document); ->setPolicyObject($document);
$actions = $this->buildActionView($document); $actions = $this->buildActionView($document);
@ -99,15 +93,15 @@ final class LegalpadDocumentManageController extends LegalpadController {
} }
private function buildActionView(LegalpadDocument $document) { private function buildActionView(LegalpadDocument $document) {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$actions = id(new PhabricatorActionListView()) $actions = id(new PhabricatorActionListView())
->setUser($user) ->setUser($viewer)
->setObjectURI($this->getRequest()->getRequestURI()) ->setObjectURI($this->getRequest()->getRequestURI())
->setObject($document); ->setObject($document);
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$user, $viewer,
$document, $document,
PhabricatorPolicyCapability::CAN_EDIT); PhabricatorPolicyCapability::CAN_EDIT);
@ -141,10 +135,10 @@ final class LegalpadDocumentManageController extends LegalpadController {
PhabricatorMarkupEngine $engine, PhabricatorMarkupEngine $engine,
PhabricatorActionListView $actions) { PhabricatorActionListView $actions) {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView()) $properties = id(new PHUIPropertyListView())
->setUser($user) ->setUser($viewer)
->setObject($document) ->setObject($document)
->setActionList($actions); ->setActionList($actions);
@ -154,11 +148,11 @@ final class LegalpadDocumentManageController extends LegalpadController {
$properties->addProperty( $properties->addProperty(
pht('Last Updated'), pht('Last Updated'),
phabricator_datetime($document->getDateModified(), $user)); phabricator_datetime($document->getDateModified(), $viewer));
$properties->addProperty( $properties->addProperty(
pht('Updated By'), pht('Updated By'),
$user->renderHandle($document->getDocumentBody()->getCreatorPHID())); $viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));
$properties->addProperty( $properties->addProperty(
pht('Versions'), pht('Versions'),
@ -167,7 +161,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
if ($document->getContributors()) { if ($document->getContributors()) {
$properties->addProperty( $properties->addProperty(
pht('Contributors'), pht('Contributors'),
$user $viewer
->renderHandleList($document->getContributors()) ->renderHandleList($document->getContributors())
->setAsInline(true)); ->setAsInline(true));
} }
@ -180,9 +174,9 @@ final class LegalpadDocumentManageController extends LegalpadController {
private function buildAddCommentView( private function buildAddCommentView(
LegalpadDocument $document, LegalpadDocument $document,
$comment_form_id) { $comment_form_id) {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$draft = PhabricatorDraft::newFromUserAndKey($user, $document->getPHID()); $draft = PhabricatorDraft::newFromUserAndKey($viewer, $document->getPHID());
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
@ -191,7 +185,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
: pht('Debate Legislation'); : pht('Debate Legislation');
$form = id(new PhabricatorApplicationTransactionCommentView()) $form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user) ->setUser($viewer)
->setObjectPHID($document->getPHID()) ->setObjectPHID($document->getPHID())
->setFormID($comment_form_id) ->setFormID($comment_form_id)
->setHeaderText($title) ->setHeaderText($title)

View file

@ -2,23 +2,17 @@
final class LegalpadDocumentSignatureListController extends LegalpadController { final class LegalpadDocumentSignatureListController extends LegalpadController {
private $documentID;
private $queryKey;
private $document; private $document;
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->documentID = idx($data, 'id'); $viewer = $request->getViewer();
$this->queryKey = idx($data, 'queryKey'); $id = $request->getURIData('id');
} $querykey = $request->getURIData('queryKey');
public function processRequest() { if ($id) {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->documentID) {
$document = id(new LegalpadDocumentQuery()) $document = id(new LegalpadDocumentQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->documentID)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -39,7 +33,7 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
} }
$controller = id(new PhabricatorApplicationSearchController()) $controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey) ->setQueryKey($querykey)
->setSearchEngine($engine) ->setSearchEngine($engine)
->setNavigation($this->buildSideNav()); ->setNavigation($this->buildSideNav());
@ -47,13 +41,13 @@ final class LegalpadDocumentSignatureListController extends LegalpadController {
} }
public function buildSideNav($for_app = false) { public function buildSideNav($for_app = false) {
$user = $this->getRequest()->getUser(); $viewer = $this->getViewer();
$nav = new AphrontSideNavFilterView(); $nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$engine = id(new LegalpadDocumentSignatureSearchEngine()) $engine = id(new LegalpadDocumentSignatureSearchEngine())
->setViewer($user); ->setViewer($viewer);
if ($this->document) { if ($this->document) {
$engine->setDocument($this->document); $engine->setDocument($this->document);

View file

@ -3,25 +3,19 @@
final class LegalpadDocumentSignatureVerificationController final class LegalpadDocumentSignatureVerificationController
extends LegalpadController { extends LegalpadController {
private $code;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->code = $data['code']; $viewer = $request->getViewer();
} $code = $request->getURIData('code');
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
// NOTE: We're using the omnipotent user to handle logged-out signatures // NOTE: We're using the omnipotent user to handle logged-out signatures
// and corporate signatures. // and corporate signatures.
$signature = id(new LegalpadDocumentSignatureQuery()) $signature = id(new LegalpadDocumentSignatureQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withSecretKeys(array($this->code)) ->withSecretKeys(array($code))
->executeOne(); ->executeOne();
if (!$signature) { if (!$signature) {

View file

@ -2,19 +2,13 @@
final class LegalpadDocumentSignatureViewController extends LegalpadController { final class LegalpadDocumentSignatureViewController extends LegalpadController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$signature = id(new LegalpadDocumentSignatureQuery()) $signature = id(new LegalpadDocumentSignatureQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$signature) { if (!$signature) {
return new Aphront404Response(); return new Aphront404Response();