From 967945e4b4e9c2f2c41ffe5672ab3a4f80c7abd1 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Mon, 20 Jun 2016 12:42:53 -0700 Subject: [PATCH] Add ability to link back to parent site in external phame blogs Summary: Ref T9897. Adds a Parent Site and Parent Domain field to allow external sites to link back to parent. Test Plan: Set up ```local.blog.phacility.com```, set parent site to "Phacility" and parent domain to "local.www.phacility.com". Get new crumbs at Blog and Post levels. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9897 Differential Revision: https://secure.phabricator.com/D16150 --- .../20160620.phame.blog.parentdomain.2.sql | 2 + .../20160620.phame.blog.parentsite.1.sql | 2 + .../phame/controller/PhameLiveController.php | 6 +++ .../blog/PhameBlogManageController.php | 21 ++++++--- .../phame/editor/PhameBlogEditEngine.php | 16 +++++++ .../phame/editor/PhameBlogEditor.php | 33 ++++++++++++++ src/applications/phame/storage/PhameBlog.php | 11 ++++- .../phame/storage/PhameBlogTransaction.php | 44 ++++++++++++++++++- 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 resources/sql/autopatches/20160620.phame.blog.parentdomain.2.sql create mode 100644 resources/sql/autopatches/20160620.phame.blog.parentsite.1.sql diff --git a/resources/sql/autopatches/20160620.phame.blog.parentdomain.2.sql b/resources/sql/autopatches/20160620.phame.blog.parentdomain.2.sql new file mode 100644 index 0000000000..3ad4b0d040 --- /dev/null +++ b/resources/sql/autopatches/20160620.phame.blog.parentdomain.2.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phame.phame_blog + ADD parentDomain VARCHAR(128) NOT NULL COLLATE {$COLLATE_TEXT}; diff --git a/resources/sql/autopatches/20160620.phame.blog.parentsite.1.sql b/resources/sql/autopatches/20160620.phame.blog.parentsite.1.sql new file mode 100644 index 0000000000..cfb4f157b1 --- /dev/null +++ b/resources/sql/autopatches/20160620.phame.blog.parentsite.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phame.phame_blog + ADD parentSite VARCHAR(128) NOT NULL COLLATE {$COLLATE_TEXT}; diff --git a/src/applications/phame/controller/PhameLiveController.php b/src/applications/phame/controller/PhameLiveController.php index 3fd9f64600..ba2b65d9f8 100644 --- a/src/applications/phame/controller/PhameLiveController.php +++ b/src/applications/phame/controller/PhameLiveController.php @@ -159,6 +159,12 @@ abstract class PhameLiveController extends PhameController { // "Blogs" crumb into the crumbs list. if ($is_external) { $crumbs = new PHUICrumbsView(); + // Link back to parent site + if ($blog->getParentSite() && $blog->getParentDomain()) { + $crumbs->addTextCrumb( + $blog->getParentSite(), + $blog->getExternalParentURI()); + } } else { $crumbs = parent::buildApplicationCrumbs(); $crumbs->addTextCrumb( diff --git a/src/applications/phame/controller/blog/PhameBlogManageController.php b/src/applications/phame/controller/blog/PhameBlogManageController.php index bcd9c9456b..a87b02070d 100644 --- a/src/applications/phame/controller/blog/PhameBlogManageController.php +++ b/src/applications/phame/controller/blog/PhameBlogManageController.php @@ -95,8 +95,7 @@ final class PhameBlogManageController extends PhameBlogController { Javelin::initBehavior('phabricator-tooltips'); $properties = id(new PHUIPropertyListView()) - ->setUser($viewer) - ->setObject($blog); + ->setUser($viewer); $domain = $blog->getDomain(); if (!$domain) { @@ -105,6 +104,20 @@ final class PhameBlogManageController extends PhameBlogController { $properties->addProperty(pht('Domain'), $domain); + $parent_site = $blog->getParentSite(); + if (!$parent_site) { + $parent_site = phutil_tag('em', array(), pht('No parent site')); + } + + $properties->addProperty(pht('Parent Site'), $parent_site); + + $parent_domain = $blog->getParentDomain(); + if (!$parent_domain) { + $parent_domain = phutil_tag('em', array(), pht('No parent domain')); + } + + $properties->addProperty(pht('Parent Domain'), $parent_domain); + $feed_uri = PhabricatorEnv::getProductionURI( $this->getApplicationURI('blog/feed/'.$blog->getID().'/')); $properties->addProperty( @@ -133,8 +146,6 @@ final class PhameBlogManageController extends PhameBlogController { ->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION) ->process(); - $properties->invokeWillRenderEvent(); - $description = $blog->getDescription(); if (strlen($description)) { $description = new PHUIRemarkupView($viewer, $description); @@ -150,7 +161,7 @@ final class PhameBlogManageController extends PhameBlogController { private function buildCurtain(PhameBlog $blog) { $viewer = $this->getViewer(); - $curtain = $this->newCurtainView($viewer); + $curtain = $this->newCurtainView($blog); $actions = id(new PhabricatorActionListView()) ->setObject($blog) diff --git a/src/applications/phame/editor/PhameBlogEditEngine.php b/src/applications/phame/editor/PhameBlogEditEngine.php index 9cc7217147..70d878e15a 100644 --- a/src/applications/phame/editor/PhameBlogEditEngine.php +++ b/src/applications/phame/editor/PhameBlogEditEngine.php @@ -101,6 +101,22 @@ final class PhameBlogEditEngine ->setConduitTypeDescription(pht('New blog domain.')) ->setValue($object->getDomain()) ->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN), + id(new PhabricatorTextEditField()) + ->setKey('parentSite') + ->setLabel(pht('Parent Site')) + ->setDescription(pht('Blog parent site name.')) + ->setConduitDescription(pht('Change the blog parent site name.')) + ->setConduitTypeDescription(pht('New blog parent site name.')) + ->setValue($object->getParentSite()) + ->setTransactionType(PhameBlogTransaction::TYPE_PARENTSITE), + id(new PhabricatorTextEditField()) + ->setKey('parentDomain') + ->setLabel(pht('Parent Domain')) + ->setDescription(pht('Blog parent domain name.')) + ->setConduitDescription(pht('Change the blog parent domain.')) + ->setConduitTypeDescription(pht('New blog parent domain.')) + ->setValue($object->getParentDomain()) + ->setTransactionType(PhameBlogTransaction::TYPE_PARENTDOMAIN), id(new PhabricatorSelectEditField()) ->setKey('status') ->setLabel(pht('Status')) diff --git a/src/applications/phame/editor/PhameBlogEditor.php b/src/applications/phame/editor/PhameBlogEditor.php index ec0cbe9e06..d2a9fcbc1f 100644 --- a/src/applications/phame/editor/PhameBlogEditor.php +++ b/src/applications/phame/editor/PhameBlogEditor.php @@ -18,6 +18,8 @@ final class PhameBlogEditor $types[] = PhameBlogTransaction::TYPE_SUBTITLE; $types[] = PhameBlogTransaction::TYPE_DESCRIPTION; $types[] = PhameBlogTransaction::TYPE_DOMAIN; + $types[] = PhameBlogTransaction::TYPE_PARENTSITE; + $types[] = PhameBlogTransaction::TYPE_PARENTDOMAIN; $types[] = PhameBlogTransaction::TYPE_STATUS; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; @@ -38,6 +40,10 @@ final class PhameBlogEditor return $object->getDescription(); case PhameBlogTransaction::TYPE_DOMAIN: return $object->getDomain(); + case PhameBlogTransaction::TYPE_PARENTSITE: + return $object->getParentSite(); + case PhameBlogTransaction::TYPE_PARENTDOMAIN: + return $object->getParentDomain(); case PhameBlogTransaction::TYPE_STATUS: return $object->getStatus(); } @@ -52,6 +58,8 @@ final class PhameBlogEditor case PhameBlogTransaction::TYPE_SUBTITLE: case PhameBlogTransaction::TYPE_DESCRIPTION: case PhameBlogTransaction::TYPE_STATUS: + case PhameBlogTransaction::TYPE_PARENTSITE: + case PhameBlogTransaction::TYPE_PARENTDOMAIN: return $xaction->getNewValue(); case PhameBlogTransaction::TYPE_DOMAIN: $domain = $xaction->getNewValue(); @@ -77,6 +85,10 @@ final class PhameBlogEditor return $object->setDomain($xaction->getNewValue()); case PhameBlogTransaction::TYPE_STATUS: return $object->setStatus($xaction->getNewValue()); + case PhameBlogTransaction::TYPE_PARENTSITE: + return $object->setParentSite($xaction->getNewValue()); + case PhameBlogTransaction::TYPE_PARENTDOMAIN: + return $object->setParentDomain($xaction->getNewValue()); } return parent::applyCustomInternalTransaction($object, $xaction); @@ -91,6 +103,8 @@ final class PhameBlogEditor case PhameBlogTransaction::TYPE_SUBTITLE: case PhameBlogTransaction::TYPE_DESCRIPTION: case PhameBlogTransaction::TYPE_DOMAIN: + case PhameBlogTransaction::TYPE_PARENTSITE: + case PhameBlogTransaction::TYPE_PARENTDOMAIN: case PhameBlogTransaction::TYPE_STATUS: return; } @@ -123,6 +137,25 @@ final class PhameBlogEditor $errors[] = $error; } break; + case PhameBlogTransaction::TYPE_PARENTDOMAIN: + if (!$xactions) { + continue; + } + $parent_domain = last($xactions)->getNewValue(); + if (empty($parent_domain)) { + continue; + } + try { + PhabricatorEnv::requireValidRemoteURIForLink($parent_domain); + } catch (Exception $ex) { + $error = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Invalid URI'), + pht('Parent Domain must be set to a valid Remote URI.'), + nonempty(last($xactions), null)); + $errors[] = $error; + } + break; case PhameBlogTransaction::TYPE_DOMAIN: if (!$xactions) { continue; diff --git a/src/applications/phame/storage/PhameBlog.php b/src/applications/phame/storage/PhameBlog.php index b956eaa1c6..4f092cd3f1 100644 --- a/src/applications/phame/storage/PhameBlog.php +++ b/src/applications/phame/storage/PhameBlog.php @@ -18,6 +18,8 @@ final class PhameBlog extends PhameDAO protected $subtitle; protected $description; protected $domain; + protected $parentSite; + protected $parentDomain; protected $configData; protected $creatorPHID; protected $viewPolicy; @@ -44,6 +46,8 @@ final class PhameBlog extends PhameDAO 'subtitle' => 'text64', 'description' => 'text', 'domain' => 'text128?', + 'parentSite' => 'text128', + 'parentDomain' => 'text128', 'status' => 'text32', 'mailKey' => 'bytes20', 'profileImagePHID' => 'phid?', @@ -187,11 +191,16 @@ final class PhameBlog extends PhameDAO } public function getExternalLiveURI() { - $domain = $this->getDomain(); $uri = new PhutilURI('http://'.$this->getDomain().'/'); return (string)$uri; } + public function getExternalParentURI() { + $uri = $this->getParentDomain(); + PhabricatorEnv::requireValidRemoteURIForLink($uri); + return (string)$uri; + } + public function getInternalLiveURI() { return '/phame/live/'.$this->getID().'/'; } diff --git a/src/applications/phame/storage/PhameBlogTransaction.php b/src/applications/phame/storage/PhameBlogTransaction.php index 8d71fa0ee9..91c6552666 100644 --- a/src/applications/phame/storage/PhameBlogTransaction.php +++ b/src/applications/phame/storage/PhameBlogTransaction.php @@ -8,6 +8,8 @@ final class PhameBlogTransaction const TYPE_DESCRIPTION = 'phame.blog.description'; const TYPE_DOMAIN = 'phame.blog.domain'; const TYPE_STATUS = 'phame.blog.status'; + const TYPE_PARENTSITE = 'phame.blog.parent.site'; + const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain'; const MAILTAG_DETAILS = 'phame-blog-details'; const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers'; @@ -65,7 +67,7 @@ final class PhameBlogTransaction switch ($this->getTransactionType()) { case self::TYPE_STATUS: if ($new == PhameBlog::STATUS_ARCHIVED) { - return 'red'; + return 'violet'; } else { return 'green'; } @@ -84,6 +86,8 @@ final class PhameBlogTransaction case self::TYPE_SUBTITLE: case self::TYPE_DESCRIPTION: case self::TYPE_DOMAIN: + case self::TYPE_PARENTSITE: + case self::TYPE_PARENTDOMAIN: $tags[] = self::MAILTAG_DETAILS; break; default: @@ -142,6 +146,32 @@ final class PhameBlogTransaction $this->renderHandleLink($author_phid), $new); break; + case self::TYPE_PARENTSITE: + if ($old === null) { + return pht( + '%s set this blog\'s parent site to "%s".', + $this->renderHandleLink($author_phid), + $new); + } else { + return pht( + '%s updated the blog\'s parent site to "%s".', + $this->renderHandleLink($author_phid), + $new); + } + break; + case self::TYPE_PARENTDOMAIN: + if ($old === null) { + return pht( + '%s set this blog\'s parent domain to "%s".', + $this->renderHandleLink($author_phid), + $new); + } else { + return pht( + '%s updated the blog\'s parent domain to "%s".', + $this->renderHandleLink($author_phid), + $new); + } + break; case self::TYPE_STATUS: switch ($new) { case PhameBlog::STATUS_ACTIVE: @@ -206,6 +236,18 @@ final class PhameBlogTransaction $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; + case self::TYPE_PARENTSITE: + return pht( + '%s updated the parent site for %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + break; + case self::TYPE_PARENTDOMAIN: + return pht( + '%s updated the parent domain for %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + break; case self::TYPE_STATUS: switch ($new) { case PhameBlog::STATUS_ACTIVE: