1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
epriestley 2022-04-01 12:29:34 -07:00
parent f555fbcb50
commit aae23f0204
5 changed files with 73 additions and 1 deletions

View file

@ -0,0 +1,6 @@
ALTER TABLE {$NAMESPACE}_phame.phame_post
ADD interactPolicy VARBINARY(64) NOT NULL;
UPDATE {$NAMESPACE}_phame.phame_post
SET interactPolicy = 'obj.phame.blog'
WHERE interactPolicy = '';

View file

@ -5277,6 +5277,7 @@ phutil_register_library_map(array(
'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php',
'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php',
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
'PhameInheritBlogPolicyRule' => 'applications/phame/policyrule/PhameInheritBlogPolicyRule.php',
'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php',
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
'PhamePost' => 'applications/phame/storage/PhamePost.php',
@ -12167,6 +12168,7 @@ phutil_register_library_map(array(
'PhameDescriptionView' => 'AphrontTagView',
'PhameDraftListView' => 'AphrontTagView',
'PhameHomeController' => 'PhamePostController',
'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule',
'PhameLiveController' => 'PhameController',
'PhameNextPostView' => 'AphrontTagView',
'PhamePost' => array(

View file

@ -21,6 +21,8 @@ final class PhamePostEditor
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
return $types;

View file

@ -0,0 +1,51 @@
<?php
final class PhameInheritBlogPolicyRule
extends PhabricatorPolicyRule {
public function getObjectPolicyKey() {
return 'phame.blog';
}
public function getObjectPolicyName() {
return pht('Same as Blog');
}
public function getPolicyExplanation() {
return pht('Use the same policy as the parent blog.');
}
public function getRuleDescription() {
return pht('inherit from blog');
}
public function getObjectPolicyIcon() {
return 'fa-feed';
}
public function canApplyToObject(PhabricatorPolicyInterface $object) {
return ($object instanceof PhamePost);
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
// TODO: This is incorrect in the general case, but: "PolicyRule" currently
// does not know which capability it is evaluating (so we can't test for
// the correct capability); and "PhamePost" currently has immutable view
// and edit policies (so we can only arrive here when evaluating the
// interact policy).
return PhabricatorPolicyFilter::hasCapability(
$viewer,
$object->getBlog(),
PhabricatorPolicyCapability::CAN_INTERACT);
}
public function getValueControlType() {
return self::CONTROL_TYPE_NONE;
}
}

View file

@ -27,6 +27,7 @@ final class PhamePost extends PhameDAO
protected $blogPHID;
protected $mailKey;
protected $headerImagePHID;
protected $interactPolicy;
private $blog = self::ATTACHABLE;
private $headerImageFile = self::ATTACHABLE;
@ -40,7 +41,10 @@ final class PhamePost extends PhameDAO
->setBlogPHID($blog->getPHID())
->attachBlog($blog)
->setDatePublished(PhabricatorTime::getNow())
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->setInteractPolicy(
id(new PhameInheritBlogPolicyRule())
->getObjectPolicyFullKey());
return $post;
}
@ -140,6 +144,8 @@ final class PhamePost extends PhameDAO
// T6203/NULLABILITY
// This one probably should be nullable?
'datePublished' => 'epoch',
'interactPolicy' => 'policy',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
@ -196,6 +202,7 @@ final class PhamePost extends PhameDAO
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_INTERACT,
);
}
@ -220,6 +227,8 @@ final class PhamePost extends PhameDAO
} else {
return PhabricatorPolicies::POLICY_NOONE;
}
case PhabricatorPolicyCapability::CAN_INTERACT:
return $this->getInteractPolicy();
}
}
@ -230,6 +239,8 @@ final class PhamePost extends PhameDAO
case PhabricatorPolicyCapability::CAN_VIEW:
case PhabricatorPolicyCapability::CAN_EDIT:
return ($user->getPHID() == $this->getBloggerPHID());
case PhabricatorPolicyCapability::CAN_INTERACT:
return false;
}
}