Add ApplicationTransaction handling for transactions with no effect
Summary:
When a user submits an action with no effect (like an empty comment, an "abandon" on an already-accepted revision, or a "close, resolved" on a closed task) we want to alert them that their action isn't effective. These warnings fall into two general buckets:
- User is submitting two or more actions, and some aren't effective but some are. Prompt them to apply the effective actions only.
- A special case of this is where the only effective action is a comment. We provide tailored text ("Post Comment") in this case.
- User is submitting one action, which isn't effective. Tell them they're out of luck.
- A special case of this is an empty comment. We provide tailored text in this case.
By default, the transaction editor throws when transactions have no effect. The caller can then deal with this, or use `PhabricatorApplicationTransactionNoEffectResponse` to provide a standard dialog that gives the user information as above. For cases where we expect transactions to have no effect (notably, "edit" forms) we just continue on no-effect unconditionally.
Also fix an issue where new, combined or filtered transactions would not be represented properly in the Ajax response (i.e., return final transactions from `applyTransactions()`), and translate some strings.
Test Plan:
- Submitted empty and nonempy comments in Macro and Pholio.
- Submitted comments with new and existing "@mentions".
- Submitted edits in both applications.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T912, T2104
Differential Revision: https://secure.phabricator.com/D4160
2012-12-12 02:27:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationTransactionNoEffectResponse
|
|
|
|
extends AphrontProxyResponse {
|
|
|
|
|
|
|
|
private $viewer;
|
|
|
|
private $exception;
|
|
|
|
private $cancelURI;
|
|
|
|
|
|
|
|
public function setCancelURI($cancel_uri) {
|
|
|
|
$this->cancelURI = $cancel_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setException(
|
|
|
|
PhabricatorApplicationTransactionNoEffectException $exception) {
|
|
|
|
$this->exception = $exception;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildProxy() {
|
|
|
|
return new AphrontDialogResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reduceProxyResponse() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$ex = $this->exception;
|
|
|
|
$xactions = $ex->getTransactions();
|
|
|
|
|
|
|
|
$type_comment = PhabricatorTransactions::TYPE_COMMENT;
|
|
|
|
$only_empty_comment = (count($xactions) == 1) &&
|
|
|
|
(head($xactions)->getTransactionType() == $type_comment);
|
|
|
|
|
|
|
|
if ($ex->hasAnyEffect()) {
|
|
|
|
$title = pht('%d Action(s) With No Effect', count($xactions));
|
|
|
|
$tail = pht('Apply remaining actions?');
|
|
|
|
$continue = pht('Apply Other Actions');
|
|
|
|
} else if ($ex->hasComment()) {
|
|
|
|
$title = pht('Post as Comment');
|
|
|
|
$tail = pht('Do you want to post your comment anyway?');
|
|
|
|
$continue = pht('Post Comment');
|
|
|
|
} else if ($only_empty_comment) {
|
|
|
|
// Special case this since it's common and we can give the user a nicer
|
|
|
|
// dialog than "Action Has No Effect".
|
|
|
|
$title = pht('Empty Comment');
|
|
|
|
$tail = null;
|
|
|
|
$continue = null;
|
|
|
|
} else {
|
|
|
|
$title = pht('%d Action(s) Have No Effect', count($xactions));
|
|
|
|
$tail = null;
|
|
|
|
$continue = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($request->getUser())
|
|
|
|
->setTitle($title);
|
|
|
|
|
|
|
|
foreach ($xactions as $xaction) {
|
2013-02-13 23:08:57 +01:00
|
|
|
$dialog->appendChild('<p>'.$xaction->getNoEffectDescription().'</p>');
|
Add ApplicationTransaction handling for transactions with no effect
Summary:
When a user submits an action with no effect (like an empty comment, an "abandon" on an already-accepted revision, or a "close, resolved" on a closed task) we want to alert them that their action isn't effective. These warnings fall into two general buckets:
- User is submitting two or more actions, and some aren't effective but some are. Prompt them to apply the effective actions only.
- A special case of this is where the only effective action is a comment. We provide tailored text ("Post Comment") in this case.
- User is submitting one action, which isn't effective. Tell them they're out of luck.
- A special case of this is an empty comment. We provide tailored text in this case.
By default, the transaction editor throws when transactions have no effect. The caller can then deal with this, or use `PhabricatorApplicationTransactionNoEffectResponse` to provide a standard dialog that gives the user information as above. For cases where we expect transactions to have no effect (notably, "edit" forms) we just continue on no-effect unconditionally.
Also fix an issue where new, combined or filtered transactions would not be represented properly in the Ajax response (i.e., return final transactions from `applyTransactions()`), and translate some strings.
Test Plan:
- Submitted empty and nonempy comments in Macro and Pholio.
- Submitted comments with new and existing "@mentions".
- Submitted edits in both applications.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T912, T2104
Differential Revision: https://secure.phabricator.com/D4160
2012-12-12 02:27:40 +01:00
|
|
|
}
|
|
|
|
$dialog->appendChild($tail);
|
|
|
|
|
|
|
|
if ($continue) {
|
|
|
|
$passthrough = $request->getPassthroughRequestParameters();
|
|
|
|
foreach ($passthrough as $key => $value) {
|
|
|
|
$dialog->addHiddenInput($key, $value);
|
|
|
|
}
|
|
|
|
$dialog->addHiddenInput('__continue__', 1);
|
|
|
|
$dialog->addSubmitButton($continue);
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog->addCancelButton($this->cancelURI);
|
|
|
|
|
|
|
|
return $this->getProxy()->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|