Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14115612
D21754.id51861.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D21754.id51861.diff
View Options
diff --git a/resources/sql/autopatches/20220401.phameinteract.04.postinteract.sql b/resources/sql/autopatches/20220401.phameinteract.04.postinteract.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20220401.phameinteract.04.postinteract.sql
@@ -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 = '';
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -5277,6 +5277,7 @@
'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 @@
'PhameDescriptionView' => 'AphrontTagView',
'PhameDraftListView' => 'AphrontTagView',
'PhameHomeController' => 'PhamePostController',
+ 'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule',
'PhameLiveController' => 'PhameController',
'PhameNextPostView' => 'AphrontTagView',
'PhamePost' => array(
diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php
--- a/src/applications/phame/editor/PhamePostEditor.php
+++ b/src/applications/phame/editor/PhamePostEditor.php
@@ -21,6 +21,8 @@
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
+
+ $types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
return $types;
diff --git a/src/applications/phame/policyrule/PhameInheritBlogPolicyRule.php b/src/applications/phame/policyrule/PhameInheritBlogPolicyRule.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/policyrule/PhameInheritBlogPolicyRule.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php
--- a/src/applications/phame/storage/PhamePost.php
+++ b/src/applications/phame/storage/PhamePost.php
@@ -27,6 +27,7 @@
protected $blogPHID;
protected $mailKey;
protected $headerImagePHID;
+ protected $interactPolicy;
private $blog = self::ATTACHABLE;
private $headerImageFile = self::ATTACHABLE;
@@ -40,7 +41,10 @@
->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 @@
// T6203/NULLABILITY
// This one probably should be nullable?
'datePublished' => 'epoch',
+
+ 'interactPolicy' => 'policy',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
@@ -196,6 +202,7 @@
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
+ PhabricatorPolicyCapability::CAN_INTERACT,
);
}
@@ -220,6 +227,8 @@
} else {
return PhabricatorPolicies::POLICY_NOONE;
}
+ case PhabricatorPolicyCapability::CAN_INTERACT:
+ return $this->getInteractPolicy();
}
}
@@ -230,6 +239,8 @@
case PhabricatorPolicyCapability::CAN_VIEW:
case PhabricatorPolicyCapability::CAN_EDIT:
return ($user->getPHID() == $this->getBloggerPHID());
+ case PhabricatorPolicyCapability::CAN_INTERACT:
+ return false;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 12:03 PM (19 h, 28 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6802227
Default Alt Text
D21754.id51861.diff (5 KB)
Attached To
Mode
D21754: Give Phame blog posts configurable interact policies, with a default policy of "Same as Blog"
Attached
Detach File
Event Timeline
Log In to Comment