mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +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:
parent
f555fbcb50
commit
aae23f0204
5 changed files with 73 additions and 1 deletions
|
@ -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 = '';
|
|
@ -5277,6 +5277,7 @@ phutil_register_library_map(array(
|
||||||
'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php',
|
'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php',
|
||||||
'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php',
|
'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php',
|
||||||
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
|
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
|
||||||
|
'PhameInheritBlogPolicyRule' => 'applications/phame/policyrule/PhameInheritBlogPolicyRule.php',
|
||||||
'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php',
|
'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php',
|
||||||
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
|
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
|
||||||
'PhamePost' => 'applications/phame/storage/PhamePost.php',
|
'PhamePost' => 'applications/phame/storage/PhamePost.php',
|
||||||
|
@ -12167,6 +12168,7 @@ phutil_register_library_map(array(
|
||||||
'PhameDescriptionView' => 'AphrontTagView',
|
'PhameDescriptionView' => 'AphrontTagView',
|
||||||
'PhameDraftListView' => 'AphrontTagView',
|
'PhameDraftListView' => 'AphrontTagView',
|
||||||
'PhameHomeController' => 'PhamePostController',
|
'PhameHomeController' => 'PhamePostController',
|
||||||
|
'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule',
|
||||||
'PhameLiveController' => 'PhameController',
|
'PhameLiveController' => 'PhameController',
|
||||||
'PhameNextPostView' => 'AphrontTagView',
|
'PhameNextPostView' => 'AphrontTagView',
|
||||||
'PhamePost' => array(
|
'PhamePost' => array(
|
||||||
|
|
|
@ -21,6 +21,8 @@ final class PhamePostEditor
|
||||||
|
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes() {
|
||||||
$types = parent::getTransactionTypes();
|
$types = parent::getTransactionTypes();
|
||||||
|
|
||||||
|
$types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
|
||||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ final class PhamePost extends PhameDAO
|
||||||
protected $blogPHID;
|
protected $blogPHID;
|
||||||
protected $mailKey;
|
protected $mailKey;
|
||||||
protected $headerImagePHID;
|
protected $headerImagePHID;
|
||||||
|
protected $interactPolicy;
|
||||||
|
|
||||||
private $blog = self::ATTACHABLE;
|
private $blog = self::ATTACHABLE;
|
||||||
private $headerImageFile = self::ATTACHABLE;
|
private $headerImageFile = self::ATTACHABLE;
|
||||||
|
@ -40,7 +41,10 @@ final class PhamePost extends PhameDAO
|
||||||
->setBlogPHID($blog->getPHID())
|
->setBlogPHID($blog->getPHID())
|
||||||
->attachBlog($blog)
|
->attachBlog($blog)
|
||||||
->setDatePublished(PhabricatorTime::getNow())
|
->setDatePublished(PhabricatorTime::getNow())
|
||||||
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
|
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED)
|
||||||
|
->setInteractPolicy(
|
||||||
|
id(new PhameInheritBlogPolicyRule())
|
||||||
|
->getObjectPolicyFullKey());
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
@ -140,6 +144,8 @@ final class PhamePost extends PhameDAO
|
||||||
// T6203/NULLABILITY
|
// T6203/NULLABILITY
|
||||||
// This one probably should be nullable?
|
// This one probably should be nullable?
|
||||||
'datePublished' => 'epoch',
|
'datePublished' => 'epoch',
|
||||||
|
|
||||||
|
'interactPolicy' => 'policy',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
'key_phid' => null,
|
'key_phid' => null,
|
||||||
|
@ -196,6 +202,7 @@ final class PhamePost extends PhameDAO
|
||||||
return array(
|
return array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
PhabricatorPolicyCapability::CAN_INTERACT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +227,8 @@ final class PhamePost extends PhameDAO
|
||||||
} else {
|
} else {
|
||||||
return PhabricatorPolicies::POLICY_NOONE;
|
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_VIEW:
|
||||||
case PhabricatorPolicyCapability::CAN_EDIT:
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||||
return ($user->getPHID() == $this->getBloggerPHID());
|
return ($user->getPHID() == $this->getBloggerPHID());
|
||||||
|
case PhabricatorPolicyCapability::CAN_INTERACT:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue