1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Give Phame blogs mutable interact policies

Summary:
Ref T13661.

I'm fairly sure these policies don't actually do anything (you can't "interact" with a blog) but the primarily support a Phame Post object policy of "Same as Parent Blog", which is the "natural" interact policy for a post.

Most of this is infrastructure support for mutable interact policies: today, only Maniphest has interact mutability and only via indirect effects (locking tasks), not through a directly mutable "Can Interact" policy.

Test Plan:
Ran storage upgrade, edited interact policy of a blog, saw appropriate persistence and transactions.

Created and edited a task to make sure there's no weird fallout from increasing what can be done with interact policies.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13661

Differential Revision: https://secure.phabricator.com/D21751
This commit is contained in:
epriestley 2022-04-01 12:01:48 -07:00
parent 5ce7f803f9
commit c25595417f
7 changed files with 65 additions and 1 deletions

View file

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

View file

@ -21,8 +21,10 @@ final class PhameBlogEditor
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
return $types;
}

View file

@ -24,6 +24,7 @@ final class PhameBlog extends PhameDAO
protected $creatorPHID;
protected $viewPolicy;
protected $editPolicy;
protected $interactPolicy;
protected $status;
protected $mailKey;
protected $profileImagePHID;
@ -56,6 +57,7 @@ final class PhameBlog extends PhameDAO
'editPolicy' => 'policy',
'viewPolicy' => 'policy',
'interactPolicy' => 'policy',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
@ -88,7 +90,9 @@ final class PhameBlog extends PhameDAO
->setCreatorPHID($actor->getPHID())
->setStatus(self::STATUS_ACTIVE)
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
->setEditPolicy(PhabricatorPolicies::POLICY_USER)
->setInteractPolicy(PhabricatorPolicies::POLICY_USER);
return $blog;
}
@ -229,6 +233,7 @@ final class PhameBlog extends PhameDAO
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_INTERACT,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
@ -238,6 +243,8 @@ final class PhameBlog extends PhameDAO
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_INTERACT:
return $this->getInteractPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}

View file

@ -66,6 +66,16 @@ final class PhabricatorPolicyEditEngineExtension
'description.conduit' => pht('Change the join policy of the object.'),
'edit' => 'join',
),
PhabricatorTransactions::TYPE_INTERACT_POLICY => array(
'key' => 'policy.interact',
'aliases' => array('interact'),
'capability' => PhabricatorPolicyCapability::CAN_INTERACT,
'label' => pht('Interact Policy'),
'description' => pht('Controls who can interact with the object.'),
'description.conduit'
=> pht('Change the interaction policy of the object.'),
'edit' => 'interact',
),
);
if ($object instanceof PhabricatorPolicyCodexInterface) {

View file

@ -7,6 +7,7 @@ final class PhabricatorTransactions extends Phobject {
const TYPE_VIEW_POLICY = 'core:view-policy';
const TYPE_EDIT_POLICY = 'core:edit-policy';
const TYPE_JOIN_POLICY = 'core:join-policy';
const TYPE_INTERACT_POLICY = 'core:interact-policy';
const TYPE_EDGE = 'core:edge';
const TYPE_CUSTOMFIELD = 'core:customfield';
const TYPE_TOKEN = 'token:give';

View file

@ -428,6 +428,11 @@ abstract class PhabricatorApplicationTransactionEditor
return null;
}
return $object->getJoinPolicy();
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
if ($this->getIsNewObject()) {
return null;
}
return $object->getInteractPolicy();
case PhabricatorTransactions::TYPE_SPACE:
if ($this->getIsNewObject()) {
return null;
@ -502,6 +507,7 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
case PhabricatorTransactions::TYPE_TOKEN:
case PhabricatorTransactions::TYPE_INLINESTATE:
case PhabricatorTransactions::TYPE_SUBTYPE:
@ -658,6 +664,7 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
case PhabricatorTransactions::TYPE_INLINESTATE:
case PhabricatorTransactions::TYPE_EDGE:
@ -722,6 +729,7 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
case PhabricatorTransactions::TYPE_INLINESTATE:
case PhabricatorTransactions::TYPE_SPACE:
case PhabricatorTransactions::TYPE_COMMENT:
@ -776,6 +784,9 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_JOIN_POLICY:
$object->setJoinPolicy($xaction->getNewValue());
break;
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
$object->setInteractPolicy($xaction->getNewValue());
break;
case PhabricatorTransactions::TYPE_SPACE:
$object->setSpacePHID($xaction->getNewValue());
break;

View file

@ -350,6 +350,7 @@ abstract class PhabricatorApplicationTransaction
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
if (!PhabricatorPolicyQuery::isSpecialPolicy($old)) {
$phids[] = array($old);
}
@ -479,6 +480,7 @@ abstract class PhabricatorApplicationTransaction
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
return 'fa-lock';
case PhabricatorTransactions::TYPE_EDGE:
switch ($this->getMetadataValue('edge:type')) {
@ -590,6 +592,7 @@ abstract class PhabricatorApplicationTransaction
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
case PhabricatorTransactions::TYPE_SPACE:
break;
case PhabricatorTransactions::TYPE_SUBTYPE:
@ -634,6 +637,7 @@ abstract class PhabricatorApplicationTransaction
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
case PhabricatorTransactions::TYPE_SPACE:
if ($this->getIsCreateTransaction()) {
break;
@ -887,6 +891,10 @@ abstract class PhabricatorApplicationTransaction
return pht(
'This %s already has that join policy.',
$this->getApplicationObjectTypeName());
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
return pht(
'This %s already has that interact policy.',
$this->getApplicationObjectTypeName());
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
return pht(
'All users are already subscribed to this %s.',
@ -964,6 +972,19 @@ abstract class PhabricatorApplicationTransaction
$this->renderPolicyName($old, 'old'),
$this->renderPolicyName($new, 'new'));
}
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
if ($this->getIsCreateTransaction()) {
return pht(
'%s created this object with interact policy "%s".',
$this->renderHandleLink($author_phid),
$this->renderPolicyName($new, 'new'));
} else {
return pht(
'%s changed the interact policy from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$this->renderPolicyName($old, 'old'),
$this->renderPolicyName($new, 'new'));
}
case PhabricatorTransactions::TYPE_SPACE:
if ($this->getIsCreateTransaction()) {
return pht(
@ -1204,6 +1225,11 @@ abstract class PhabricatorApplicationTransaction
'%s changed the join policy for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
return pht(
'%s changed the interact policy for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
return pht(
'%s updated subscribers of %s.',
@ -1426,6 +1452,7 @@ abstract class PhabricatorApplicationTransaction
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorTransactions::TYPE_INTERACT_POLICY:
return pht('Changed Policy');
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
return pht('Changed Subscribers');