2012-11-22 02:23:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group pholio
|
|
|
|
*/
|
|
|
|
final class PholioMockEditController extends PholioController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->id) {
|
2012-11-22 02:27:44 +01:00
|
|
|
$mock = id(new PholioMockQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$mock) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = pht('Edit Mock');
|
|
|
|
|
|
|
|
$is_new = false;
|
2012-11-22 02:23:28 +01:00
|
|
|
} else {
|
|
|
|
$mock = new PholioMock();
|
|
|
|
$mock->setAuthorPHID($user->getPHID());
|
|
|
|
$mock->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
|
|
|
|
|
|
|
$title = pht('Create Mock');
|
2012-11-22 02:27:44 +01:00
|
|
|
|
|
|
|
$is_new = true;
|
2012-11-22 02:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$e_images = true;
|
|
|
|
$errors = array();
|
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
$v_name = $mock->getName();
|
|
|
|
$v_desc = $mock->getDescription();
|
|
|
|
$v_view = $mock->getViewPolicy();
|
|
|
|
|
2012-11-22 02:23:28 +01:00
|
|
|
if ($request->isFormPost()) {
|
2012-11-22 02:27:44 +01:00
|
|
|
$xactions = array();
|
2012-11-22 02:23:28 +01:00
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
$type_name = PholioTransactionType::TYPE_NAME;
|
|
|
|
$type_desc = PholioTransactionType::TYPE_DESCRIPTION;
|
2012-12-11 22:59:20 +01:00
|
|
|
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
2012-11-22 02:23:28 +01:00
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
$v_name = $request->getStr('name');
|
|
|
|
$v_desc = $request->getStr('description');
|
|
|
|
$v_view = $request->getStr('can_view');
|
2012-11-22 02:23:28 +01:00
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
$xactions[$type_name] = $v_name;
|
|
|
|
$xactions[$type_desc] = $v_desc;
|
|
|
|
$xactions[$type_view] = $v_view;
|
2012-11-22 02:23:28 +01:00
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
if (!strlen($request->getStr('name'))) {
|
|
|
|
$e_name = 'Required';
|
|
|
|
$errors[] = pht('You must name the mock.');
|
2012-11-22 02:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$images = array();
|
2012-11-22 02:27:44 +01:00
|
|
|
if ($is_new) {
|
|
|
|
// TODO: Make this transactional and allow edits?
|
|
|
|
|
|
|
|
$files = array();
|
|
|
|
|
|
|
|
$file_phids = $request->getArr('file_phids');
|
|
|
|
if ($file_phids) {
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs($file_phids)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$files) {
|
|
|
|
$e_images = 'Required';
|
|
|
|
$errors[] = pht('You must add at least one image to the mock.');
|
|
|
|
} else {
|
|
|
|
$mock->setCoverPHID(head($files)->getPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
$sequence = 0;
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$image = new PholioImage();
|
|
|
|
$image->setFilePHID($file->getPHID());
|
|
|
|
$image->setSequence($sequence++);
|
|
|
|
|
|
|
|
$images[] = $image;
|
|
|
|
}
|
2012-11-22 02:23:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
2012-11-22 02:27:44 +01:00
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr(),
|
|
|
|
));
|
|
|
|
|
|
|
|
foreach ($xactions as $type => $value) {
|
|
|
|
$xactions[$type] = id(new PholioTransaction())
|
|
|
|
->setTransactionType($type)
|
|
|
|
->setNewValue($value);
|
|
|
|
}
|
|
|
|
|
2012-11-22 02:23:28 +01:00
|
|
|
$mock->openTransaction();
|
2012-11-22 02:27:44 +01:00
|
|
|
$editor = id(new PholioMockEditor())
|
|
|
|
->setContentSource($content_source)
|
2012-12-21 14:51:33 +01:00
|
|
|
->setContinueOnNoEffect(true)
|
2012-11-22 02:27:44 +01:00
|
|
|
->setActor($user);
|
|
|
|
|
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
|
|
|
$xactions = $editor->applyTransactions($mock, $xactions);
|
2012-11-22 02:27:44 +01:00
|
|
|
|
|
|
|
if ($images) {
|
|
|
|
foreach ($images as $image) {
|
|
|
|
// TODO: Move into editor?
|
|
|
|
$image->setMockID($mock->getID());
|
|
|
|
$image->save();
|
|
|
|
}
|
2012-11-22 02:23:28 +01:00
|
|
|
}
|
|
|
|
$mock->saveTransaction();
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/M'.$mock->getID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Form Errors'))
|
|
|
|
->setErrors($errors);
|
|
|
|
} else {
|
|
|
|
$error_view = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->id) {
|
|
|
|
$submit = id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton('/M'.$this->id)
|
|
|
|
->setValue(pht('Save'));
|
|
|
|
} else {
|
|
|
|
$submit = id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($this->getApplicationURI())
|
|
|
|
->setValue(pht('Create'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($mock)
|
|
|
|
->execute();
|
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
// NOTE: Make this show up correctly on the rendered form.
|
|
|
|
$mock->setViewPolicy($v_view);
|
|
|
|
|
2012-11-22 02:23:28 +01:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setFlexible(true)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
2012-11-22 02:27:44 +01:00
|
|
|
->setValue($v_name)
|
2012-11-22 02:23:28 +01:00
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setError($e_name))
|
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setName('description')
|
2012-11-22 02:27:44 +01:00
|
|
|
->setValue($v_desc)
|
2012-11-27 23:06:31 +01:00
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setUser($user))
|
2012-11-22 02:23:28 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormDragAndDropUploadControl($request))
|
|
|
|
->setName('file_phids')
|
|
|
|
->setLabel(pht('Images'))
|
|
|
|
->setError($e_images))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
|
|
|
->setPolicyObject($mock)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setName('can_view'))
|
|
|
|
->appendChild($submit);
|
|
|
|
|
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
$content = array(
|
|
|
|
$header,
|
|
|
|
$error_view,
|
|
|
|
$form,
|
|
|
|
);
|
|
|
|
|
|
|
|
$nav = $this->buildSideNav();
|
|
|
|
$nav->selectFilter(null);
|
|
|
|
$nav->appendChild($content);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|