From c40420eb74659da7f2f0080f44acf4e21cddf456 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 16 Jan 2014 14:36:57 -0800 Subject: [PATCH] Legalpad - a few rough edges smoothed... Summary: does a few smallish things... Ref T3116 - adds an action to "sign document", thus improving visiblity of this feature from 0 to some value more than 0 - adds a crumb on the edit page to get back to the view page - warns the user on the edit page IFF signatures exist for the current version that their edits could invalidate those signatures - adds a "needSignatures" option to the Document Query class Test Plan: click the new UI elements and they worked. edited a document with signatures, noted warning UI, edited anyway, noted warning UI correctly disappeared on new edit. also verified a single signature had the correct translation Reviewers: epriestley Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T3116 Differential Revision: https://secure.phabricator.com/D7983 --- .../LegalpadDocumentEditController.php | 16 +++++++-- .../LegalpadDocumentViewController.php | 8 ++++- .../legalpad/query/LegalpadDocumentQuery.php | 33 +++++++++++++++++++ .../legalpad/storage/LegalpadDocument.php | 10 ++++++ .../PhabricatorBaseEnglishTranslation.php | 13 +++++++- 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/applications/legalpad/controller/LegalpadDocumentEditController.php b/src/applications/legalpad/controller/LegalpadDocumentEditController.php index dd5879dfe5..5e19a050c1 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentEditController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentEditController.php @@ -23,6 +23,7 @@ final class LegalpadDocumentEditController extends LegalpadController { ->setCreatorPHID($user->getPHID()) ->setContributorCount(0) ->setRecentContributorPHIDs(array()) + ->attachSignatures(array()) ->setViewPolicy(PhabricatorPolicies::POLICY_USER) ->setEditPolicy(PhabricatorPolicies::POLICY_USER); $body = id(new LegalpadDocumentBody()) @@ -37,6 +38,7 @@ final class LegalpadDocumentEditController extends LegalpadController { $document = id(new LegalpadDocumentQuery()) ->setViewer($user) ->needDocumentBodies(true) + ->needSignatures(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, @@ -147,6 +149,7 @@ final class LegalpadDocumentEditController extends LegalpadController { ->setPolicies($policies) ->setName('can_edit')); + $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); $submit = new AphrontFormSubmitControl(); if ($is_create) { $submit->setValue(pht('Create Document')); @@ -158,6 +161,17 @@ final class LegalpadDocumentEditController extends LegalpadController { $this->getApplicationURI('view/'.$document->getID())); $title = pht('Update Document'); $short = pht('Update'); + $signatures = $document->getSignatures(); + if ($signatures) { + $form->appendInstructions(pht( + 'Warning: there are %d signature(s) already for this document. '. + 'Updating the title or text will invalidate these signatures and '. + 'users will need to sign again. Proceed carefully.', + count($signatures))); + } + $crumbs->addTextCrumb( + $document->getMonogram(), + $this->getApplicationURI('view/'.$document->getID())); } $form @@ -168,10 +182,8 @@ final class LegalpadDocumentEditController extends LegalpadController { ->setFormErrors($errors) ->setForm($form); - $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); $crumbs->addTextCrumb($short); - $preview = id(new PHUIRemarkupPreviewPanel()) ->setHeader(pht('Document Preview')) ->setPreviewURI($this->getApplicationURI('document/preview/')) diff --git a/src/applications/legalpad/controller/LegalpadDocumentViewController.php b/src/applications/legalpad/controller/LegalpadDocumentViewController.php index 379a5f500e..40550ca358 100644 --- a/src/applications/legalpad/controller/LegalpadDocumentViewController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentViewController.php @@ -82,7 +82,7 @@ final class LegalpadDocumentViewController extends LegalpadController { $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); $crumbs->setActionList($actions); $crumbs->addTextCrumb( - 'L'.$document->getID(), + $document->getMonogram(), $this->getApplicationURI('view/'.$document->getID())); $object_box = id(new PHUIObjectBoxView()) @@ -140,6 +140,12 @@ final class LegalpadDocumentViewController extends LegalpadController { ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); + $actions->addAction( + id(new PhabricatorActionView()) + ->setIcon('like') + ->setName(pht('Sign Document')) + ->setHref('/'.$document->getMonogram())); + return $actions; } diff --git a/src/applications/legalpad/query/LegalpadDocumentQuery.php b/src/applications/legalpad/query/LegalpadDocumentQuery.php index ad076ee1f3..6316d70c0b 100644 --- a/src/applications/legalpad/query/LegalpadDocumentQuery.php +++ b/src/applications/legalpad/query/LegalpadDocumentQuery.php @@ -16,6 +16,7 @@ final class LegalpadDocumentQuery private $needDocumentBodies; private $needContributors; + private $needSignatures; public function withIDs(array $ids) { $this->ids = $ids; @@ -52,6 +53,11 @@ final class LegalpadDocumentQuery return $this; } + public function needSignatures($need_signatures) { + $this->needSignatures = $need_signatures; + return $this; + } + public function withDateCreatedBefore($date_created_before) { $this->dateCreatedBefore = $date_created_before; return $this; @@ -102,6 +108,7 @@ final class LegalpadDocumentQuery } } } + if ($this->needDocumentBodies) { $documents = $this->loadDocumentBodies($documents); } @@ -110,6 +117,10 @@ final class LegalpadDocumentQuery $documents = $this->loadContributors($documents); } + if ($this->needSignatures) { + $documents = $this->loadSignatures($documents); + } + return $documents; } @@ -208,6 +219,28 @@ final class LegalpadDocumentQuery return $documents; } + private function loadSignatures(array $documents) { + $document_map = mpull($documents, null, 'getPHID'); + + $signatures = id(new LegalpadDocumentSignature()) + ->loadAllWhere( + 'documentPHID IN (%Ls)', + array_keys($document_map)); + $signatures = mgroup($signatures, 'getDocumentPHID'); + + foreach ($documents as $document) { + $sigs = idx($signatures, $document->getPHID()); + foreach ($sigs as $index => $sig) { + if ($sig->getDocumentVersion() != $document->getVersions()) { + unset($sigs[$index]); + } + } + $document->attachSignatures($sigs); + } + + return $documents; + } + public function getQueryApplicationClass() { return 'PhabricatorApplicationLegalpad'; } diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php index 22a766f16f..1ed6445d91 100644 --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -21,6 +21,7 @@ final class LegalpadDocument extends LegalpadDAO private $documentBody = self::ATTACHABLE; private $contributors = self::ATTACHABLE; + private $signatures = self::ATTACHABLE; public function getConfiguration() { return array( @@ -54,6 +55,15 @@ final class LegalpadDocument extends LegalpadDAO return $this; } + public function getSignatures() { + return $this->assertAttached($this->signatures); + } + + public function attachSignatures(array $signatures) { + $this->signatures = $signatures; + return $this; + } + public function save() { if (!$this->getMailKey()) { $this->setMailKey(Filesystem::readRandomCharacters(20)); diff --git a/src/infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php b/src/infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php index 7a36a54f41..09a2cce336 100644 --- a/src/infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php +++ b/src/infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php @@ -815,7 +815,18 @@ abstract class PhabricatorBaseEnglishTranslation '%d Users Need Approval', ), + 'Warning: there are %d signature(s) already for this document. '. + 'Updating the title or text will invalidate these signatures and users '. + 'will need to sign again. Proceed carefully.' => array( + 'Warning: there is %d signature already for this document. '. + 'Updating the title or text will invalidate this signature and the '. + 'user will need to sign again. Proceed carefully.', + 'Warning: there are %d signatures already for this document. '. + 'Updating the title or text will invalidate these signatures and '. + 'users will need to sign again. Proceed carefully.', + ), + ); } -} + }