mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 21:10:56 +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:
parent
268fac25d5
commit
f8b085c574
12 changed files with 150 additions and 47 deletions
|
@ -3262,6 +3262,7 @@ phutil_register_library_map(array(
|
|||
'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php',
|
||||
'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php',
|
||||
'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php',
|
||||
'PhameConstants' => 'applications/phame/constants/PhameConstants.php',
|
||||
'PhameController' => 'applications/phame/controller/PhameController.php',
|
||||
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
|
||||
'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
|
||||
|
@ -7525,6 +7526,7 @@ phutil_register_library_map(array(
|
|||
'PhameBlogViewController' => 'PhameBlogController',
|
||||
'PhameCelerityResources' => 'CelerityResources',
|
||||
'PhameConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'PhameConstants' => 'Phobject',
|
||||
'PhameController' => 'PhabricatorController',
|
||||
'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod',
|
||||
'PhameDAO' => 'PhabricatorLiskDAO',
|
||||
|
|
|
@ -85,7 +85,7 @@ final class PhameCreatePostConduitAPIMethod extends PhameConduitAPIMethod {
|
|||
$is_draft = $request->getValue('isDraft', false);
|
||||
if (!$is_draft) {
|
||||
$post->setDatePublished(time());
|
||||
$post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
|
||||
$post->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
|
||||
}
|
||||
$post->setTitle($title);
|
||||
$phame_title = $request->getValue(
|
||||
|
|
|
@ -65,9 +65,9 @@ final class PhameQueryPostsConduitAPIMethod extends PhameConduitAPIMethod {
|
|||
|
||||
$published = $request->getValue('published', null);
|
||||
if ($published === true) {
|
||||
$query->withVisibility(PhamePost::VISIBILITY_PUBLISHED);
|
||||
$query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED);
|
||||
} else if ($published === false) {
|
||||
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
|
||||
$query->withVisibility(PhameConstants::VISIBILITY_DRAFT);
|
||||
}
|
||||
|
||||
$published_after = $request->getValue('publishedAfter', null);
|
||||
|
|
23
src/applications/phame/constants/PhameConstants.php
Normal file
23
src/applications/phame/constants/PhameConstants.php
Normal 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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ final class PhameBlogFeedController extends PhameBlogController {
|
|||
$posts = id(new PhamePostQuery())
|
||||
->setViewer($viewer)
|
||||
->withBlogPHIDs(array($blog->getPHID()))
|
||||
->withVisibility(PhamePost::VISIBILITY_PUBLISHED)
|
||||
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
|
||||
->execute();
|
||||
|
||||
$blog_uri = PhabricatorEnv::getProductionURI(
|
||||
|
|
|
@ -45,25 +45,27 @@ final class PhamePostEditController extends PhamePostController {
|
|||
$post = PhamePost::initializePost($viewer, $blog);
|
||||
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/');
|
||||
|
||||
$submit_button = pht('Save Draft');
|
||||
$page_title = pht('Create Post');
|
||||
$submit_button = pht('Create Post');
|
||||
$page_title = pht('Create Post');
|
||||
}
|
||||
|
||||
$title = $post->getTitle();
|
||||
$phame_title = $post->getPhameTitle();
|
||||
$body = $post->getBody();
|
||||
$title = $post->getTitle();
|
||||
$phame_title = $post->getPhameTitle();
|
||||
$body = $post->getBody();
|
||||
$comments_widget = $post->getCommentsWidget();
|
||||
$visibility = $post->getVisibility();
|
||||
|
||||
$e_title = true;
|
||||
$e_phame_title = true;
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$title = $request->getStr('title');
|
||||
$phame_title = $request->getStr('phame_title');
|
||||
$phame_title = PhabricatorSlug::normalize($phame_title);
|
||||
$body = $request->getStr('body');
|
||||
$title = $request->getStr('title');
|
||||
$phame_title = $request->getStr('phame_title');
|
||||
$phame_title = PhabricatorSlug::normalize($phame_title);
|
||||
$body = $request->getStr('body');
|
||||
$comments_widget = $request->getStr('comments_widget');
|
||||
$v_projects = $request->getArr('projects');
|
||||
$v_projects = $request->getArr('projects');
|
||||
$visibility = $request->getInt('visibility');
|
||||
|
||||
$xactions = array(
|
||||
id(new PhamePostTransaction())
|
||||
|
@ -75,6 +77,9 @@ final class PhamePostEditController extends PhamePostController {
|
|||
id(new PhamePostTransaction())
|
||||
->setTransactionType(PhamePostTransaction::TYPE_BODY)
|
||||
->setNewValue($body),
|
||||
id(new PhamePostTransaction())
|
||||
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
|
||||
->setNewValue($visibility),
|
||||
id(new PhamePostTransaction())
|
||||
->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET)
|
||||
->setNewValue($comments_widget),
|
||||
|
@ -134,6 +139,12 @@ final class PhamePostEditController extends PhamePostController {
|
|||
'with underscores for spaces. '.
|
||||
'Formatting is enforced.'))
|
||||
->setError($e_phame_title))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Visibility'))
|
||||
->setName('visibility')
|
||||
->setvalue($visibility)
|
||||
->setOptions(PhameConstants::getPhamePostStatusMap()))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setLabel(pht('Body'))
|
||||
|
|
|
@ -21,9 +21,23 @@ final class PhamePostPublishController extends PhamePostController {
|
|||
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
|
||||
$post->setDatePublished(time());
|
||||
$post->save();
|
||||
$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);
|
||||
|
||||
id(new PhamePostEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
->applyTransactions($post, $xactions);
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,23 @@ final class PhamePostUnpublishController extends PhamePostController {
|
|||
}
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$post->setVisibility(PhamePost::VISIBILITY_DRAFT);
|
||||
$post->setDatePublished(0);
|
||||
$post->save();
|
||||
$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);
|
||||
|
||||
id(new PhamePostEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
->applyTransactions($post, $xactions);
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));
|
||||
|
|
|
@ -17,6 +17,7 @@ final class PhamePostEditor
|
|||
$types[] = PhamePostTransaction::TYPE_TITLE;
|
||||
$types[] = PhamePostTransaction::TYPE_PHAME_TITLE;
|
||||
$types[] = PhamePostTransaction::TYPE_BODY;
|
||||
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
|
||||
$types[] = PhamePostTransaction::TYPE_COMMENTS_WIDGET;
|
||||
|
||||
return $types;
|
||||
|
@ -33,6 +34,8 @@ final class PhamePostEditor
|
|||
return $object->getPhameTitle();
|
||||
case PhamePostTransaction::TYPE_BODY:
|
||||
return $object->getBody();
|
||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
||||
return $object->getVisibility();
|
||||
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
|
||||
return $object->getCommentsWidget();
|
||||
}
|
||||
|
@ -46,6 +49,7 @@ final class PhamePostEditor
|
|||
case PhamePostTransaction::TYPE_TITLE:
|
||||
case PhamePostTransaction::TYPE_PHAME_TITLE:
|
||||
case PhamePostTransaction::TYPE_BODY:
|
||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
||||
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
|
@ -62,6 +66,13 @@ final class PhamePostEditor
|
|||
return $object->setPhameTitle($xaction->getNewValue());
|
||||
case PhamePostTransaction::TYPE_BODY:
|
||||
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:
|
||||
return $object->setCommentsWidget($xaction->getNewValue());
|
||||
}
|
||||
|
@ -77,6 +88,7 @@ final class PhamePostEditor
|
|||
case PhamePostTransaction::TYPE_TITLE:
|
||||
case PhamePostTransaction::TYPE_PHAME_TITLE:
|
||||
case PhamePostTransaction::TYPE_BODY:
|
||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
||||
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ final class PhamePostSearchEngine
|
|||
->setLabel(pht('Visibility'))
|
||||
->setOptions(array(
|
||||
'' => pht('All'),
|
||||
PhamePost::VISIBILITY_PUBLISHED => pht('Live'),
|
||||
PhamePost::VISIBILITY_DRAFT => pht('Draft'),
|
||||
PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
|
||||
PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ final class PhamePostSearchEngine
|
|||
protected function getBuiltinQueryNames() {
|
||||
$names = array(
|
||||
'all' => pht('All Posts'),
|
||||
'live' => pht('Live Posts'),
|
||||
'live' => pht('Published Posts'),
|
||||
'draft' => pht('Draft Posts'),
|
||||
);
|
||||
return $names;
|
||||
|
@ -60,10 +60,10 @@ final class PhamePostSearchEngine
|
|||
return $query;
|
||||
case 'live':
|
||||
return $query->setParameter(
|
||||
'visibility', PhamePost::VISIBILITY_PUBLISHED);
|
||||
'visibility', PhameConstants::VISIBILITY_PUBLISHED);
|
||||
case 'draft':
|
||||
return $query->setParameter(
|
||||
'visibility', PhamePost::VISIBILITY_DRAFT);
|
||||
'visibility', PhameConstants::VISIBILITY_DRAFT);
|
||||
}
|
||||
|
||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
|
|
|
@ -13,9 +13,6 @@ final class PhamePost extends PhameDAO
|
|||
const MARKUP_FIELD_BODY = 'markup:body';
|
||||
const MARKUP_FIELD_SUMMARY = 'markup:summary';
|
||||
|
||||
const VISIBILITY_DRAFT = 0;
|
||||
const VISIBILITY_PUBLISHED = 1;
|
||||
|
||||
protected $bloggerPHID;
|
||||
protected $title;
|
||||
protected $phameTitle;
|
||||
|
@ -37,7 +34,7 @@ final class PhamePost extends PhameDAO
|
|||
->setBlogPHID($blog->getPHID())
|
||||
->setBlog($blog)
|
||||
->setDatePublished(0)
|
||||
->setVisibility(self::VISIBILITY_DRAFT);
|
||||
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
|
||||
return $post;
|
||||
}
|
||||
|
||||
|
@ -66,7 +63,7 @@ final class PhamePost extends PhameDAO
|
|||
}
|
||||
|
||||
public function isDraft() {
|
||||
return $this->getVisibility() == self::VISIBILITY_DRAFT;
|
||||
return $this->getVisibility() == PhameConstants::VISIBILITY_DRAFT;
|
||||
}
|
||||
|
||||
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() {
|
||||
$current = $this->getCommentsWidget();
|
||||
$options = array();
|
||||
|
|
|
@ -6,6 +6,7 @@ final class PhamePostTransaction
|
|||
const TYPE_TITLE = 'phame.post.title';
|
||||
const TYPE_PHAME_TITLE = 'phame.post.phame.title';
|
||||
const TYPE_BODY = 'phame.post.body';
|
||||
const TYPE_VISIBILITY = 'phame.post.visibility';
|
||||
const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget';
|
||||
|
||||
const MAILTAG_CONTENT = 'phame-post-content';
|
||||
|
@ -54,6 +55,7 @@ final class PhamePostTransaction
|
|||
break;
|
||||
case self::TYPE_PHAME_TITLE:
|
||||
case self::TYPE_BODY:
|
||||
case self::TYPE_VISIBILITY:
|
||||
case self::TYPE_COMMENTS_WIDGET:
|
||||
return 'fa-pencil';
|
||||
break;
|
||||
|
@ -108,6 +110,17 @@ final class PhamePostTransaction
|
|||
'%s updated the blog post.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
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:
|
||||
return pht(
|
||||
'%s updated the post\'s Phame title to "%s".',
|
||||
|
@ -153,6 +166,19 @@ final class PhamePostTransaction
|
|||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
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:
|
||||
return pht(
|
||||
'%s updated the Phame title for %s.',
|
||||
|
@ -171,19 +197,32 @@ final class PhamePostTransaction
|
|||
}
|
||||
|
||||
public function getBodyForFeed(PhabricatorFeedStory $story) {
|
||||
$new = $this->getNewValue();
|
||||
|
||||
$body = null;
|
||||
|
||||
$text = null;
|
||||
switch ($this->getTransactionType()) {
|
||||
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:
|
||||
return phutil_escape_html_newlines(
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($new));
|
||||
$text = $this->getNewValue();
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen($text)) {
|
||||
return phutil_escape_html_newlines(
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($text));
|
||||
}
|
||||
|
||||
return parent::getBodyForFeed($story);
|
||||
}
|
||||
|
||||
|
@ -201,7 +240,6 @@ final class PhamePostTransaction
|
|||
return parent::getColor();
|
||||
}
|
||||
|
||||
|
||||
public function hasChangeDetails() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_BODY:
|
||||
|
|
Loading…
Reference in a new issue