1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Phriction - move delete to modern editor + transactions

Summary:
Ref T4029. Much like D10756 this does the bare minimum to get things in there. I have a sticky with "TODOs" about moving the error-checking business logic into the editor in both cases.

Up next - move actions...

Test Plan: deleted a document and it worked! verified proper feed story.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: shadowhand, Korvin, epriestley

Maniphest Tasks: T4029

Differential Revision: https://secure.phabricator.com/D10761
This commit is contained in:
Bob Trahan 2014-11-05 12:37:53 -08:00
parent f7fbf9ccc1
commit bdbb771830
3 changed files with 57 additions and 12 deletions

View file

@ -15,6 +15,7 @@ final class PhrictionDeleteController extends PhrictionController {
$document = id(new PhrictionDocumentQuery())
->setViewer($user)
->withIDs(array($this->id))
->needContent(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
@ -32,15 +33,24 @@ final class PhrictionDeleteController extends PhrictionController {
PhrictionDocumentStatus::STATUS_STUB => true, // How could they?
);
if (isset($disallowed_states[$document->getStatus()])) {
$e_text = pht('An already moved or deleted document can not be deleted');
$e_text = pht(
'An already moved or deleted document can not be deleted.');
}
$document_uri = PhrictionDocument::getSlugURI($document->getSlug());
if (!$e_text && $request->isFormPost()) {
$editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))
$xactions = array();
$xactions[] = id(new PhrictionTransaction())
->setTransactionType(PhrictionTransaction::TYPE_DELETE)
->setNewValue(true);
$editor = id(new PhrictionTransactionEditor())
->setActor($user)
->delete();
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->applyTransactions($document, $xactions);
return id(new AphrontRedirectResponse())->setURI($document_uri);
}

View file

@ -48,6 +48,7 @@ final class PhrictionTransactionEditor
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhrictionTransaction::TYPE_TITLE;
$types[] = PhrictionTransaction::TYPE_CONTENT;
$types[] = PhrictionTransaction::TYPE_DELETE;
/* TODO
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
@ -72,6 +73,8 @@ final class PhrictionTransactionEditor
return null;
}
return $this->getOldContent()->getContent();
case PhrictionTransaction::TYPE_DELETE:
return null;
}
}
@ -82,6 +85,7 @@ final class PhrictionTransactionEditor
switch ($xaction->getTransactionType()) {
case PhrictionTransaction::TYPE_TITLE:
case PhrictionTransaction::TYPE_CONTENT:
case PhrictionTransaction::TYPE_DELETE:
return $xaction->getNewValue();
}
}
@ -94,6 +98,7 @@ final class PhrictionTransactionEditor
switch ($xaction->getTransactionType()) {
case PhrictionTransaction::TYPE_TITLE:
case PhrictionTransaction::TYPE_CONTENT:
case PhrictionTransaction::TYPE_DELETE:
return true;
}
}
@ -131,6 +136,11 @@ final class PhrictionTransactionEditor
case PhrictionTransaction::TYPE_CONTENT:
$this->getNewContent()->setContent($xaction->getNewValue());
break;
case PhrictionTransaction::TYPE_DELETE:
$this->getNewContent()->setContent('');
$this->getNewContent()->setChangeType(
PhrictionChangeType::CHANGE_DELETE);
break;
default:
break;
}
@ -145,6 +155,7 @@ final class PhrictionTransactionEditor
switch ($xaction->getTransactionType()) {
case PhrictionTransaction::TYPE_TITLE:
case PhrictionTransaction::TYPE_CONTENT:
case PhrictionTransaction::TYPE_DELETE:
$save_content = true;
break;
default:
@ -213,6 +224,8 @@ final class PhrictionTransactionEditor
pht("A document's title changes."),
PhrictionTransaction::MAILTAG_CONTENT =>
pht("A document's content changes."),
PhrictionTransaction::MAILTAG_DELETE =>
pht('A document is deleted.'),
);
}
@ -279,14 +292,12 @@ final class PhrictionTransactionEditor
private function buildNewContentTemplate(
PhrictionDocument $document) {
$new_content = new PhrictionContent();
$new_content->setSlug($document->getSlug());
$new_content->setAuthorPHID($this->getActor()->getPHID());
$new_content->setChangeType(PhrictionChangeType::CHANGE_EDIT);
$new_content->setTitle($this->getOldContent()->getTitle());
$new_content->setContent($this->getOldContent()->getContent());
$new_content = id(new PhrictionContent())
->setSlug($document->getSlug())
->setAuthorPHID($this->getActor()->getPHID())
->setChangeType(PhrictionChangeType::CHANGE_EDIT)
->setTitle($this->getOldContent()->getTitle())
->setContent($this->getOldContent()->getContent());
if (strlen($this->getDescription())) {
$new_content->setDescription($this->getDescription());
}

View file

@ -5,9 +5,11 @@ final class PhrictionTransaction
const TYPE_TITLE = 'title';
const TYPE_CONTENT = 'content';
const TYPE_DELETE = 'delete';
const MAILTAG_TITLE = 'phriction-title';
const MAILTAG_CONTENT = 'phriction-content';
const MAILTAG_DELETE = 'phriction-delete';
public function getApplicationName() {
return 'phriction';
@ -53,6 +55,8 @@ final class PhrictionTransaction
return 1.4;
case self::TYPE_CONTENT:
return 1.3;
case self::TYPE_DELETE:
return 1.5;
}
return parent::getActionStrength();
@ -73,6 +77,9 @@ final class PhrictionTransaction
case self::TYPE_CONTENT:
return pht('Edited');
case self::TYPE_DELETE:
return pht('Deleted');
}
return parent::getActionName();
@ -86,13 +93,14 @@ final class PhrictionTransaction
case self::TYPE_TITLE:
case self::TYPE_CONTENT:
return 'fa-pencil';
case self::TYPE_DELETE:
return 'fa-times';
}
return parent::getIcon();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
@ -117,6 +125,12 @@ final class PhrictionTransaction
'%s edited the document content.',
$this->renderHandleLink($author_phid));
case self::TYPE_DELETE:
return pht(
'%s deleted this document.',
$this->renderHandleLink($author_phid));
}
return parent::getTitle();
@ -151,6 +165,12 @@ final class PhrictionTransaction
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_DELETE:
return pht(
'%s deleted %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
return parent::getTitleForFeed($story);
}
@ -179,6 +199,10 @@ final class PhrictionTransaction
case self::TYPE_CONTENT:
$tags[] = self::MAILTAG_CONTENT;
break;
case self::TYPE_DELETE:
$tags[] = self::MAILTAG_DELETE;
break;
}
return $tags;
}