Skip to content

Commit aae23f0

Browse files
author
epriestley
committedApr 1, 2022
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
1 parent f555fbc commit aae23f0

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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 = '';

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,7 @@
52775277
'PhameDescriptionView' => 'applications/phame/view/PhameDescriptionView.php',
52785278
'PhameDraftListView' => 'applications/phame/view/PhameDraftListView.php',
52795279
'PhameHomeController' => 'applications/phame/controller/PhameHomeController.php',
5280+
'PhameInheritBlogPolicyRule' => 'applications/phame/policyrule/PhameInheritBlogPolicyRule.php',
52805281
'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php',
52815282
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
52825283
'PhamePost' => 'applications/phame/storage/PhamePost.php',
@@ -12167,6 +12168,7 @@
1216712168
'PhameDescriptionView' => 'AphrontTagView',
1216812169
'PhameDraftListView' => 'AphrontTagView',
1216912170
'PhameHomeController' => 'PhamePostController',
12171+
'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule',
1217012172
'PhameLiveController' => 'PhameController',
1217112173
'PhameNextPostView' => 'AphrontTagView',
1217212174
'PhamePost' => array(

‎src/applications/phame/editor/PhamePostEditor.php

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function getCreateObjectTitleForFeed($author, $object) {
2121

2222
public function getTransactionTypes() {
2323
$types = parent::getTransactionTypes();
24+
25+
$types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
2426
$types[] = PhabricatorTransactions::TYPE_COMMENT;
2527

2628
return $types;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

‎src/applications/phame/storage/PhamePost.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class PhamePost extends PhameDAO
2727
protected $blogPHID;
2828
protected $mailKey;
2929
protected $headerImagePHID;
30+
protected $interactPolicy;
3031

3132
private $blog = self::ATTACHABLE;
3233
private $headerImageFile = self::ATTACHABLE;
@@ -40,7 +41,10 @@ public static function initializePost(
4041
->setBlogPHID($blog->getPHID())
4142
->attachBlog($blog)
4243
->setDatePublished(PhabricatorTime::getNow())
43-
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
44+
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED)
45+
->setInteractPolicy(
46+
id(new PhameInheritBlogPolicyRule())
47+
->getObjectPolicyFullKey());
4448

4549
return $post;
4650
}
@@ -140,6 +144,8 @@ protected function getConfiguration() {
140144
// T6203/NULLABILITY
141145
// This one probably should be nullable?
142146
'datePublished' => 'epoch',
147+
148+
'interactPolicy' => 'policy',
143149
),
144150
self::CONFIG_KEY_SCHEMA => array(
145151
'key_phid' => null,
@@ -196,6 +202,7 @@ public function getCapabilities() {
196202
return array(
197203
PhabricatorPolicyCapability::CAN_VIEW,
198204
PhabricatorPolicyCapability::CAN_EDIT,
205+
PhabricatorPolicyCapability::CAN_INTERACT,
199206
);
200207
}
201208

@@ -220,6 +227,8 @@ public function getPolicy($capability) {
220227
} else {
221228
return PhabricatorPolicies::POLICY_NOONE;
222229
}
230+
case PhabricatorPolicyCapability::CAN_INTERACT:
231+
return $this->getInteractPolicy();
223232
}
224233
}
225234

@@ -230,6 +239,8 @@ public function hasAutomaticCapability($capability, PhabricatorUser $user) {
230239
case PhabricatorPolicyCapability::CAN_VIEW:
231240
case PhabricatorPolicyCapability::CAN_EDIT:
232241
return ($user->getPHID() == $this->getBloggerPHID());
242+
case PhabricatorPolicyCapability::CAN_INTERACT:
243+
return false;
233244
}
234245
}
235246

0 commit comments

Comments
 (0)
Failed to load comments.