1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-17 10:11:10 +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' => 'javelin-behavior-phabricator-transaction-list' =>
array( 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', 'type' => 'js',
'requires' => 'requires' =>
array( array(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -79,8 +79,15 @@ JX.behavior('phabricator-transaction-list', function(config) {
['submit', 'didSyntheticSubmit'], ['submit', 'didSyntheticSubmit'],
'transaction-append', 'transaction-append',
function(e) { function(e) {
e.kill();
var form = e.getTarget(); 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.DOM.invoke(form, 'willSubmit');
JX.Workflow.newFromForm(form, { anchor : next_anchor }) JX.Workflow.newFromForm(form, { anchor : next_anchor })