mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-03 20:22:46 +01:00
9838251515
Summary: Fixes T2691. Now, all PhabricatorActionListViews in the codebase setObjectHref to $request->getRequestURI. This value is passed over to PhabricatorActionItems right before they are rendered. If a PhabricatorActionItem is a workflow and there is no user OR the user is logged out, we used this objectURI to construct a log in URI. Potentially added some undesirable behavior to aggressively setUser (and later setObjectURI) from within the List on Actions... This should be okay-ish unless there was a vision of actions having different user objects associated with them. I think this is a safe assumption. Test Plan: played around with a mock all logged out (Ref T2652) and it worked! Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2691 Differential Revision: https://secure.phabricator.com/D6416
159 lines
4.2 KiB
PHP
159 lines
4.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|
|
|
private $id;
|
|
|
|
public function shouldAllowPublic() {
|
|
return true;
|
|
}
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$paste = id(new PhabricatorPasteQuery())
|
|
->setViewer($user)
|
|
->withIDs(array($this->id))
|
|
->needContent(true)
|
|
->executeOne();
|
|
if (!$paste) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere(
|
|
'phid = %s',
|
|
$paste->getFilePHID());
|
|
if (!$file) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$forks = id(new PhabricatorPasteQuery())
|
|
->setViewer($user)
|
|
->withParentPHIDs(array($paste->getPHID()))
|
|
->execute();
|
|
$fork_phids = mpull($forks, 'getPHID');
|
|
|
|
$this->loadHandles(
|
|
array_merge(
|
|
array(
|
|
$paste->getAuthorPHID(),
|
|
$paste->getParentPHID(),
|
|
),
|
|
$fork_phids));
|
|
|
|
$header = $this->buildHeaderView($paste);
|
|
$actions = $this->buildActionView($user, $paste, $file);
|
|
$properties = $this->buildPropertyView($paste, $fork_phids);
|
|
$source_code = $this->buildSourceCodeView($paste);
|
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView())
|
|
->setActionList($actions)
|
|
->addCrumb(
|
|
id(new PhabricatorCrumbView())
|
|
->setName('P'.$paste->getID())
|
|
->setHref('/P'.$paste->getID()));
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$header,
|
|
$actions,
|
|
$properties,
|
|
$source_code,
|
|
),
|
|
array(
|
|
'title' => $paste->getFullName(),
|
|
'device' => true,
|
|
'pageObjects' => array($paste->getPHID()),
|
|
));
|
|
}
|
|
|
|
private function buildHeaderView(PhabricatorPaste $paste) {
|
|
return id(new PhabricatorHeaderView())
|
|
->setHeader($paste->getTitle());
|
|
}
|
|
|
|
private function buildActionView(
|
|
PhabricatorUser $user,
|
|
PhabricatorPaste $paste,
|
|
PhabricatorFile $file) {
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
$user,
|
|
$paste,
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
$can_fork = $user->isLoggedIn();
|
|
$fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID());
|
|
|
|
return id(new PhabricatorActionListView())
|
|
->setUser($user)
|
|
->setObject($paste)
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
|
->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('Fork This Paste'))
|
|
->setIcon('fork')
|
|
->setDisabled(!$can_fork)
|
|
->setWorkflow(!$can_fork)
|
|
->setHref($fork_uri))
|
|
->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('View Raw File'))
|
|
->setIcon('file')
|
|
->setHref($file->getBestURI()))
|
|
->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('Edit Paste'))
|
|
->setIcon('edit')
|
|
->setDisabled(!$can_edit)
|
|
->setWorkflow(!$can_edit)
|
|
->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')));
|
|
}
|
|
|
|
private function buildPropertyView(
|
|
PhabricatorPaste $paste,
|
|
array $child_phids) {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
$properties = id(new PhabricatorPropertyListView())
|
|
->setUser($user)
|
|
->setObject($paste);
|
|
|
|
$properties->addProperty(
|
|
pht('Author'),
|
|
$this->getHandle($paste->getAuthorPHID())->renderLink());
|
|
|
|
$properties->addProperty(
|
|
pht('Created'),
|
|
phabricator_datetime($paste->getDateCreated(), $user));
|
|
|
|
if ($paste->getParentPHID()) {
|
|
$properties->addProperty(
|
|
pht('Forked From'),
|
|
$this->getHandle($paste->getParentPHID())->renderLink());
|
|
}
|
|
|
|
if ($child_phids) {
|
|
$properties->addProperty(
|
|
pht('Forks'),
|
|
$this->renderHandlesForPHIDs($child_phids));
|
|
}
|
|
|
|
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
|
|
$user,
|
|
$paste);
|
|
|
|
$properties->addProperty(
|
|
pht('Visible To'),
|
|
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
|
|
|
|
return $properties;
|
|
}
|
|
|
|
}
|