1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +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 {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$document = id(new LegalpadDocumentQuery())
->setViewer($user)
->withIDs(array($this->id))
->setViewer($viewer)
->withIDs(array($id))
->needDocumentBodies(true)
->executeOne();
@ -48,7 +42,7 @@ final class LegalpadDocumentCommentController extends LegalpadController {
}
$editor = id(new LegalpadDocumentEditor())
->setActor($user)
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect($request->isContinueRequest())
->setIsPreview($is_preview);
@ -67,7 +61,7 @@ final class LegalpadDocumentCommentController extends LegalpadController {
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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