mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 19:02:41 +01:00
d403700e1f
Summary: Ref T7689. Ref T4100. This advances the goals of removing `loadViewerHandles()` (only 67 callsites remain!) and letting tokenizers some day take token functions like `viewer()` and `members(differential)`. Test Plan: - Sent a new message; used "To". - I simplified the cancel URI construction slightly because it's moot in all normal cases. - Edited a thread; used "Add Participants". - Searched rooms; used "Participants". - Searched countdowns; used "Authors". - Created a diff; used "Repository". - Edited a revision; edited "Projects"; edited "Reveiwers"; edited "Subscribers". - Searched for revisions; edited "responsible users"; "authors"; "reviwers"; "subscribers"; "repositories". - Added revision comments; edited "Add Reveiwers"; "Add Subscribers". - Commented on a commit; edited "Add Auditors"; "Add subscribers". - Edited a commit; edited "Projects". - Edited a repository; edited "Projects". - Searched feed, used "include Users"; "include Proejcts". - Searched files, used "authors". - Edited initiative; edited "Projects". - Searched backers; used "Backers". - Searched initiatives; used "Owners". - Edited build plans; edited "Run Command". - Searched Herald; used "Authors". - Added signature exemption in Legalpad. - Searhced legalpad; used "creators"; used "contributors". - Searched signatures; used "documents"; used "signers". - Created meme. - Searched macros; used "Authors". - Used "Projects" in Maniphest reports. - Used Maniphest comment actions. - Edited Maniphest tasks; edited "Assigned To"; edited "CC"; edited "projects". - Used "parent" in Maniphest task creation workflow. - Searched for projects; used "assigned to"; "in any projec"; "in all projects"; "not in projects"; "in users' projects"; "authors"; "subscribers". - Edited Maniphest bug filing domains, used "Default Author". - Searched for OAuth applications, used "Creators". - Edited Owners pacakge; edited "Primary Owner"; edited "Owners". - Searched for Owners packages; used "Owner". - OMG this UI is OLD - Edited a paste; edited "Projects". - Searched for paste; used "Authors". - Searched user activity log; used "Actors"; used "Users". - Edited a mock; edited "Projects"; edited "CC". - Searched for mocks; used "Authors". - Edited Phortune account; edited "Members". - Edited Phortune merchant account; edited "Members". - Searched Phrequent; used "Users". - Edited Ponder question; sued "projects". - Searched Ponder; used "Authors"; used "Answered By". - Added project members. - Searched for projects; used "Members". - Edited a Releeph product; edited "Pushers". - Searched pull requests; searched "Requestors". - Edited an arcanist project; used "Uses Symbols From". - Searhced push logs; used "Repositories"; used "Pushers". - Searched repositories; used "In nay project". - Used global search; used Authors/owners/Subscribers/In Any Project. - Edited a slowvote; used "Projects". - Searched slovotes; used "Authors". - Created a custom "Users" field; edited and searched for it. - Made a whole lot of typos in this list. ^^^^^^ Did not test: - Lint is nontrivial to test locally, I'll test it in production. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100, T7689 Differential Revision: https://secure.phabricator.com/D12224
161 lines
4.9 KiB
PHP
161 lines
4.9 KiB
PHP
<?php
|
|
|
|
final class LegalpadDocumentSignatureAddController extends LegalpadController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$document = id(new LegalpadDocumentQuery())
|
|
->setViewer($viewer)
|
|
->needDocumentBodies(true)
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->withIDs(array($request->getURIData('id')))
|
|
->executeOne();
|
|
if (!$document) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$next_uri = $this->getApplicationURI('signatures/'.$document->getID().'/');
|
|
|
|
$e_name = true;
|
|
$e_user = true;
|
|
$v_users = array();
|
|
$v_notes = '';
|
|
$v_name = '';
|
|
$errors = array();
|
|
|
|
$type_individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
|
|
$is_individual = ($document->getSignatureType() == $type_individual);
|
|
|
|
if ($request->isFormPost()) {
|
|
$v_notes = $request->getStr('notes');
|
|
$v_users = array_slice($request->getArr('users'), 0, 1);
|
|
$v_name = $request->getStr('name');
|
|
|
|
if ($is_individual) {
|
|
$user_phid = head($v_users);
|
|
if (!$user_phid) {
|
|
$e_user = pht('Required');
|
|
$errors[] = pht('You must choose a user to exempt.');
|
|
} else {
|
|
$user = id(new PhabricatorPeopleQuery())
|
|
->setViewer($viewer)
|
|
->withPHIDs(array($user_phid))
|
|
->executeOne();
|
|
|
|
if (!$user) {
|
|
$e_user = pht('Invalid');
|
|
$errors[] = pht('That user does not exist.');
|
|
} else {
|
|
$signature = id(new LegalpadDocumentSignatureQuery())
|
|
->setViewer($viewer)
|
|
->withDocumentPHIDs(array($document->getPHID()))
|
|
->withSignerPHIDs(array($user->getPHID()))
|
|
->executeOne();
|
|
if ($signature) {
|
|
$e_user = pht('Signed');
|
|
$errors[] = pht('That user has already signed this document.');
|
|
} else {
|
|
$e_user = null;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$company_name = $v_name;
|
|
if (!strlen($company_name)) {
|
|
$e_name = pht('Required');
|
|
$errors[] = pht('You must choose a company to add an exemption for.');
|
|
}
|
|
}
|
|
|
|
if (!$errors) {
|
|
if ($is_individual) {
|
|
$name = $user->getRealName();
|
|
$email = $user->loadPrimaryEmailAddress();
|
|
$signer_phid = $user->getPHID();
|
|
$signature_data = array(
|
|
'name' => $name,
|
|
'email' => $email,
|
|
'notes' => $v_notes,
|
|
);
|
|
} else {
|
|
$name = $company_name;
|
|
$email = '';
|
|
$signer_phid = null;
|
|
$signature_data = array(
|
|
'name' => $name,
|
|
'email' => null,
|
|
'notes' => $v_notes,
|
|
'actorPHID' => $viewer->getPHID(),
|
|
);
|
|
}
|
|
|
|
$signature = id(new LegalpadDocumentSignature())
|
|
->setDocumentPHID($document->getPHID())
|
|
->setDocumentVersion($document->getVersions())
|
|
->setSignerPHID($signer_phid)
|
|
->setSignerName($name)
|
|
->setSignerEmail($email)
|
|
->setSignatureType($document->getSignatureType())
|
|
->setIsExemption(1)
|
|
->setExemptionPHID($viewer->getPHID())
|
|
->setVerified(LegalpadDocumentSignature::VERIFIED)
|
|
->setSignatureData($signature_data);
|
|
|
|
$signature->save();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($next_uri);
|
|
}
|
|
}
|
|
|
|
$form = id(new AphrontFormView())
|
|
->setUser($viewer);
|
|
|
|
if ($is_individual) {
|
|
$form
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Exempt User'))
|
|
->setName('users')
|
|
->setLimit(1)
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
->setValue($v_users)
|
|
->setError($e_user));
|
|
} else {
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel(pht('Company Name'))
|
|
->setName('name')
|
|
->setError($e_name)
|
|
->setValue($v_name));
|
|
}
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTextAreaControl())
|
|
->setLabel(pht('Notes'))
|
|
->setName('notes')
|
|
->setValue($v_notes));
|
|
|
|
return $this->newDialog()
|
|
->setTitle(pht('Add Signature Exemption'))
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
->setErrors($errors)
|
|
->appendParagraph(
|
|
pht(
|
|
'You can record a signature exemption if a user has signed an '.
|
|
'equivalent document. Other applications will behave as through the '.
|
|
'user has signed this document.'))
|
|
->appendParagraph(null)
|
|
->appendChild($form->buildLayoutView())
|
|
->addSubmitButton(pht('Add Exemption'))
|
|
->addCancelButton($next_uri);
|
|
}
|
|
|
|
}
|