mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Fix Phriction document move on to existing document placeholder
Summary: Looks like the logic was there already but some minor parts were missing. Fixes T8082. Test Plan: - Create document `/w/foo` - Delete document `/w/foo` - Create document `/w/bar` - Move document `/w/bar` for `/w/foo` No error was displayed and document `/w/bar` was moved to `/w/foo`. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T8082 Differential Revision: https://secure.phabricator.com/D16713
This commit is contained in:
parent
dad17fb98a
commit
4e831e786e
2 changed files with 25 additions and 11 deletions
|
@ -31,11 +31,11 @@ final class PhrictionMoveController extends PhrictionController {
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$v_note = $request->getStr('description');
|
$v_note = $request->getStr('description');
|
||||||
$v_slug = $request->getStr('slug');
|
$v_slug = $request->getStr('slug');
|
||||||
|
$normal_slug = PhabricatorSlug::normalize($v_slug);
|
||||||
|
|
||||||
// If what the user typed isn't what we're actually using, warn them
|
// If what the user typed isn't what we're actually using, warn them
|
||||||
// about it.
|
// about it.
|
||||||
if (strlen($v_slug)) {
|
if (strlen($v_slug)) {
|
||||||
$normal_slug = PhabricatorSlug::normalize($v_slug);
|
|
||||||
$no_slash_slug = rtrim($normal_slug, '/');
|
$no_slash_slug = rtrim($normal_slug, '/');
|
||||||
if ($normal_slug !== $v_slug && $no_slash_slug !== $v_slug) {
|
if ($normal_slug !== $v_slug && $no_slash_slug !== $v_slug) {
|
||||||
return $this->newDialog()
|
return $this->newDialog()
|
||||||
|
@ -66,9 +66,21 @@ final class PhrictionMoveController extends PhrictionController {
|
||||||
$xactions[] = id(new PhrictionTransaction())
|
$xactions[] = id(new PhrictionTransaction())
|
||||||
->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO)
|
->setTransactionType(PhrictionTransaction::TYPE_MOVE_TO)
|
||||||
->setNewValue($document);
|
->setNewValue($document);
|
||||||
$target_document = PhrictionDocument::initializeNewDocument(
|
$target_document = id(new PhrictionDocumentQuery())
|
||||||
$viewer,
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
$v_slug);
|
->withSlugs(array($normal_slug))
|
||||||
|
->needContent(true)
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
if (!$target_document) {
|
||||||
|
$target_document = PhrictionDocument::initializeNewDocument(
|
||||||
|
$viewer,
|
||||||
|
$v_slug);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$editor->applyTransactions($target_document, $xactions);
|
$editor->applyTransactions($target_document, $xactions);
|
||||||
$redir_uri = PhrictionDocument::getSlugURI(
|
$redir_uri = PhrictionDocument::getSlugURI(
|
||||||
|
|
|
@ -588,6 +588,7 @@ final class PhrictionTransactionEditor
|
||||||
// Prevent overwrites and no-op moves.
|
// Prevent overwrites and no-op moves.
|
||||||
$exists = PhrictionDocumentStatus::STATUS_EXISTS;
|
$exists = PhrictionDocumentStatus::STATUS_EXISTS;
|
||||||
if ($target_document) {
|
if ($target_document) {
|
||||||
|
$message = null;
|
||||||
if ($target_document->getSlug() == $source_document->getSlug()) {
|
if ($target_document->getSlug() == $source_document->getSlug()) {
|
||||||
$message = pht(
|
$message = pht(
|
||||||
'You can not move a document to its existing location. '.
|
'You can not move a document to its existing location. '.
|
||||||
|
@ -598,13 +599,14 @@ final class PhrictionTransactionEditor
|
||||||
'overwrite an existing document which is already at that '.
|
'overwrite an existing document which is already at that '.
|
||||||
'location. Move or delete the existing document first.');
|
'location. Move or delete the existing document first.');
|
||||||
}
|
}
|
||||||
|
if ($message !== null) {
|
||||||
$error = new PhabricatorApplicationTransactionValidationError(
|
$error = new PhabricatorApplicationTransactionValidationError(
|
||||||
$type,
|
$type,
|
||||||
pht('Invalid'),
|
pht('Invalid'),
|
||||||
$message,
|
$message,
|
||||||
$xaction);
|
$xaction);
|
||||||
$errors[] = $error;
|
$errors[] = $error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue