Page MenuHomePhabricator

D21754.diff
No OneTemporary

D21754.diff

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

Mime Type
text/plain
Expires
Thu, May 9, 8:18 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6276603
Default Alt Text
D21754.diff (5 KB)

Event Timeline