@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Give Phame blog posts configurable interact policies, with a default policy of "Same as Blog"

Summary: Ref T13661. This allows posts to have comments disabled (or restricted) on a per-post basis, and makes them inherit the containing blog policy by default.

Test Plan: Locked a post by editing its policy explicitly; locked a post by editing the containing blog policy.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13661

Differential Revision: https://secure.phabricator.com/D21754

+73 -1
+6
resources/sql/autopatches/20220401.phameinteract.04.postinteract.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phame.phame_post 2 + ADD interactPolicy VARBINARY(64) NOT NULL; 3 + 4 + UPDATE {$NAMESPACE}_phame.phame_post 5 + SET interactPolicy = 'obj.phame.blog' 6 + WHERE interactPolicy = '';
+2
src/__phutil_library_map__.php
··· 5277 5277 'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php', 5278 5278 'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php', 5279 5279 'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php', 5280 + 'PhameInheritBlogPolicyRule' => 'applications/phame/policyrule/PhameInheritBlogPolicyRule.php', 5280 5281 'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php', 5281 5282 'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php', 5282 5283 'PhamePost' => 'applications/phame/storage/PhamePost.php', ··· 12167 12168 'PhameDescriptionView' => 'AphrontTagView', 12168 12169 'PhameDraftListView' => 'AphrontTagView', 12169 12170 'PhameHomeController' => 'PhamePostController', 12171 + 'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule', 12170 12172 'PhameLiveController' => 'PhameController', 12171 12173 'PhameNextPostView' => 'AphrontTagView', 12172 12174 'PhamePost' => array(
+2
src/applications/phame/editor/PhamePostEditor.php
··· 21 21 22 22 public function getTransactionTypes() { 23 23 $types = parent::getTransactionTypes(); 24 + 25 + $types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY; 24 26 $types[] = PhabricatorTransactions::TYPE_COMMENT; 25 27 26 28 return $types;
+51
src/applications/phame/policyrule/PhameInheritBlogPolicyRule.php
··· 1 + <?php 2 + 3 + final class PhameInheritBlogPolicyRule 4 + extends PhabricatorPolicyRule { 5 + 6 + public function getObjectPolicyKey() { 7 + return 'phame.blog'; 8 + } 9 + 10 + public function getObjectPolicyName() { 11 + return pht('Same as Blog'); 12 + } 13 + 14 + public function getPolicyExplanation() { 15 + return pht('Use the same policy as the parent blog.'); 16 + } 17 + 18 + public function getRuleDescription() { 19 + return pht('inherit from blog'); 20 + } 21 + 22 + public function getObjectPolicyIcon() { 23 + return 'fa-feed'; 24 + } 25 + 26 + public function canApplyToObject(PhabricatorPolicyInterface $object) { 27 + return ($object instanceof PhamePost); 28 + } 29 + 30 + public function applyRule( 31 + PhabricatorUser $viewer, 32 + $value, 33 + PhabricatorPolicyInterface $object) { 34 + 35 + // TODO: This is incorrect in the general case, but: "PolicyRule" currently 36 + // does not know which capability it is evaluating (so we can't test for 37 + // the correct capability); and "PhamePost" currently has immutable view 38 + // and edit policies (so we can only arrive here when evaluating the 39 + // interact policy). 40 + 41 + return PhabricatorPolicyFilter::hasCapability( 42 + $viewer, 43 + $object->getBlog(), 44 + PhabricatorPolicyCapability::CAN_INTERACT); 45 + } 46 + 47 + public function getValueControlType() { 48 + return self::CONTROL_TYPE_NONE; 49 + } 50 + 51 + }
+12 -1
src/applications/phame/storage/PhamePost.php
··· 27 27 protected $blogPHID; 28 28 protected $mailKey; 29 29 protected $headerImagePHID; 30 + protected $interactPolicy; 30 31 31 32 private $blog = self::ATTACHABLE; 32 33 private $headerImageFile = self::ATTACHABLE; ··· 40 41 ->setBlogPHID($blog->getPHID()) 41 42 ->attachBlog($blog) 42 43 ->setDatePublished(PhabricatorTime::getNow()) 43 - ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED); 44 + ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED) 45 + ->setInteractPolicy( 46 + id(new PhameInheritBlogPolicyRule()) 47 + ->getObjectPolicyFullKey()); 44 48 45 49 return $post; 46 50 } ··· 140 144 // T6203/NULLABILITY 141 145 // This one probably should be nullable? 142 146 'datePublished' => 'epoch', 147 + 148 + 'interactPolicy' => 'policy', 143 149 ), 144 150 self::CONFIG_KEY_SCHEMA => array( 145 151 'key_phid' => null, ··· 196 202 return array( 197 203 PhabricatorPolicyCapability::CAN_VIEW, 198 204 PhabricatorPolicyCapability::CAN_EDIT, 205 + PhabricatorPolicyCapability::CAN_INTERACT, 199 206 ); 200 207 } 201 208 ··· 220 227 } else { 221 228 return PhabricatorPolicies::POLICY_NOONE; 222 229 } 230 + case PhabricatorPolicyCapability::CAN_INTERACT: 231 + return $this->getInteractPolicy(); 223 232 } 224 233 } 225 234 ··· 230 239 case PhabricatorPolicyCapability::CAN_VIEW: 231 240 case PhabricatorPolicyCapability::CAN_EDIT: 232 241 return ($user->getPHID() == $this->getBloggerPHID()); 242 + case PhabricatorPolicyCapability::CAN_INTERACT: 243 + return false; 233 244 } 234 245 } 235 246