2013-12-09 08:24:50 +11:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhragmentSnapshotViewController extends PhragmentController {
|
|
|
|
|
2013-12-13 14:42:12 +11:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-02 14:24:40 +00:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2013-12-09 08:24:50 +11:00
|
|
|
|
|
|
|
$snapshot = id(new PhragmentSnapshotQuery())
|
|
|
|
->setViewer($viewer)
|
2016-04-02 14:24:40 +00:00
|
|
|
->withIDs(array($id))
|
2013-12-09 08:24:50 +11:00
|
|
|
->executeOne();
|
|
|
|
if ($snapshot === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$box = $this->createSnapshotView($snapshot);
|
|
|
|
|
|
|
|
$fragment = id(new PhragmentFragmentQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($snapshot->getPrimaryFragmentPHID()))
|
|
|
|
->executeOne();
|
|
|
|
if ($fragment === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parents = $this->loadParentFragments($fragment->getPath());
|
|
|
|
if ($parents === null) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb(pht('"%s" Snapshot', $snapshot->getName()));
|
2013-12-09 08:24:50 +11:00
|
|
|
|
|
|
|
$children = id(new PhragmentSnapshotChildQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->needFragments(true)
|
|
|
|
->needFragmentVersions(true)
|
|
|
|
->withSnapshotPHIDs(array($snapshot->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
->setHeader($child->getFragment()->getPath());
|
|
|
|
|
|
|
|
if ($child->getFragmentVersion() !== null) {
|
|
|
|
$item
|
|
|
|
->setHref($child->getFragmentVersion()->getURI())
|
|
|
|
->addAttribute(pht(
|
|
|
|
'Version %s',
|
|
|
|
$child->getFragmentVersion()->getSequence()));
|
|
|
|
} else {
|
|
|
|
$item
|
|
|
|
->setHref($child->getFragment()->getURI())
|
|
|
|
->addAttribute(pht('Directory'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
2016-04-02 14:24:40 +00:00
|
|
|
$title = pht('View Snapshot');
|
|
|
|
|
|
|
|
$view = array(
|
|
|
|
$this->renderConfigurationWarningIfRequired(),
|
|
|
|
$box,
|
|
|
|
$list,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
2013-12-09 08:24:50 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function createSnapshotView($snapshot) {
|
|
|
|
if ($snapshot === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('"%s" Snapshot', $snapshot->getName()))
|
|
|
|
->setPolicyObject($snapshot)
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$zip_uri = $this->getApplicationURI(
|
2014-06-09 11:36:49 -07:00
|
|
|
'zip@'.$snapshot->getName().
|
|
|
|
'/'.$snapshot->getPrimaryFragment()->getPath());
|
2013-12-09 08:24:50 +11:00
|
|
|
|
2013-12-13 14:42:12 +11:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$snapshot,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2013-12-09 08:24:50 +11:00
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
Remove all setObjectURI() from ActionListViews
Summary:
Ref T10004. After D14804, we get this behavior by default and no longer need to set it explicitly.
(If some endpoint did eventually need to set it explicitly, it could just change what it passes to `setHref()`, but I believe we currently have no such endpoints and do not foresee ever having any.)
Test Plan:
- As a logged out user, clicked various links in Differential, Maniphest, Files, etc., always got redirected to a sensible place after login.
- Grepped for `setObjectURI()`, `getObjectURI()` (there are a few remaining callsites, but to a different method with the same name in Doorkeeper).
Reviewers: chad
Reviewed By: chad
Subscribers: hach-que
Maniphest Tasks: T10004
Differential Revision: https://secure.phabricator.com/D14805
2015-12-17 06:31:33 -08:00
|
|
|
->setObject($snapshot);
|
2013-12-09 08:24:50 +11:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Download Snapshot as ZIP'))
|
2013-12-13 14:42:12 +11:00
|
|
|
->setHref($this->isCorrectlyConfigured() ? $zip_uri : null)
|
|
|
|
->setDisabled(!$this->isCorrectlyConfigured())
|
2014-05-13 07:45:39 -07:00
|
|
|
->setIcon('fa-floppy-o'));
|
2013-12-09 08:24:50 +11:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Delete Snapshot'))
|
|
|
|
->setHref($this->getApplicationURI(
|
2014-06-09 11:36:49 -07:00
|
|
|
'snapshot/delete/'.$snapshot->getID().'/'))
|
2013-12-13 14:42:12 +11:00
|
|
|
->setDisabled(!$can_edit)
|
2013-12-09 08:24:50 +11:00
|
|
|
->setWorkflow(true)
|
2014-05-13 07:45:39 -07:00
|
|
|
->setIcon('fa-times'));
|
2013-12-09 08:24:50 +11:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Promote Another Snapshot to Here'))
|
|
|
|
->setHref($this->getApplicationURI(
|
2014-06-09 11:36:49 -07:00
|
|
|
'snapshot/promote/'.$snapshot->getID().'/'))
|
2013-12-13 14:42:12 +11:00
|
|
|
->setDisabled(!$can_edit)
|
2013-12-09 08:24:50 +11:00
|
|
|
->setWorkflow(true)
|
2014-05-13 07:45:39 -07:00
|
|
|
->setIcon('fa-arrow-up'));
|
2013-12-09 08:24:50 +11:00
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($snapshot)
|
|
|
|
->setActionList($actions);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Name'),
|
|
|
|
$snapshot->getName());
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Fragment'),
|
2015-03-30 06:35:32 -07:00
|
|
|
$viewer->renderHandle($snapshot->getPrimaryFragmentPHID()));
|
2013-12-09 08:24:50 +11:00
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
}
|
|
|
|
}
|