From f6af1c43742480c7d17778cce2e71e3ef5f4b2fa Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 22 May 2019 15:10:19 -0700 Subject: [PATCH] When creating a Phriction document, mark initial transactions as "create" transactions to fix weird email Summary: Ref T13289. When you create a Phriction document, you currently get an email with the whole new content as a "diff". You also get extra transactions in the email and on the page. This is because Phriction isn't on EditEngine and doesn't mark "create" transactions in a modern way. Get them marked properly to fix these obviously-broken behaviors. This can all go away once Phriction switches to EditEngine, although I don't have any particular plans to do that in the immediate future. Test Plan: - Created a new document, viewed email, no longer saw redundant "edited content" transaction or "CHANGES TO CONTENT" diff. - Updated a document, viewed email, got interdiff. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13289 Differential Revision: https://secure.phabricator.com/D20548 --- .../controller/PhrictionEditController.php | 18 +++++++++++++++--- .../phriction/storage/PhrictionDocument.php | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionEditController.php b/src/applications/phriction/controller/PhrictionEditController.php index 9f59b63121..d86fa1e05b 100644 --- a/src/applications/phriction/controller/PhrictionEditController.php +++ b/src/applications/phriction/controller/PhrictionEditController.php @@ -97,6 +97,10 @@ final class PhrictionEditController $content_text = $content->getContent(); $is_draft_mode = ($document->getContent()->getVersion() != $max_version); + $default_view = $document->getViewPolicy(); + $default_edit = $document->getEditPolicy(); + $default_space = $document->getSpacePHID(); + if ($request->isFormPost()) { if ($is_new) { $save_as_draft = false; @@ -122,6 +126,11 @@ final class PhrictionEditController $xactions = array(); + if ($is_new) { + $xactions[] = id(new PhrictionTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_CREATE); + } + $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhrictionDocumentTitleTransaction::TRANSACTIONTYPE) ->setNewValue($title); @@ -130,13 +139,16 @@ final class PhrictionEditController ->setNewValue($content_text); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) - ->setNewValue($v_view); + ->setNewValue($v_view) + ->setIsDefaultTransaction($is_new && ($v_view === $default_view)); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) - ->setNewValue($v_edit); + ->setNewValue($v_edit) + ->setIsDefaultTransaction($is_new && ($v_edit === $default_edit)); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_SPACE) - ->setNewValue($v_space); + ->setNewValue($v_space) + ->setIsDefaultTransaction($is_new && ($v_space === $default_space)); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) ->setNewValue(array('=' => $v_cc)); diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index 9f8a4a475b..88c6b142e6 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -78,10 +78,13 @@ final class PhrictionDocument extends PhrictionDAO } if ($parent_doc) { + $space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID( + $parent_doc); + $document ->setViewPolicy($parent_doc->getViewPolicy()) ->setEditPolicy($parent_doc->getEditPolicy()) - ->setSpacePHID($parent_doc->getSpacePHID()); + ->setSpacePHID($space_phid); } else { $default_view_policy = PhabricatorPolicies::getMostOpenPolicy(); $document