mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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->setConfig('viewer', $request->getUser());
|
||||
|
||||
$result = array(
|
||||
'content' => $engine->markupText($content),
|
||||
|
|
|
@ -64,6 +64,7 @@ final class ManiphestTaskDescriptionChangeController
|
|||
$handles = $this->loadViewerHandles($phids);
|
||||
|
||||
$engine = new PhabricatorMarkupEngine();
|
||||
$engine->setViewer($user);
|
||||
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
||||
$engine->process();
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ final class ManiphestTaskDescriptionPreviewController
|
|||
extends ManiphestController {
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$description = $request->getStr('description');
|
||||
|
||||
|
@ -32,7 +31,8 @@ final class ManiphestTaskDescriptionPreviewController
|
|||
|
||||
$output = PhabricatorMarkupEngine::renderOneObject(
|
||||
$task,
|
||||
ManiphestTask::MARKUP_FIELD_DESCRIPTION);
|
||||
ManiphestTask::MARKUP_FIELD_DESCRIPTION,
|
||||
$request->getUser());
|
||||
|
||||
$content =
|
||||
'<div class="phabricator-remarkup">'.
|
||||
|
|
|
@ -314,6 +314,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
$headsup_panel->setProperties($dict);
|
||||
|
||||
$engine = new PhabricatorMarkupEngine();
|
||||
$engine->setViewer($user);
|
||||
$engine->addObject($task, ManiphestTask::MARKUP_FIELD_DESCRIPTION);
|
||||
foreach ($transactions as $xaction) {
|
||||
if ($xaction->hasComments()) {
|
||||
|
|
|
@ -119,6 +119,7 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
|
|||
$transactions[] = $transaction;
|
||||
|
||||
$engine = new PhabricatorMarkupEngine();
|
||||
$engine->setViewer($user);
|
||||
$engine->addObject($transaction, ManiphestTransaction::MARKUP_FIELD_BODY);
|
||||
$engine->process();
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ final class PhrictionDocumentController
|
|||
|
||||
$doc_status = $document->getStatus();
|
||||
if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) {
|
||||
$core_content = $content->renderContent();
|
||||
$core_content = $content->renderContent($user);
|
||||
} else if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) {
|
||||
$notice = new AphrontErrorView();
|
||||
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||
|
|
|
@ -42,9 +42,7 @@ final class PhrictionDocumentPreviewController
|
|||
|
||||
$content_obj = new PhrictionContent();
|
||||
$content_obj->setContent($document);
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newPhrictionMarkupEngine();
|
||||
$content = $content_obj->renderContent();
|
||||
$content = $content_obj->renderContent($request->getUser());
|
||||
|
||||
return id(new AphrontAjaxResponse())->setContent($content);
|
||||
}
|
||||
|
|
|
@ -39,10 +39,11 @@ final class PhrictionContent extends PhrictionDAO
|
|||
protected $changeType;
|
||||
protected $changeRef;
|
||||
|
||||
public function renderContent() {
|
||||
public function renderContent(PhabricatorUser $viewer) {
|
||||
return PhabricatorMarkupEngine::renderOneObject(
|
||||
$this,
|
||||
self::MARKUP_FIELD_BODY);
|
||||
self::MARKUP_FIELD_BODY,
|
||||
$viewer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,8 @@ final class PonderCommentBodyView extends AphrontView {
|
|||
|
||||
$content = PhabricatorMarkupEngine::renderOneObject(
|
||||
$target,
|
||||
$target->getMarkupField());
|
||||
$target->getMarkupField(),
|
||||
$this->user);
|
||||
|
||||
$content =
|
||||
'<div class="phabricator-remarkup">'.
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
final class PhabricatorMarkupEngine {
|
||||
|
||||
private $objects = array();
|
||||
private $viewer;
|
||||
|
||||
|
||||
/* -( Markup Pipeline )---------------------------------------------------- */
|
||||
|
@ -67,13 +68,16 @@ final class PhabricatorMarkupEngine {
|
|||
*
|
||||
* @param PhabricatorMarkupInterface The object to render.
|
||||
* @param string The field to render.
|
||||
* @param PhabricatorUser User viewing the markup.
|
||||
* @return string Marked up output.
|
||||
* @task markup
|
||||
*/
|
||||
public static function renderOneObject(
|
||||
PhabricatorMarkupInterface $object,
|
||||
$field) {
|
||||
$field,
|
||||
PhabricatorUser $viewer) {
|
||||
return id(new PhabricatorMarkupEngine())
|
||||
->setViewer($viewer)
|
||||
->addObject($object, $field)
|
||||
->process()
|
||||
->getOutput($object, $field);
|
||||
|
@ -126,6 +130,7 @@ final class PhabricatorMarkupEngine {
|
|||
$engines = array();
|
||||
foreach ($objects as $key => $info) {
|
||||
$engines[$key] = $info['object']->newMarkupEngine($info['field']);
|
||||
$engines[$key]->setConfig('viewer', $this->viewer);
|
||||
}
|
||||
|
||||
// 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 )------------------------------------------------ */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @task engine
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue