2013-07-03 20:15:45 +02:00
|
|
|
<?php
|
|
|
|
|
2014-06-26 03:38:07 +02:00
|
|
|
final class LegalpadDocumentManageController extends LegalpadController {
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2014-06-26 03:38:07 +02:00
|
|
|
// NOTE: We require CAN_EDIT to view this page.
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
$document = id(new LegalpadDocumentQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->needDocumentBodies(true)
|
|
|
|
->needContributors(true)
|
2014-06-26 03:38:07 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2013-07-03 20:15:45 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$document) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions = id(new LegalpadTransactionQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withObjectPHIDs(array($document->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
|
|
|
$document->getPHID());
|
|
|
|
|
|
|
|
$document_body = $document->getDocumentBody();
|
|
|
|
$phids = array();
|
|
|
|
$phids[] = $document_body->getCreatorPHID();
|
|
|
|
foreach ($subscribers as $subscriber) {
|
|
|
|
$phids[] = $subscriber;
|
|
|
|
}
|
|
|
|
foreach ($document->getContributors() as $contributor) {
|
|
|
|
$phids[] = $contributor;
|
|
|
|
}
|
|
|
|
$this->loadHandles($phids);
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
->setViewer($user);
|
|
|
|
$engine->addObject(
|
|
|
|
$document_body,
|
|
|
|
LegalpadDocumentBody::MARKUP_FIELD_TEXT);
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
if ($xaction->getComment()) {
|
|
|
|
$engine->addObject(
|
|
|
|
$xaction->getComment(),
|
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$engine->process();
|
|
|
|
|
|
|
|
$title = $document_body->getTitle();
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-09-18 23:50:39 +02:00
|
|
|
->setHeader($title)
|
2013-09-19 20:56:58 +02:00
|
|
|
->setUser($user)
|
|
|
|
->setPolicyObject($document);
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$actions = $this->buildActionView($document);
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyView($document, $engine, $actions);
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$comment_form_id = celerity_generate_unique_node_id();
|
|
|
|
|
|
|
|
$xaction_view = id(new LegalpadTransactionView())
|
|
|
|
->setUser($this->getRequest()->getUser())
|
2013-07-29 03:21:22 +02:00
|
|
|
->setObjectPHID($document->getPHID())
|
2013-07-03 20:15:45 +02:00
|
|
|
->setTransactions($xactions)
|
|
|
|
->setMarkupEngine($engine);
|
|
|
|
|
|
|
|
$add_comment = $this->buildAddCommentView($document, $comment_form_id);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNav());
|
|
|
|
$crumbs->setActionList($actions);
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(
|
2014-01-16 23:36:57 +01:00
|
|
|
$document->getMonogram(),
|
2014-06-26 03:38:07 +02:00
|
|
|
'/'.$document->getMonogram());
|
|
|
|
$crumbs->addTextCrumb(pht('Manage'));
|
2013-07-03 20:15:45 +02:00
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-30 20:45:13 +01:00
|
|
|
->addPropertyList($properties)
|
|
|
|
->addPropertyList($this->buildDocument($engine, $document_body));
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
$content = array(
|
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2013-07-03 20:15:45 +02:00
|
|
|
$xaction_view,
|
|
|
|
$add_comment,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$content,
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'pageObjects' => array($document->getPHID()),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildDocument(
|
|
|
|
PhabricatorMarkupEngine
|
|
|
|
$engine, LegalpadDocumentBody $body) {
|
|
|
|
|
2013-10-30 20:45:13 +01:00
|
|
|
$view = new PHUIPropertyListView();
|
2014-01-24 21:50:33 +01:00
|
|
|
$view->addClass('legalpad');
|
2013-10-30 20:45:13 +01:00
|
|
|
$view->addSectionHeader(pht('Document'));
|
|
|
|
$view->addTextContent(
|
2013-07-03 20:15:45 +02:00
|
|
|
$engine->getOutput($body, LegalpadDocumentBody::MARKUP_FIELD_TEXT));
|
|
|
|
|
2013-10-30 20:45:13 +01:00
|
|
|
return $view;
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionView(LegalpadDocument $document) {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($user)
|
2013-07-12 20:39:47 +02:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2013-07-03 20:15:45 +02:00
|
|
|
->setObject($document);
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$user,
|
|
|
|
$document,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2014-01-17 20:40:26 +01:00
|
|
|
$doc_id = $document->getID();
|
|
|
|
|
2014-06-26 03:38:07 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-pencil-square')
|
|
|
|
->setName(pht('View/Sign Document'))
|
|
|
|
->setHref('/'.$document->getMonogram()));
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-pencil')
|
2013-07-03 20:15:45 +02:00
|
|
|
->setName(pht('Edit Document'))
|
2014-01-17 20:40:26 +01:00
|
|
|
->setHref($this->getApplicationURI('/edit/'.$doc_id.'/'))
|
2013-07-03 20:15:45 +02:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
2014-01-17 20:40:26 +01:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 19:08:32 +02:00
|
|
|
->setIcon('fa-terminal')
|
2014-01-17 20:40:26 +01:00
|
|
|
->setName(pht('View Signatures'))
|
|
|
|
->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyView(
|
|
|
|
LegalpadDocument $document,
|
2013-10-11 16:53:56 +02:00
|
|
|
PhabricatorMarkupEngine $engine,
|
|
|
|
PhabricatorActionListView $actions) {
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = id(new PHUIPropertyListView())
|
2013-07-03 20:15:45 +02:00
|
|
|
->setUser($user)
|
2013-10-11 16:53:56 +02:00
|
|
|
->setObject($document)
|
|
|
|
->setActionList($actions);
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Last Updated'),
|
|
|
|
phabricator_datetime($document->getDateModified(), $user));
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Updated By'),
|
|
|
|
$this->getHandle(
|
|
|
|
$document->getDocumentBody()->getCreatorPHID())->renderLink());
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Versions'),
|
|
|
|
$document->getVersions());
|
|
|
|
|
|
|
|
$contributor_view = array();
|
|
|
|
foreach ($document->getContributors() as $contributor) {
|
|
|
|
$contributor_view[] = $this->getHandle($contributor)->renderLink();
|
|
|
|
}
|
|
|
|
$contributor_view = phutil_implode_html(', ', $contributor_view);
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Contributors'),
|
|
|
|
$contributor_view);
|
|
|
|
|
|
|
|
$properties->invokeWillRenderEvent();
|
|
|
|
|
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildAddCommentView(
|
|
|
|
LegalpadDocument $document,
|
|
|
|
$comment_form_id) {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$draft = PhabricatorDraft::newFromUserAndKey($user, $document->getPHID());
|
|
|
|
|
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
|
|
|
|
$title = $is_serious
|
|
|
|
? pht('Add Comment')
|
|
|
|
: pht('Debate Legislation');
|
|
|
|
|
|
|
|
$form = id(new PhabricatorApplicationTransactionCommentView())
|
|
|
|
->setUser($user)
|
2013-07-29 03:21:22 +02:00
|
|
|
->setObjectPHID($document->getPHID())
|
2013-07-03 20:15:45 +02:00
|
|
|
->setFormID($comment_form_id)
|
2013-11-22 01:09:04 +01:00
|
|
|
->setHeaderText($title)
|
2013-07-03 20:15:45 +02:00
|
|
|
->setDraft($draft)
|
2014-04-19 02:51:46 +02:00
|
|
|
->setSubmitButtonName(pht('Add Comment'))
|
2013-07-03 20:15:45 +02:00
|
|
|
->setAction($this->getApplicationURI('/comment/'.$document->getID().'/'))
|
|
|
|
->setRequestURI($this->getRequest()->getRequestURI());
|
|
|
|
|
2013-11-22 01:09:04 +01:00
|
|
|
return $form;
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|