diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fba9a50375..17e83263eb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -863,6 +863,7 @@ phutil_register_library_map(array( 'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php', 'LegalpadDocumentEditor' => 'applications/legalpad/editor/LegalpadDocumentEditor.php', 'LegalpadDocumentListController' => 'applications/legalpad/controller/LegalpadDocumentListController.php', + 'LegalpadDocumentManageController' => 'applications/legalpad/controller/LegalpadDocumentManageController.php', 'LegalpadDocumentQuery' => 'applications/legalpad/query/LegalpadDocumentQuery.php', 'LegalpadDocumentRemarkupRule' => 'applications/legalpad/remarkup/LegalpadDocumentRemarkupRule.php', 'LegalpadDocumentSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSearchEngine.php', @@ -871,7 +872,6 @@ phutil_register_library_map(array( 'LegalpadDocumentSignatureListController' => 'applications/legalpad/controller/LegalpadDocumentSignatureListController.php', 'LegalpadDocumentSignatureQuery' => 'applications/legalpad/query/LegalpadDocumentSignatureQuery.php', 'LegalpadDocumentSignatureVerificationController' => 'applications/legalpad/controller/LegalpadDocumentSignatureVerificationController.php', - 'LegalpadDocumentViewController' => 'applications/legalpad/controller/LegalpadDocumentViewController.php', 'LegalpadMockMailReceiver' => 'applications/legalpad/mail/LegalpadMockMailReceiver.php', 'LegalpadReplyHandler' => 'applications/legalpad/mail/LegalpadReplyHandler.php', 'LegalpadTransaction' => 'applications/legalpad/storage/LegalpadTransaction.php', @@ -3616,6 +3616,7 @@ phutil_register_library_map(array( 'LegalpadDocumentEditController' => 'LegalpadController', 'LegalpadDocumentEditor' => 'PhabricatorApplicationTransactionEditor', 'LegalpadDocumentListController' => 'LegalpadController', + 'LegalpadDocumentManageController' => 'LegalpadController', 'LegalpadDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'LegalpadDocumentRemarkupRule' => 'PhabricatorRemarkupRuleObject', 'LegalpadDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine', @@ -3628,7 +3629,6 @@ phutil_register_library_map(array( 'LegalpadDocumentSignatureListController' => 'LegalpadController', 'LegalpadDocumentSignatureQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'LegalpadDocumentSignatureVerificationController' => 'LegalpadController', - 'LegalpadDocumentViewController' => 'LegalpadController', 'LegalpadMockMailReceiver' => 'PhabricatorObjectMailReceiver', 'LegalpadReplyHandler' => 'PhabricatorMailReplyHandler', 'LegalpadTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php index a8d8d8302c..f39f3ff265 100644 --- a/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php +++ b/src/applications/legalpad/application/PhabricatorApplicationLegalpad.php @@ -45,7 +45,7 @@ final class PhabricatorApplicationLegalpad extends PhabricatorApplication { 'create/' => 'LegalpadDocumentEditController', 'edit/(?P\d+)/' => 'LegalpadDocumentEditController', 'comment/(?P\d+)/' => 'LegalpadDocumentCommentController', - 'view/(?P\d+)/' => 'LegalpadDocumentViewController', + 'view/(?P\d+)/' => 'LegalpadDocumentManageController', 'verify/(?P[^/]+)/' => 'LegalpadDocumentSignatureVerificationController', 'signatures/(?P\d+)/' => 'LegalpadDocumentSignatureListController', diff --git a/src/applications/legalpad/controller/LegalpadController.php b/src/applications/legalpad/controller/LegalpadController.php index 87f7ad7a62..1715b4c400 100644 --- a/src/applications/legalpad/controller/LegalpadController.php +++ b/src/applications/legalpad/controller/LegalpadController.php @@ -22,18 +22,6 @@ abstract class LegalpadController extends PhabricatorController { return $nav; } - public function buildApplicationCrumbs() { - $crumbs = parent::buildApplicationCrumbs(); - - $crumbs->addAction( - id(new PHUIListItemView()) - ->setName(pht('Create Document')) - ->setHref($this->getApplicationURI('create/')) - ->setIcon('fa-plus-square')); - - return $crumbs; - } - public function buildApplicationMenu() { return $this->buildSideNav(true)->getMenu(); } diff --git a/src/applications/legalpad/controller/LegalpadDocumentListController.php b/src/applications/legalpad/controller/LegalpadDocumentListController.php index 20c425d2d8..f9baffe81d 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentListController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentListController.php @@ -18,4 +18,16 @@ final class LegalpadDocumentListController extends LegalpadController { return $this->delegateToController($controller); } + public function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $crumbs->addAction( + id(new PHUIListItemView()) + ->setName(pht('Create Document')) + ->setHref($this->getApplicationURI('create/')) + ->setIcon('fa-plus-square')); + + return $crumbs; + } + } diff --git a/src/applications/legalpad/controller/LegalpadDocumentViewController.php b/src/applications/legalpad/controller/LegalpadDocumentManageController.php similarity index 93% rename from src/applications/legalpad/controller/LegalpadDocumentViewController.php rename to src/applications/legalpad/controller/LegalpadDocumentManageController.php index ab15fe0a8c..4823384059 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentViewController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentManageController.php @@ -1,9 +1,6 @@ getRequest(); $user = $request->getUser(); + // NOTE: We require CAN_EDIT to view this page. + $document = id(new LegalpadDocumentQuery()) ->setViewer($user) ->withIDs(array($this->id)) ->needDocumentBodies(true) ->needContributors(true) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) ->executeOne(); - if (!$document) { return new Aphront404Response(); } @@ -83,7 +86,8 @@ final class LegalpadDocumentViewController extends LegalpadController { $crumbs->setActionList($actions); $crumbs->addTextCrumb( $document->getMonogram(), - $this->getApplicationURI('view/'.$document->getID())); + '/'.$document->getMonogram()); + $crumbs->addTextCrumb(pht('Manage')); $object_box = id(new PHUIObjectBoxView()) ->setHeader($header) @@ -134,6 +138,12 @@ final class LegalpadDocumentViewController extends LegalpadController { $doc_id = $document->getID(); + $actions->addAction( + id(new PhabricatorActionView()) + ->setIcon('fa-pencil-square') + ->setName(pht('View/Sign Document')) + ->setHref('/'.$document->getMonogram())); + $actions->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') @@ -142,12 +152,6 @@ final class LegalpadDocumentViewController extends LegalpadController { ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); - $actions->addAction( - id(new PhabricatorActionView()) - ->setIcon('fa-pencil-square') - ->setName(pht('Sign Document')) - ->setHref('/'.$document->getMonogram())); - $actions->addAction( id(new PhabricatorActionView()) ->setIcon('fa-terminal') diff --git a/src/applications/legalpad/controller/LegalpadDocumentSignController.php b/src/applications/legalpad/controller/LegalpadDocumentSignController.php index 34f4b6e13c..6c84b235b1 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentSignController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentSignController.php @@ -14,10 +14,10 @@ final class LegalpadDocumentSignController extends LegalpadController { public function processRequest() { $request = $this->getRequest(); - $user = $request->getUser(); + $viewer = $request->getUser(); $document = id(new LegalpadDocumentQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withIDs(array($this->id)) ->needDocumentBodies(true) ->executeOne(); @@ -29,10 +29,10 @@ final class LegalpadDocumentSignController extends LegalpadController { $signer_phid = null; $signature = null; $signature_data = array(); - if ($user->isLoggedIn()) { - $signer_phid = $user->getPHID(); + if ($viewer->isLoggedIn()) { + $signer_phid = $viewer->getPHID(); $signature_data = array( - 'email' => $user->loadPrimaryEmailAddress()); + 'email' => $viewer->loadPrimaryEmailAddress()); } else if ($request->isFormPost()) { $email = new PhutilEmailAddress($request->getStr('email')); $email_obj = id(new PhabricatorUserEmail()) @@ -41,7 +41,7 @@ final class LegalpadDocumentSignController extends LegalpadController { return $this->signInResponse(); } $external_account = id(new PhabricatorExternalAccountQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withAccountTypes(array('email')) ->withAccountDomains(array($email->getDomainName())) ->withAccountIDs(array($email->getAddress())) @@ -54,7 +54,7 @@ final class LegalpadDocumentSignController extends LegalpadController { if ($signer_phid) { $signature = id(new LegalpadDocumentSignatureQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withDocumentPHIDs(array($document->getPHID())) ->withSignerPHIDs(array($signer_phid)) ->withDocumentVersions(array($document->getVersions())) @@ -132,10 +132,10 @@ final class LegalpadDocumentSignController extends LegalpadController { } $verified = LegalpadDocumentSignature::UNVERIFIED; - if ($user->isLoggedIn() && $addr_obj) { + if ($viewer->isLoggedIn() && $addr_obj) { $email_obj = id(new PhabricatorUserEmail()) ->loadOneWhere('address = %s', $addr_obj->getAddress()); - if ($email_obj && $email_obj->getUserPHID() == $user->getPHID()) { + if ($email_obj && $email_obj->getUserPHID() == $viewer->getPHID()) { $verified = LegalpadDocumentSignature::VERIFIED; } } @@ -165,7 +165,7 @@ final class LegalpadDocumentSignController extends LegalpadController { $document_body = $document->getDocumentBody(); $engine = id(new PhabricatorMarkupEngine()) - ->setViewer($user); + ->setViewer($viewer); $engine->addObject( $document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT); @@ -173,8 +173,25 @@ final class LegalpadDocumentSignController extends LegalpadController { $title = $document_body->getTitle(); + $manage_uri = $this->getApplicationURI('view/'.$document->getID().'/'); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $document, + PhabricatorPolicyCapability::CAN_EDIT); + $header = id(new PHUIHeaderView()) - ->setHeader($title); + ->setHeader($title) + ->addActionLink( + id(new PHUIButtonView()) + ->setTag('a') + ->setIcon( + id(new PHUIIconView()) + ->setIconFont('fa-pencil')) + ->setText(pht('Manage Document')) + ->setHref($manage_uri) + ->setDisabled(!$can_edit) + ->setWorkflow(!$can_edit)); $content = array( $this->buildDocument( @@ -190,8 +207,14 @@ final class LegalpadDocumentSignController extends LegalpadController { $e_address_1, $error_view)); + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb($document->getMonogram()); + return $this->buildApplicationPage( - $content, + array( + $crumbs, + $content, + ), array( 'title' => $title, 'pageObjects' => array($document->getPHID()), @@ -220,7 +243,7 @@ final class LegalpadDocumentSignController extends LegalpadController { $e_address_1 = true, $error_view = null) { - $user = $this->getRequest()->getUser(); + $viewer = $this->getRequest()->getUser(); if ($has_signed) { $instructions = pht('Thank you for signing and agreeing.'); } else { @@ -229,7 +252,7 @@ final class LegalpadDocumentSignController extends LegalpadController { $data = $signature->getSignatureData(); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Name')) @@ -282,6 +305,7 @@ final class LegalpadDocumentSignController extends LegalpadController { if ($error_view) { $view->setErrorView($error_view); } + return $view; } diff --git a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php index 72270e6ac3..71b166d8ea 100644 --- a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php +++ b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php @@ -132,9 +132,9 @@ final class LegalpadDocumentSearchEngine $title = $document->getTitle(); $item = id(new PHUIObjectItemView()) - ->setObjectName('L'.$document->getID()) + ->setObjectName($document->getMonogram()) ->setHeader($title) - ->setHref($this->getApplicationURI('view/'.$document->getID())) + ->setHref('/'.$document->getMonogram()) ->setObject($document) ->addIcon('none', pht('Last updated: %s', $last_updated)) ->addByline(pht('Updated by: %s', $updater))