1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-17 02:01:13 +01:00

Fix bug when multiple comment forms appear on a single page

Summary:
Ref T3373. The submit listener doesn't properly scope the form it listens to right now, so several forms on the page mean that comments post to one of them more or less at random.

Scope it properly by telling it which object PHID it is associated with.

Test Plan: Made Question comments, saw comments Ajax in on the question itself rather than on an arbitrary answer.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3373

Differential Revision: https://secure.phabricator.com/D6611
This commit is contained in:
epriestley 2013-07-28 18:21:22 -07:00
parent b6130ad49e
commit cf9dc5d189
18 changed files with 75 additions and 2 deletions

View file

@ -2194,7 +2194,7 @@ celerity_register_resource_map(array(
),
'javelin-behavior-phabricator-transaction-list' =>
array(
'uri' => '/res/e7a015a7/rsrc/js/application/transactions/behavior-transaction-list.js',
'uri' => '/res/8d602093/rsrc/js/application/transactions/behavior-transaction-list.js',
'type' => 'js',
'requires' =>
array(

View file

@ -266,6 +266,7 @@ final class PhabricatorAuthEditController
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setObjectPHID($config->getPHID())
->setTransactions($xactions);
}

View file

@ -219,6 +219,7 @@ final class PhabricatorConfigEditController
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($config_entry->getPHID())
->setTransactions($xactions);
return $this->buildApplicationPage(

View file

@ -51,6 +51,7 @@ final class DiffusionRepositoryEditController extends DiffusionController {
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($repository->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);

View file

@ -71,6 +71,7 @@ final class LegalpadDocumentViewController extends LegalpadController {
$xaction_view = id(new LegalpadTransactionView())
->setUser($this->getRequest()->getUser())
->setObjectPHID($document->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
@ -209,6 +210,7 @@ final class LegalpadDocumentViewController extends LegalpadController {
$form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setObjectPHID($document->getPHID())
->setFormID($comment_form_id)
->setDraft($draft)
->setSubmitButtonName($button_name)

View file

@ -55,6 +55,7 @@ final class PhabricatorMacroViewController
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($macro->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
@ -85,6 +86,7 @@ final class PhabricatorMacroViewController
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setObjectPHID($macro->getPHID())
->setDraft($draft)
->setAction($this->getApplicationURI('/comment/'.$macro->getID().'/'))
->setSubmitButtonName($submit_button_name);

View file

@ -79,6 +79,7 @@ final class PhluxViewController extends PhluxController {
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($var->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);

View file

@ -88,6 +88,7 @@ final class PholioMockViewController extends PholioController {
$xaction_view = id(new PholioTransactionView())
->setUser($this->getRequest()->getUser())
->setObjectPHID($mock->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
@ -249,6 +250,7 @@ final class PholioMockViewController extends PholioController {
$form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setObjectPHID($mock->getPHID())
->setFormID($comment_form_id)
->setDraft($draft)
->setSubmitButtonName($button_name)

View file

@ -168,6 +168,7 @@ final class PhortuneAccountViewController extends PhortuneController {
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($account->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);

View file

@ -77,6 +77,7 @@ final class PhortuneProductViewController extends PhortuneController {
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($product->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);

View file

@ -172,11 +172,13 @@ final class PonderQuestionViewController extends PonderController {
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setObjectPHID($question->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
$add_comment = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($question->getPHID())
->setShowPreview(false)
->setAction($this->getApplicationURI("/question/comment/{$id}/"))
->setSubmitButtonName(pht('Comment'));
@ -230,11 +232,13 @@ final class PonderQuestionViewController extends PonderController {
$out[] = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setObjectPHID($answer->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
$out[] = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($answer->getPHID())
->setShowPreview(false)
->setAction($this->getApplicationURI("/answer/comment/{$id}/"))
->setSubmitButtonName(pht('Comment'));

View file

@ -50,6 +50,7 @@ final class ReleephRequestViewController extends ReleephProjectController {
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($request->getUser())
->setObjectPHID($releeph_request->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
@ -62,6 +63,7 @@ final class ReleephRequestViewController extends ReleephProjectController {
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setObjectPHID($releeph_request->getPHID())
->setDraft($draft)
->setAction($this->getApplicationURI(
'/request/comment/'.$releeph_request->getID().'/'))

View file

@ -155,6 +155,7 @@ final class PhabricatorSlowvotePollController
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setObjectPHID($poll->getPHID())
->setTransactions($xactions)
->setMarkupEngine($engine);
@ -180,6 +181,7 @@ final class PhabricatorSlowvotePollController
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($poll->getPHID())
->setDraft($draft)
->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/'))
->setSubmitButtonName($submit_button_name);

View file

@ -61,6 +61,7 @@ final class PhabricatorApplicationTransactionCommentHistoryController
$view = id(new PhabricatorApplicationTransactionView())
->setUser($user)
->setObjectPHID($obj_phid)
->setTransactions($xactions)
->setShowEditActions(false);

View file

@ -17,6 +17,16 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
private $draft;
private $requestURI;
private $showPreview = true;
private $objectPHID;
public function setObjectPHID($object_phid) {
$this->objectPHID = $object_phid;
return $this;
}
public function getObjectPHID() {
return $this->objectPHID;
}
public function setShowPreview($show_preview) {
$this->showPreview = $show_preview;
@ -130,11 +140,19 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
$draft_comment = $this->getDraft()->getDraft();
}
if (!$this->getObjectPHID()) {
throw new Exception("Call setObjectPHID() before render()!");
}
return id(new AphrontFormView())
->setUser($this->getUser())
->setFlexible(true)
->addSigil('transaction-append')
->setWorkflow(true)
->setMetadata(
array(
'objectPHID' => $this->getObjectPHID(),
))
->setAction($this->getAction())
->setID($this->getFormID())
->appendChild(

View file

@ -10,6 +10,16 @@ class PhabricatorApplicationTransactionView extends AphrontView {
private $anchorOffset = 1;
private $showEditActions = true;
private $isPreview;
private $objectPHID;
public function setObjectPHID($object_phid) {
$this->objectPHID = $object_phid;
return $this;
}
public function getObjectPHID() {
return $this->objectPHID;
}
public function setIsPreview($is_preview) {
$this->isPreview = $is_preview;
@ -131,6 +141,10 @@ class PhabricatorApplicationTransactionView extends AphrontView {
}
public function render() {
if (!$this->getObjectPHID()) {
throw new Exception("Call setObjectPHID() before render()!");
}
$view = new PhabricatorTimelineView();
$events = $this->buildEvents();
foreach ($events as $event) {
@ -146,6 +160,7 @@ class PhabricatorApplicationTransactionView extends AphrontView {
'phabricator-transaction-list',
array(
'listID' => $list_id,
'objectPHID' => $this->getObjectPHID(),
'nextAnchor' => $this->anchorOffset + count($events),
));
}

View file

@ -12,6 +12,17 @@ final class AphrontFormView extends AphrontView {
private $flexible;
private $noShading;
private $sigils = array();
private $metadata;
public function setMetadata($metadata) {
$this->metadata = $metadata;
return $this;
}
public function getMetadata() {
return $this->metadata;
}
public function setFlexible($flexible) {
$this->flexible = $flexible;
@ -111,6 +122,7 @@ final class AphrontFormView extends AphrontView {
'method' => $this->method,
'enctype' => $this->encType,
'sigil' => $sigils ? implode(' ', $sigils) : null,
'meta' => $this->metadata,
'id' => $this->id,
),
$layout->render());

View file

@ -79,8 +79,15 @@ JX.behavior('phabricator-transaction-list', function(config) {
['submit', 'didSyntheticSubmit'],
'transaction-append',
function(e) {
e.kill();
var form = e.getTarget();
if (JX.Stratcom.getData(form).objectPHID != config.objectPHID) {
// This indicates there are several forms on the page, and the user
// submitted a different one than the one we're in control of.
return;
}
e.kill();
JX.DOM.invoke(form, 'willSubmit');
JX.Workflow.newFromForm(form, { anchor : next_anchor })