1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Add a transaction for PhamePost visibility

Summary: Adds ability to set visibility when authoring a Post. New default is "Visible". If you write a post and save it as a Draft, and later click publish, a feed story and mail will go out.

Test Plan: Write a new Post, see feed story and get email. Write a new Draft, get nothing. Click Publish, see story and email.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9360

Differential Revision: https://secure.phabricator.com/D14429
This commit is contained in:
Chad Little 2015-11-07 06:52:42 -08:00
parent 268fac25d5
commit f8b085c574
12 changed files with 150 additions and 47 deletions

View file

@ -3262,6 +3262,7 @@ phutil_register_library_map(array(
'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php',
'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php', 'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php',
'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php', 'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php',
'PhameConstants' => 'applications/phame/constants/PhameConstants.php',
'PhameController' => 'applications/phame/controller/PhameController.php', 'PhameController' => 'applications/phame/controller/PhameController.php',
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php', 'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
'PhameDAO' => 'applications/phame/storage/PhameDAO.php', 'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
@ -7525,6 +7526,7 @@ phutil_register_library_map(array(
'PhameBlogViewController' => 'PhameBlogController', 'PhameBlogViewController' => 'PhameBlogController',
'PhameCelerityResources' => 'CelerityResources', 'PhameCelerityResources' => 'CelerityResources',
'PhameConduitAPIMethod' => 'ConduitAPIMethod', 'PhameConduitAPIMethod' => 'ConduitAPIMethod',
'PhameConstants' => 'Phobject',
'PhameController' => 'PhabricatorController', 'PhameController' => 'PhabricatorController',
'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod', 'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod',
'PhameDAO' => 'PhabricatorLiskDAO', 'PhameDAO' => 'PhabricatorLiskDAO',

View file

@ -85,7 +85,7 @@ final class PhameCreatePostConduitAPIMethod extends PhameConduitAPIMethod {
$is_draft = $request->getValue('isDraft', false); $is_draft = $request->getValue('isDraft', false);
if (!$is_draft) { if (!$is_draft) {
$post->setDatePublished(time()); $post->setDatePublished(time());
$post->setVisibility(PhamePost::VISIBILITY_PUBLISHED); $post->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
} }
$post->setTitle($title); $post->setTitle($title);
$phame_title = $request->getValue( $phame_title = $request->getValue(

View file

@ -65,9 +65,9 @@ final class PhameQueryPostsConduitAPIMethod extends PhameConduitAPIMethod {
$published = $request->getValue('published', null); $published = $request->getValue('published', null);
if ($published === true) { if ($published === true) {
$query->withVisibility(PhamePost::VISIBILITY_PUBLISHED); $query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED);
} else if ($published === false) { } else if ($published === false) {
$query->withVisibility(PhamePost::VISIBILITY_DRAFT); $query->withVisibility(PhameConstants::VISIBILITY_DRAFT);
} }
$published_after = $request->getValue('publishedAfter', null); $published_after = $request->getValue('publishedAfter', null);

View file

@ -0,0 +1,23 @@
<?php
final class PhameConstants extends Phobject {
const VISIBILITY_DRAFT = 0;
const VISIBILITY_PUBLISHED = 1;
public static function getPhamePostStatusMap() {
return array(
self::VISIBILITY_PUBLISHED => pht('Published'),
self::VISIBILITY_DRAFT => pht('Draft'),
);
}
public static function getPhamePostStatusName($status) {
$map = array(
self::VISIBILITY_PUBLISHED => pht('Published'),
self::VISIBILITY_DRAFT => pht('Draft'),
);
return idx($map, $status, pht('Unknown'));
}
}

View file

@ -21,7 +21,7 @@ final class PhameBlogFeedController extends PhameBlogController {
$posts = id(new PhamePostQuery()) $posts = id(new PhamePostQuery())
->setViewer($viewer) ->setViewer($viewer)
->withBlogPHIDs(array($blog->getPHID())) ->withBlogPHIDs(array($blog->getPHID()))
->withVisibility(PhamePost::VISIBILITY_PUBLISHED) ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->execute(); ->execute();
$blog_uri = PhabricatorEnv::getProductionURI( $blog_uri = PhabricatorEnv::getProductionURI(

View file

@ -45,7 +45,7 @@ final class PhamePostEditController extends PhamePostController {
$post = PhamePost::initializePost($viewer, $blog); $post = PhamePost::initializePost($viewer, $blog);
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/');
$submit_button = pht('Save Draft'); $submit_button = pht('Create Post');
$page_title = pht('Create Post'); $page_title = pht('Create Post');
} }
@ -53,6 +53,7 @@ final class PhamePostEditController extends PhamePostController {
$phame_title = $post->getPhameTitle(); $phame_title = $post->getPhameTitle();
$body = $post->getBody(); $body = $post->getBody();
$comments_widget = $post->getCommentsWidget(); $comments_widget = $post->getCommentsWidget();
$visibility = $post->getVisibility();
$e_title = true; $e_title = true;
$e_phame_title = true; $e_phame_title = true;
@ -64,6 +65,7 @@ final class PhamePostEditController extends PhamePostController {
$body = $request->getStr('body'); $body = $request->getStr('body');
$comments_widget = $request->getStr('comments_widget'); $comments_widget = $request->getStr('comments_widget');
$v_projects = $request->getArr('projects'); $v_projects = $request->getArr('projects');
$visibility = $request->getInt('visibility');
$xactions = array( $xactions = array(
id(new PhamePostTransaction()) id(new PhamePostTransaction())
@ -75,6 +77,9 @@ final class PhamePostEditController extends PhamePostController {
id(new PhamePostTransaction()) id(new PhamePostTransaction())
->setTransactionType(PhamePostTransaction::TYPE_BODY) ->setTransactionType(PhamePostTransaction::TYPE_BODY)
->setNewValue($body), ->setNewValue($body),
id(new PhamePostTransaction())
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
->setNewValue($visibility),
id(new PhamePostTransaction()) id(new PhamePostTransaction())
->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET) ->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET)
->setNewValue($comments_widget), ->setNewValue($comments_widget),
@ -134,6 +139,12 @@ final class PhamePostEditController extends PhamePostController {
'with underscores for spaces. '. 'with underscores for spaces. '.
'Formatting is enforced.')) 'Formatting is enforced.'))
->setError($e_phame_title)) ->setError($e_phame_title))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Visibility'))
->setName('visibility')
->setvalue($visibility)
->setOptions(PhameConstants::getPhamePostStatusMap()))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setLabel(pht('Body')) ->setLabel(pht('Body'))

View file

@ -21,9 +21,23 @@ final class PhamePostPublishController extends PhamePostController {
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); $view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
if ($request->isFormPost()) { if ($request->isFormPost()) {
$post->setVisibility(PhamePost::VISIBILITY_PUBLISHED); $xactions = array();
$post->setDatePublished(time()); $xactions[] = id(new PhamePostTransaction())
$post->save(); ->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);
id(new PhamePostEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri); return id(new AphrontRedirectResponse())->setURI($view_uri);
} }

View file

@ -19,9 +19,23 @@ final class PhamePostUnpublishController extends PhamePostController {
} }
if ($request->isFormPost()) { if ($request->isFormPost()) {
$post->setVisibility(PhamePost::VISIBILITY_DRAFT); $xactions = array();
$post->setDatePublished(0); $xactions[] = id(new PhamePostTransaction())
$post->save(); ->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);
id(new PhamePostEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/')); ->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));

View file

@ -17,6 +17,7 @@ final class PhamePostEditor
$types[] = PhamePostTransaction::TYPE_TITLE; $types[] = PhamePostTransaction::TYPE_TITLE;
$types[] = PhamePostTransaction::TYPE_PHAME_TITLE; $types[] = PhamePostTransaction::TYPE_PHAME_TITLE;
$types[] = PhamePostTransaction::TYPE_BODY; $types[] = PhamePostTransaction::TYPE_BODY;
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
$types[] = PhamePostTransaction::TYPE_COMMENTS_WIDGET; $types[] = PhamePostTransaction::TYPE_COMMENTS_WIDGET;
return $types; return $types;
@ -33,6 +34,8 @@ final class PhamePostEditor
return $object->getPhameTitle(); return $object->getPhameTitle();
case PhamePostTransaction::TYPE_BODY: case PhamePostTransaction::TYPE_BODY:
return $object->getBody(); return $object->getBody();
case PhamePostTransaction::TYPE_VISIBILITY:
return $object->getVisibility();
case PhamePostTransaction::TYPE_COMMENTS_WIDGET: case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $object->getCommentsWidget(); return $object->getCommentsWidget();
} }
@ -46,6 +49,7 @@ final class PhamePostEditor
case PhamePostTransaction::TYPE_TITLE: case PhamePostTransaction::TYPE_TITLE:
case PhamePostTransaction::TYPE_PHAME_TITLE: case PhamePostTransaction::TYPE_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY: case PhamePostTransaction::TYPE_BODY:
case PhamePostTransaction::TYPE_VISIBILITY:
case PhamePostTransaction::TYPE_COMMENTS_WIDGET: case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $xaction->getNewValue(); return $xaction->getNewValue();
} }
@ -62,6 +66,13 @@ final class PhamePostEditor
return $object->setPhameTitle($xaction->getNewValue()); return $object->setPhameTitle($xaction->getNewValue());
case PhamePostTransaction::TYPE_BODY: case PhamePostTransaction::TYPE_BODY:
return $object->setBody($xaction->getNewValue()); return $object->setBody($xaction->getNewValue());
case PhamePostTransaction::TYPE_VISIBILITY:
if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
$object->setDatePublished(time());
} else {
$object->setDatePublished(0);
}
return $object->setVisibility($xaction->getNewValue());
case PhamePostTransaction::TYPE_COMMENTS_WIDGET: case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $object->setCommentsWidget($xaction->getNewValue()); return $object->setCommentsWidget($xaction->getNewValue());
} }
@ -77,6 +88,7 @@ final class PhamePostEditor
case PhamePostTransaction::TYPE_TITLE: case PhamePostTransaction::TYPE_TITLE:
case PhamePostTransaction::TYPE_PHAME_TITLE: case PhamePostTransaction::TYPE_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY: case PhamePostTransaction::TYPE_BODY:
case PhamePostTransaction::TYPE_VISIBILITY:
case PhamePostTransaction::TYPE_COMMENTS_WIDGET: case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return; return;
} }

View file

@ -32,8 +32,8 @@ final class PhamePostSearchEngine
->setLabel(pht('Visibility')) ->setLabel(pht('Visibility'))
->setOptions(array( ->setOptions(array(
'' => pht('All'), '' => pht('All'),
PhamePost::VISIBILITY_PUBLISHED => pht('Live'), PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
PhamePost::VISIBILITY_DRAFT => pht('Draft'), PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
)), )),
); );
} }
@ -45,7 +45,7 @@ final class PhamePostSearchEngine
protected function getBuiltinQueryNames() { protected function getBuiltinQueryNames() {
$names = array( $names = array(
'all' => pht('All Posts'), 'all' => pht('All Posts'),
'live' => pht('Live Posts'), 'live' => pht('Published Posts'),
'draft' => pht('Draft Posts'), 'draft' => pht('Draft Posts'),
); );
return $names; return $names;
@ -60,10 +60,10 @@ final class PhamePostSearchEngine
return $query; return $query;
case 'live': case 'live':
return $query->setParameter( return $query->setParameter(
'visibility', PhamePost::VISIBILITY_PUBLISHED); 'visibility', PhameConstants::VISIBILITY_PUBLISHED);
case 'draft': case 'draft':
return $query->setParameter( return $query->setParameter(
'visibility', PhamePost::VISIBILITY_DRAFT); 'visibility', PhameConstants::VISIBILITY_DRAFT);
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);

View file

@ -13,9 +13,6 @@ final class PhamePost extends PhameDAO
const MARKUP_FIELD_BODY = 'markup:body'; const MARKUP_FIELD_BODY = 'markup:body';
const MARKUP_FIELD_SUMMARY = 'markup:summary'; const MARKUP_FIELD_SUMMARY = 'markup:summary';
const VISIBILITY_DRAFT = 0;
const VISIBILITY_PUBLISHED = 1;
protected $bloggerPHID; protected $bloggerPHID;
protected $title; protected $title;
protected $phameTitle; protected $phameTitle;
@ -37,7 +34,7 @@ final class PhamePost extends PhameDAO
->setBlogPHID($blog->getPHID()) ->setBlogPHID($blog->getPHID())
->setBlog($blog) ->setBlog($blog)
->setDatePublished(0) ->setDatePublished(0)
->setVisibility(self::VISIBILITY_DRAFT); ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
return $post; return $post;
} }
@ -66,7 +63,7 @@ final class PhamePost extends PhameDAO
} }
public function isDraft() { public function isDraft() {
return $this->getVisibility() == self::VISIBILITY_DRAFT; return $this->getVisibility() == PhameConstants::VISIBILITY_DRAFT;
} }
public function getHumanName() { public function getHumanName() {
@ -165,14 +162,6 @@ final class PhamePost extends PhameDAO
); );
} }
public static function getVisibilityOptionsForSelect() {
return array(
self::VISIBILITY_DRAFT => pht('Draft: visible only to me.'),
self::VISIBILITY_PUBLISHED => pht(
'Published: visible to the whole world.'),
);
}
public function getCommentsWidgetOptionsForSelect() { public function getCommentsWidgetOptionsForSelect() {
$current = $this->getCommentsWidget(); $current = $this->getCommentsWidget();
$options = array(); $options = array();

View file

@ -6,6 +6,7 @@ final class PhamePostTransaction
const TYPE_TITLE = 'phame.post.title'; const TYPE_TITLE = 'phame.post.title';
const TYPE_PHAME_TITLE = 'phame.post.phame.title'; const TYPE_PHAME_TITLE = 'phame.post.phame.title';
const TYPE_BODY = 'phame.post.body'; const TYPE_BODY = 'phame.post.body';
const TYPE_VISIBILITY = 'phame.post.visibility';
const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget'; const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget';
const MAILTAG_CONTENT = 'phame-post-content'; const MAILTAG_CONTENT = 'phame-post-content';
@ -54,6 +55,7 @@ final class PhamePostTransaction
break; break;
case self::TYPE_PHAME_TITLE: case self::TYPE_PHAME_TITLE:
case self::TYPE_BODY: case self::TYPE_BODY:
case self::TYPE_VISIBILITY:
case self::TYPE_COMMENTS_WIDGET: case self::TYPE_COMMENTS_WIDGET:
return 'fa-pencil'; return 'fa-pencil';
break; break;
@ -108,6 +110,17 @@ final class PhamePostTransaction
'%s updated the blog post.', '%s updated the blog post.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
break; break;
case self::TYPE_VISIBILITY:
if ($new == PhameConstants::VISIBILITY_DRAFT) {
return pht(
'%s marked this post as a draft.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s published this post.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_PHAME_TITLE: case self::TYPE_PHAME_TITLE:
return pht( return pht(
'%s updated the post\'s Phame title to "%s".', '%s updated the post\'s Phame title to "%s".',
@ -153,6 +166,19 @@ final class PhamePostTransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid)); $this->renderHandleLink($object_phid));
break; break;
case self::TYPE_VISIBILITY:
if ($new == PhameConstants::VISIBILITY_DRAFT) {
return pht(
'%s marked %s as a draft.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
} else {
return pht(
'%s published %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
break;
case self::TYPE_PHAME_TITLE: case self::TYPE_PHAME_TITLE:
return pht( return pht(
'%s updated the Phame title for %s.', '%s updated the Phame title for %s.',
@ -171,19 +197,32 @@ final class PhamePostTransaction
} }
public function getBodyForFeed(PhabricatorFeedStory $story) { public function getBodyForFeed(PhabricatorFeedStory $story) {
$new = $this->getNewValue(); $text = null;
$body = null;
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_TITLE: case self::TYPE_TITLE:
if ($this->getOldValue() === null) {
$post = $story->getPrimaryObject();
$text = $post->getBody();
}
break;
case self::TYPE_VISIBILITY:
if ($this->getNewValue() == PhameConstants::VISIBILITY_PUBLISHED) {
$post = $story->getPrimaryObject();
$text = $post->getBody();
}
break;
case self::TYPE_BODY: case self::TYPE_BODY:
$text = $this->getNewValue();
break;
}
if (strlen($text)) {
return phutil_escape_html_newlines( return phutil_escape_html_newlines(
id(new PhutilUTF8StringTruncator()) id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(128) ->setMaximumGlyphs(128)
->truncateString($new)); ->truncateString($text));
break;
} }
return parent::getBodyForFeed($story); return parent::getBodyForFeed($story);
} }
@ -201,7 +240,6 @@ final class PhamePostTransaction
return parent::getColor(); return parent::getColor();
} }
public function hasChangeDetails() { public function hasChangeDetails() {
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_BODY: case self::TYPE_BODY: