From c86a514f8478d0e04116ae232210aca0f84782ec Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sat, 7 Nov 2015 11:29:20 -0800 Subject: [PATCH] Add Subscribers to Phame Blogs / Posts Summary: Fixes T9051, adds ability to edit blogs and posts and manually add subscribers. Also fixed bug granting tokens to posts. Test Plan: Create a new blog, subcribe chad and notchad. Write a post, both are notified. Award token for hard work. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9051 Differential Revision: https://secure.phabricator.com/D14432 --- .../blog/PhameBlogEditController.php | 40 +++++++++++++------ .../post/PhamePostEditController.php | 15 +++++++ .../post/PhamePostPublishController.php | 6 --- .../post/PhamePostUnpublishController.php | 6 --- .../phame/editor/PhameBlogEditor.php | 4 ++ .../phame/editor/PhamePostEditor.php | 8 +++- 6 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/applications/phame/controller/blog/PhameBlogEditController.php b/src/applications/phame/controller/blog/PhameBlogEditController.php index 659f33ae3d..b59e5e01a2 100644 --- a/src/applications/phame/controller/blog/PhameBlogEditController.php +++ b/src/applications/phame/controller/blog/PhameBlogEditController.php @@ -28,6 +28,8 @@ final class PhameBlogEditController $blog->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $v_projects = array_reverse($v_projects); + $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( + $blog->getPHID()); } else { $this->requireApplicationCapability( @@ -39,28 +41,30 @@ final class PhameBlogEditController $page_title = pht('Create Blog'); $cancel_uri = $this->getApplicationURI(); $v_projects = array(); + $v_cc = array(); } - $name = $blog->getName(); - $description = $blog->getDescription(); + $name = $blog->getName(); + $description = $blog->getDescription(); $custom_domain = $blog->getDomain(); - $skin = $blog->getSkin(); - $can_view = $blog->getViewPolicy(); - $can_edit = $blog->getEditPolicy(); - $can_join = $blog->getJoinPolicy(); + $skin = $blog->getSkin(); + $can_view = $blog->getViewPolicy(); + $can_edit = $blog->getEditPolicy(); + $can_join = $blog->getJoinPolicy(); $e_name = true; $e_custom_domain = null; $e_view_policy = null; $validation_exception = null; if ($request->isFormPost()) { - $name = $request->getStr('name'); - $description = $request->getStr('description'); + $name = $request->getStr('name'); + $description = $request->getStr('description'); $custom_domain = nonempty($request->getStr('custom_domain'), null); - $skin = $request->getStr('skin'); - $can_view = $request->getStr('can_view'); - $can_edit = $request->getStr('can_edit'); - $can_join = $request->getStr('can_join'); - $v_projects = $request->getArr('projects'); + $skin = $request->getStr('skin'); + $can_view = $request->getStr('can_view'); + $can_edit = $request->getStr('can_edit'); + $can_join = $request->getStr('can_join'); + $v_projects = $request->getArr('projects'); + $v_cc = $request->getArr('cc'); $xactions = array( id(new PhameBlogTransaction()) @@ -84,6 +88,9 @@ final class PhameBlogEditController id(new PhameBlogTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY) ->setNewValue($can_join), + id(new PhameBlogTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) + ->setNewValue(array('=' => $v_cc)), ); $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; @@ -139,6 +146,13 @@ final class PhameBlogEditController ->setID('blog-description') ->setUser($viewer) ->setDisableMacros(true)) + ->appendControl( + id(new AphrontFormTokenizerControl()) + ->setLabel(pht('Subscribers')) + ->setName('cc') + ->setValue($v_cc) + ->setUser($viewer) + ->setDatasource(new PhabricatorMetaMTAMailableDatasource())) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) diff --git a/src/applications/phame/controller/post/PhamePostEditController.php b/src/applications/phame/controller/post/PhamePostEditController.php index 44368b3207..99e6df390e 100644 --- a/src/applications/phame/controller/post/PhamePostEditController.php +++ b/src/applications/phame/controller/post/PhamePostEditController.php @@ -27,6 +27,8 @@ final class PhamePostEditController extends PhamePostController { $post->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $v_projects = array_reverse($v_projects); + $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( + $post->getPHID()); } else { $blog = id(new PhameBlogQuery()) ->setViewer($viewer) @@ -41,6 +43,7 @@ final class PhamePostEditController extends PhamePostController { return new Aphront404Response(); } $v_projects = array(); + $v_cc = array(); $post = PhamePost::initializePost($viewer, $blog); $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); @@ -65,6 +68,7 @@ final class PhamePostEditController extends PhamePostController { $body = $request->getStr('body'); $comments_widget = $request->getStr('comments_widget'); $v_projects = $request->getArr('projects'); + $v_cc = $request->getArr('cc'); $visibility = $request->getInt('visibility'); $xactions = array( @@ -83,6 +87,10 @@ final class PhamePostEditController extends PhamePostController { id(new PhamePostTransaction()) ->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET) ->setNewValue($comments_widget), + id(new PhamePostTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) + ->setNewValue(array('=' => $v_cc)), + ); $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; @@ -154,6 +162,13 @@ final class PhamePostEditController extends PhamePostController { ->setID('post-body') ->setUser($viewer) ->setDisableMacros(true)) + ->appendControl( + id(new AphrontFormTokenizerControl()) + ->setLabel(pht('Subscribers')) + ->setName('cc') + ->setValue($v_cc) + ->setUser($viewer) + ->setDatasource(new PhabricatorMetaMTAMailableDatasource())) ->appendControl( id(new AphrontFormTokenizerControl()) ->setLabel(pht('Projects')) diff --git a/src/applications/phame/controller/post/PhamePostPublishController.php b/src/applications/phame/controller/post/PhamePostPublishController.php index 0d612d193e..9b593b1313 100644 --- a/src/applications/phame/controller/post/PhamePostPublishController.php +++ b/src/applications/phame/controller/post/PhamePostPublishController.php @@ -22,12 +22,6 @@ final class PhamePostPublishController extends PhamePostController { if ($request->isFormPost()) { $xactions = array(); - $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_TITLE) - ->setNewValue($post->getTitle()); - $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE) - ->setNewValue($post->getPhameTitle()); $xactions[] = id(new PhamePostTransaction()) ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) ->setNewValue(PhameConstants::VISIBILITY_PUBLISHED); diff --git a/src/applications/phame/controller/post/PhamePostUnpublishController.php b/src/applications/phame/controller/post/PhamePostUnpublishController.php index 8e95cfe75b..ca09ef8879 100644 --- a/src/applications/phame/controller/post/PhamePostUnpublishController.php +++ b/src/applications/phame/controller/post/PhamePostUnpublishController.php @@ -20,12 +20,6 @@ final class PhamePostUnpublishController extends PhamePostController { if ($request->isFormPost()) { $xactions = array(); - $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_TITLE) - ->setNewValue($post->getTitle()); - $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE) - ->setNewValue($post->getPhameTitle()); $xactions[] = id(new PhamePostTransaction()) ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) ->setNewValue(PhameConstants::VISIBILITY_DRAFT); diff --git a/src/applications/phame/editor/PhameBlogEditor.php b/src/applications/phame/editor/PhameBlogEditor.php index d665d92541..a44bec422b 100644 --- a/src/applications/phame/editor/PhameBlogEditor.php +++ b/src/applications/phame/editor/PhameBlogEditor.php @@ -94,6 +94,7 @@ final class PhameBlogEditor $errors = parent::validateTransaction($object, $type, $xactions); + switch ($type) { case PhameBlogTransaction::TYPE_NAME: $missing = $this->validateIsEmptyTextField( @@ -112,6 +113,9 @@ final class PhameBlogEditor } break; case PhameBlogTransaction::TYPE_DOMAIN: + if (!$xactions) { + continue; + } $custom_domain = last($xactions)->getNewValue(); if (empty($custom_domain)) { continue; diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php index 4cf0a0c60d..0009ccaea5 100644 --- a/src/applications/phame/editor/PhamePostEditor.php +++ b/src/applications/phame/editor/PhamePostEditor.php @@ -121,6 +121,9 @@ final class PhamePostEditor } break; case PhamePostTransaction::TYPE_PHAME_TITLE: + if (!$xactions) { + continue; + } $missing = $this->validateIsEmptyTextField( $object->getPhameTitle(), $xactions); @@ -183,8 +186,11 @@ final class PhamePostEditor $blog_phid = $object->getBlogPHID(); if ($blog_phid) { - $phids[] = PhabricatorSubscribersQuery::loadSubscribersForPHID( + $cc_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID( $blog_phid); + foreach ($cc_phids as $cc) { + $phids[] = $cc; + } } return $phids; }