diff --git a/src/applications/legalpad/controller/LegalpadDocumentEditController.php b/src/applications/legalpad/controller/LegalpadDocumentEditController.php --- a/src/applications/legalpad/controller/LegalpadDocumentEditController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentEditController.php @@ -97,8 +97,8 @@ if (!$user->getIsAdmin()) { $errors[] = pht('Only admins may require signature.'); } - $corp = LegalpadDocument::SIGNATURE_TYPE_CORPORATION; - if ($v_signature_type == $corp) { + $individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL; + if ($v_signature_type != $individual) { $errors[] = pht( 'Only documents with signature type "individual" may require '. 'signing to use Phabricator.'); @@ -147,6 +147,7 @@ ->setValue($v_signature_type) ->setOptions(LegalpadDocument::getSignatureTypeMap())); $show_require = true; + $caption = pht('Applies only to documents individuals sign.'); } else { $form->appendChild( id(new AphrontFormMarkupControl()) @@ -154,6 +155,7 @@ ->setValue($document->getSignatureTypeName())); $individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL; $show_require = $document->getSignatureType() == $individual; + $caption = null; } if ($show_require) { @@ -166,9 +168,9 @@ 'requireSignature', 'requireSignature', pht( - 'Should signing this document be required to use Phabricator? '. - 'Applies to invidivuals only.'), - $v_require_signature)); + 'Should signing this document be required to use Phabricator?'), + $v_require_signature) + ->setCaption($caption)); } $form diff --git a/src/applications/legalpad/controller/LegalpadDocumentSignController.php b/src/applications/legalpad/controller/LegalpadDocumentSignController.php --- a/src/applications/legalpad/controller/LegalpadDocumentSignController.php +++ b/src/applications/legalpad/controller/LegalpadDocumentSignController.php @@ -26,109 +26,120 @@ $type_individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL; $is_individual = ($document->getSignatureType() == $type_individual); - if ($is_individual) { - if ($signer_phid) { - // TODO: This is odd and should probably be adjusted after grey/external - // accounts work better, but use the omnipotent viewer to check for a - // signature so we can pick up anonymous/grey signatures. - - $signature = id(new LegalpadDocumentSignatureQuery()) - ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->withDocumentPHIDs(array($document->getPHID())) - ->withSignerPHIDs(array($signer_phid)) - ->executeOne(); - - if ($signature && !$viewer->isLoggedIn()) { + switch ($document->getSignatureType()) { + case LegalpadDocument::SIGNATURE_TYPE_NONE: + // nothing to sign means this should be true + $has_signed = true; + // this is a status UI element + $signed_status = null; + break; + case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL: + if ($signer_phid) { + // TODO: This is odd and should probably be adjusted after + // grey/external accounts work better, but use the omnipotent + // viewer to check for a signature so we can pick up + // anonymous/grey signatures. + + $signature = id(new LegalpadDocumentSignatureQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withDocumentPHIDs(array($document->getPHID())) + ->withSignerPHIDs(array($signer_phid)) + ->executeOne(); + + if ($signature && !$viewer->isLoggedIn()) { return $this->newDialog() ->setTitle(pht('Already Signed')) ->appendParagraph(pht('You have already signed this document!')) ->addCancelButton('/'.$document->getMonogram(), pht('Okay')); + } } - } - $signed_status = null; - if (!$signature) { - $has_signed = false; - $signature = id(new LegalpadDocumentSignature()) - ->setSignerPHID($signer_phid) - ->setDocumentPHID($document->getPHID()) - ->setDocumentVersion($document->getVersions()); + $signed_status = null; + if (!$signature) { + $has_signed = false; + $signature = id(new LegalpadDocumentSignature()) + ->setSignerPHID($signer_phid) + ->setDocumentPHID($document->getPHID()) + ->setDocumentVersion($document->getVersions()); + + // If the user is logged in, show a notice that they haven't signed. + // If they aren't logged in, we can't be as sure, so don't show + // anything. + if ($viewer->isLoggedIn()) { + $signed_status = id(new PHUIErrorView()) + ->setSeverity(PHUIErrorView::SEVERITY_WARNING) + ->setErrors( + array( + pht('You have not signed this document yet.'), + )); + } + } else { + $has_signed = true; + $signature_data = $signature->getSignatureData(); + + // In this case, we know they've signed. + $signed_at = $signature->getDateCreated(); + + if ($signature->getIsExemption()) { + $exemption_phid = $signature->getExemptionPHID(); + $handles = $this->loadViewerHandles(array($exemption_phid)); + $exemption_handle = $handles[$exemption_phid]; + + $signed_text = pht( + 'You do not need to sign this document. '. + '%s added a signature exemption for you on %s.', + $exemption_handle->renderLink(), + phabricator_datetime($signed_at, $viewer)); + } else { + $signed_text = pht( + 'You signed this document on %s.', + phabricator_datetime($signed_at, $viewer)); + } - // If the user is logged in, show a notice that they haven't signed. - // If they aren't logged in, we can't be as sure, so don't show - // anything. - if ($viewer->isLoggedIn()) { $signed_status = id(new PHUIErrorView()) - ->setSeverity(PHUIErrorView::SEVERITY_WARNING) - ->setErrors( - array( - pht('You have not signed this document yet.'), - )); + ->setSeverity(PHUIErrorView::SEVERITY_NOTICE) + ->setErrors(array($signed_text)); } - } else { - $has_signed = true; - $signature_data = $signature->getSignatureData(); - - // In this case, we know they've signed. - $signed_at = $signature->getDateCreated(); - - if ($signature->getIsExemption()) { - $exemption_phid = $signature->getExemptionPHID(); - $handles = $this->loadViewerHandles(array($exemption_phid)); - $exemption_handle = $handles[$exemption_phid]; - $signed_text = pht( - 'You do not need to sign this document. '. - '%s added a signature exemption for you on %s.', - $exemption_handle->renderLink(), - phabricator_datetime($signed_at, $viewer)); - } else { - $signed_text = pht( - 'You signed this document on %s.', - phabricator_datetime($signed_at, $viewer)); - } - - $signed_status = id(new PHUIErrorView()) - ->setSeverity(PHUIErrorView::SEVERITY_NOTICE) - ->setErrors(array($signed_text)); - } + $field_errors = array( + 'name' => true, + 'email' => true, + 'agree' => true, + ); + $signature->setSignatureData($signature_data); + break; - $field_errors = array( - 'name' => true, - 'email' => true, - 'agree' => true, - ); - } else { - $signature = id(new LegalpadDocumentSignature()) - ->setDocumentPHID($document->getPHID()) - ->setDocumentVersion($document->getVersions()); + case LegalpadDocument::SIGNATURE_TYPE_CORPORATION: + $signature = id(new LegalpadDocumentSignature()) + ->setDocumentPHID($document->getPHID()) + ->setDocumentVersion($document->getVersions()); - if ($viewer->isLoggedIn()) { - $has_signed = false; + if ($viewer->isLoggedIn()) { + $has_signed = false; - $signed_status = null; - } else { - // This just hides the form. - $has_signed = true; + $signed_status = null; + } else { + // This just hides the form. + $has_signed = true; - $login_text = pht( - 'This document requires a corporate signatory. You must log in to '. - 'accept this document on behalf of a company you represent.'); - $signed_status = id(new PHUIErrorView()) - ->setSeverity(PHUIErrorView::SEVERITY_WARNING) - ->setErrors(array($login_text)); - } + $login_text = pht( + 'This document requires a corporate signatory. You must log in to '. + 'accept this document on behalf of a company you represent.'); + $signed_status = id(new PHUIErrorView()) + ->setSeverity(PHUIErrorView::SEVERITY_WARNING) + ->setErrors(array($login_text)); + } - $field_errors = array( - 'name' => true, - 'address' => true, - 'contact.name' => true, - 'email' => true, - ); + $field_errors = array( + 'name' => true, + 'address' => true, + 'contact.name' => true, + 'email' => true, + ); + $signature->setSignatureData($signature_data); + break; } - $signature->setSignatureData($signature_data); - $errors = array(); if ($request->isFormOrHisecPost() && !$has_signed) { @@ -256,9 +267,17 @@ $signature, $field_errors); - $subheader = id(new PHUIHeaderView()) - ->setHeader(pht('Agree and Sign Document')) - ->setBleedHeader(true); + switch ($document->getSignatureType()) { + case LegalpadDocument::SIGNATURE_TYPE_NONE: + $subheader = null; + break; + case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL: + case LegalpadDocument::SIGNATURE_TYPE_CORPORATION: + $subheader = id(new PHUIHeaderView()) + ->setHeader(pht('Agree and Sign Document')) + ->setBleedHeader(true); + break; + } $content->appendChild( array( @@ -292,6 +311,8 @@ $signature_data = array(); switch ($document->getSignatureType()) { + case LegalpadDocument::SIGNATURE_TYPE_NONE: + break; case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL: if ($viewer->isLoggedIn()) { $signer_phid = $viewer->getPHID(); @@ -348,6 +369,9 @@ $signature_type = $document->getSignatureType(); switch ($signature_type) { + case LegalpadDocument::SIGNATURE_TYPE_NONE: + // bail out of here quick + return; case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL: $this->buildIndividualSignatureForm( $form, diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -20,7 +20,8 @@ protected $preamble; protected $requireSignature; - const SIGNATURE_TYPE_INDIVIDUAL = 'user'; + const SIGNATURE_TYPE_NONE = 'none'; + const SIGNATURE_TYPE_INDIVIDUAL = 'user'; const SIGNATURE_TYPE_CORPORATION = 'corp'; private $documentBody = self::ATTACHABLE; @@ -134,6 +135,7 @@ return array( self::SIGNATURE_TYPE_INDIVIDUAL => pht('Individuals'), self::SIGNATURE_TYPE_CORPORATION => pht('Corporations'), + self::SIGNATURE_TYPE_NONE => pht('No One'), ); } @@ -145,6 +147,7 @@ public function getSignatureTypeIcon() { $type = $this->getSignatureType(); $map = array( + self::SIGNATURE_TYPE_NONE => '', self::SIGNATURE_TYPE_INDIVIDUAL => 'fa-user grey', self::SIGNATURE_TYPE_CORPORATION => 'fa-building-o grey', );