mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Add 'viewer' to some Remarkup callsites
Summary: I want to implement a `{P123}` rule to embed pastes, but we need viewers everywhere before it will work with privacy. This is not exhaustive; many Remarkup callsites haven't been converted to `PhabricatorMarkupInterface` yet. Test Plan: Looked at Maniphest, Differential, Diffusion, Phriction; added markup, made edits and hit previews. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3428
This commit is contained in:
parent
9b843a3d44
commit
dbc8218f06
10 changed files with 33 additions and 10 deletions
|
@ -57,6 +57,7 @@ final class ConduitAPI_remarkup_process_Method extends ConduitAPIMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine = PhabricatorMarkupEngine::$engine_class();
|
$engine = PhabricatorMarkupEngine::$engine_class();
|
||||||
|
$engine->setConfig('viewer', $request->getUser());
|
||||||
|
|
||||||
$result = array(
|
$result = array(
|
||||||
'content' => $engine->markupText($content),
|
'content' => $engine->markupText($content),
|
||||||
|
|
|
@ -64,6 +64,7 @@ final class ManiphestTaskDescriptionChangeController
|
||||||
$handles = $this->loadViewerHandles($phids);
|
$handles = $this->loadViewerHandles($phids);
|
||||||
|
|
||||||
$engine = new PhabricatorMarkupEngine();
|
$engine = new PhabricatorMarkupEngine();
|
||||||
|
$engine->setViewer($user);
|
||||||
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
||||||
$engine->process();
|
$engine->process();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ final class ManiphestTaskDescriptionPreviewController
|
||||||
extends ManiphestController {
|
extends ManiphestController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$description = $request->getStr('description');
|
$description = $request->getStr('description');
|
||||||
|
|
||||||
|
@ -32,7 +31,8 @@ final class ManiphestTaskDescriptionPreviewController
|
||||||
|
|
||||||
$output = PhabricatorMarkupEngine::renderOneObject(
|
$output = PhabricatorMarkupEngine::renderOneObject(
|
||||||
$task,
|
$task,
|
||||||
ManiphestTask::MARKUP_FIELD_DESCRIPTION);
|
ManiphestTask::MARKUP_FIELD_DESCRIPTION,
|
||||||
|
$request->getUser());
|
||||||
|
|
||||||
$content =
|
$content =
|
||||||
'<div class="phabricator-remarkup">'.
|
'<div class="phabricator-remarkup">'.
|
||||||
|
|
|
@ -314,6 +314,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
||||||
$headsup_panel->setProperties($dict);
|
$headsup_panel->setProperties($dict);
|
||||||
|
|
||||||
$engine = new PhabricatorMarkupEngine();
|
$engine = new PhabricatorMarkupEngine();
|
||||||
|
$engine->setViewer($user);
|
||||||
$engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION);
|
$engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION);
|
||||||
foreach ($transactions as $xaction) {
|
foreach ($transactions as $xaction) {
|
||||||
if ($xaction->hasComments()) {
|
if ($xaction->hasComments()) {
|
||||||
|
|
|
@ -119,6 +119,7 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
|
||||||
$transactions[] = $transaction;
|
$transactions[] = $transaction;
|
||||||
|
|
||||||
$engine = new PhabricatorMarkupEngine();
|
$engine = new PhabricatorMarkupEngine();
|
||||||
|
$engine->setViewer($user);
|
||||||
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
||||||
$engine->process();
|
$engine->process();
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ final class PhrictionDocumentController
|
||||||
|
|
||||||
$doc_status = $document->getStatus();
|
$doc_status = $document->getStatus();
|
||||||
if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) {
|
if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) {
|
||||||
$core_content = $content->renderContent();
|
$core_content = $content->renderContent($user);
|
||||||
} else if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) {
|
} else if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) {
|
||||||
$notice = new AphrontErrorView();
|
$notice = new AphrontErrorView();
|
||||||
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||||
|
|
|
@ -42,9 +42,7 @@ final class PhrictionDocumentPreviewController
|
||||||
|
|
||||||
$content_obj = new PhrictionContent();
|
$content_obj = new PhrictionContent();
|
||||||
$content_obj->setContent($document);
|
$content_obj->setContent($document);
|
||||||
|
$content = $content_obj->renderContent($request->getUser());
|
||||||
$engine = PhabricatorMarkupEngine::newPhrictionMarkupEngine();
|
|
||||||
$content = $content_obj->renderContent();
|
|
||||||
|
|
||||||
return id(new AphrontAjaxResponse())->setContent($content);
|
return id(new AphrontAjaxResponse())->setContent($content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,11 @@ final class PhrictionContent extends PhrictionDAO
|
||||||
protected $changeType;
|
protected $changeType;
|
||||||
protected $changeRef;
|
protected $changeRef;
|
||||||
|
|
||||||
public function renderContent() {
|
public function renderContent(PhabricatorUser $viewer) {
|
||||||
return PhabricatorMarkupEngine::renderOneObject(
|
return PhabricatorMarkupEngine::renderOneObject(
|
||||||
$this,
|
$this,
|
||||||
self::MARKUP_FIELD_BODY);
|
self::MARKUP_FIELD_BODY,
|
||||||
|
$viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,8 @@ final class PonderCommentBodyView extends AphrontView {
|
||||||
|
|
||||||
$content = PhabricatorMarkupEngine::renderOneObject(
|
$content = PhabricatorMarkupEngine::renderOneObject(
|
||||||
$target,
|
$target,
|
||||||
$target->getMarkupField());
|
$target->getMarkupField(),
|
||||||
|
$this->user);
|
||||||
|
|
||||||
$content =
|
$content =
|
||||||
'<div class="phabricator-remarkup">'.
|
'<div class="phabricator-remarkup">'.
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
final class PhabricatorMarkupEngine {
|
final class PhabricatorMarkupEngine {
|
||||||
|
|
||||||
private $objects = array();
|
private $objects = array();
|
||||||
|
private $viewer;
|
||||||
|
|
||||||
|
|
||||||
/* -( Markup Pipeline )---------------------------------------------------- */
|
/* -( Markup Pipeline )---------------------------------------------------- */
|
||||||
|
@ -67,13 +68,16 @@ final class PhabricatorMarkupEngine {
|
||||||
*
|
*
|
||||||
* @param PhabricatorMarkupInterface The object to render.
|
* @param PhabricatorMarkupInterface The object to render.
|
||||||
* @param string The field to render.
|
* @param string The field to render.
|
||||||
|
* @param PhabricatorUser User viewing the markup.
|
||||||
* @return string Marked up output.
|
* @return string Marked up output.
|
||||||
* @task markup
|
* @task markup
|
||||||
*/
|
*/
|
||||||
public static function renderOneObject(
|
public static function renderOneObject(
|
||||||
PhabricatorMarkupInterface $object,
|
PhabricatorMarkupInterface $object,
|
||||||
$field) {
|
$field,
|
||||||
|
PhabricatorUser $viewer) {
|
||||||
return id(new PhabricatorMarkupEngine())
|
return id(new PhabricatorMarkupEngine())
|
||||||
|
->setViewer($viewer)
|
||||||
->addObject($object, $field)
|
->addObject($object, $field)
|
||||||
->process()
|
->process()
|
||||||
->getOutput($object, $field);
|
->getOutput($object, $field);
|
||||||
|
@ -126,6 +130,7 @@ final class PhabricatorMarkupEngine {
|
||||||
$engines = array();
|
$engines = array();
|
||||||
foreach ($objects as $key => $info) {
|
foreach ($objects as $key => $info) {
|
||||||
$engines[$key] = $info['object']->newMarkupEngine($info['field']);
|
$engines[$key] = $info['object']->newMarkupEngine($info['field']);
|
||||||
|
$engines[$key]->setConfig('viewer', $this->viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load or build the preprocessor caches.
|
// Load or build the preprocessor caches.
|
||||||
|
@ -243,9 +248,23 @@ final class PhabricatorMarkupEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the viewing user. Used to implement object permissions.
|
||||||
|
*
|
||||||
|
* @param PhabricatorUser The viewing user.
|
||||||
|
* @return this
|
||||||
|
* @task markup
|
||||||
|
*/
|
||||||
|
public function setViewer(PhabricatorUser $viewer) {
|
||||||
|
$this->viewer = $viewer;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Engine Construction )------------------------------------------------ */
|
/* -( Engine Construction )------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @task engine
|
* @task engine
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue