3 final class LegalpadDocumentSignatureAddController
extends LegalpadController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $request = $this->getRequest();
7 $viewer = $request->getUser();
9 $document = id(new LegalpadDocumentQuery())
11 ->needDocumentBodies(true)
12 ->requireCapabilities(
14 PhabricatorPolicyCapability
::CAN_VIEW
,
15 PhabricatorPolicyCapability
::CAN_EDIT
,
17 ->withIDs(array($request->getURIData('id')))
20 return new Aphront404Response();
23 $next_uri = $this->getApplicationURI('signatures/'.$document->getID().'/');
32 $type_individual = LegalpadDocument
::SIGNATURE_TYPE_INDIVIDUAL
;
33 $is_individual = ($document->getSignatureType() == $type_individual);
35 if ($request->isFormPost()) {
36 $v_notes = $request->getStr('notes');
37 $v_users = array_slice($request->getArr('users'), 0, 1);
38 $v_name = $request->getStr('name');
41 $user_phid = head($v_users);
43 $e_user = pht('Required');
44 $errors[] = pht('You must choose a user to exempt.');
46 $user = id(new PhabricatorPeopleQuery())
48 ->withPHIDs(array($user_phid))
52 $e_user = pht('Invalid');
53 $errors[] = pht('That user does not exist.');
55 $signature = id(new LegalpadDocumentSignatureQuery())
57 ->withDocumentPHIDs(array($document->getPHID()))
58 ->withSignerPHIDs(array($user->getPHID()))
61 $e_user = pht('Signed');
62 $errors[] = pht('That user has already signed this document.');
69 $company_name = $v_name;
70 if (!strlen($company_name)) {
71 $e_name = pht('Required');
72 $errors[] = pht('You must choose a company to add an exemption for.');
78 $name = $user->getRealName();
79 $email = $user->loadPrimaryEmailAddress();
80 $signer_phid = $user->getPHID();
81 $signature_data = array(
87 $name = $company_name;
90 $signature_data = array(
94 'actorPHID' => $viewer->getPHID(),
98 $signature = id(new LegalpadDocumentSignature())
99 ->setDocumentPHID($document->getPHID())
100 ->setDocumentVersion($document->getVersions())
101 ->setSignerPHID($signer_phid)
102 ->setSignerName($name)
103 ->setSignerEmail($email)
104 ->setSignatureType($document->getSignatureType())
106 ->setExemptionPHID($viewer->getPHID())
107 ->setVerified(LegalpadDocumentSignature
::VERIFIED
)
108 ->setSignatureData($signature_data);
112 return id(new AphrontRedirectResponse())->setURI($next_uri);
116 $form = id(new AphrontFormView())
119 if ($is_individual) {
122 id(new AphrontFormTokenizerControl())
123 ->setLabel(pht('Exempt User'))
126 ->setDatasource(new PhabricatorPeopleDatasource())
128 ->setError($e_user));
132 id(new AphrontFormTextControl())
133 ->setLabel(pht('Company Name'))
136 ->setValue($v_name));
141 id(new AphrontFormTextAreaControl())
142 ->setLabel(pht('Notes'))
144 ->setValue($v_notes));
146 return $this->newDialog()
147 ->setTitle(pht('Add Signature Exemption'))
148 ->setWidth(AphrontDialogView
::WIDTH_FORM
)
152 'You can record a signature exemption if a user has signed an '.
153 'equivalent document. Other applications will behave as through the '.
154 'user has signed this document.'))
155 ->appendParagraph(null)
156 ->appendChild($form->buildLayoutView())
157 ->addSubmitButton(pht('Add Exemption'))
158 ->addCancelButton($next_uri);