Skip to content

Commit 24c5b93

Browse files
committedApr 22, 2022
Merge branch 'update-2022-15'
* update-2022-15: Improve some PHP 8.1 behavior in "bin/auth recover" In Git, always "sudo" to the daemon user if a daemon user is configured Improve some UI/language for Phame posts when viewer doesn't have CAN_INTERACT Give Phame blog posts configurable interact policies, with a default policy of "Same as Blog" Remove unused "MARKUP_FIELD_SUMMARY" for Phame posts Fix a PHP 8.1 unit test failure in Projects Give Phame blogs mutable interact policies Fix double-bordered breadcrumbs in Phame blogs Remove ancient Remarkup constants from Phame and Maniphest Make Phame blog policies non-nullable
2 parents 694a1b2 + fa256cd commit 24c5b93

26 files changed

+228
-29
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPDATE {$NAMESPACE}_phame.phame_blog
2+
SET editPolicy = 'admin' WHERE editPolicy IS NULL;
3+
4+
ALTER TABLE {$NAMESPACE}_phame.phame_blog
5+
CHANGE editPolicy editPolicy VARBINARY(64) NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPDATE {$NAMESPACE}_phame.phame_blog
2+
SET viewPolicy = 'admin' WHERE viewPolicy IS NULL;
3+
4+
ALTER TABLE {$NAMESPACE}_phame.phame_blog
5+
CHANGE viewPolicy viewPolicy VARBINARY(64) NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALTER TABLE {$NAMESPACE}_phame.phame_blog
2+
ADD interactPolicy VARBINARY(64) NOT NULL;
3+
4+
UPDATE {$NAMESPACE}_phame.phame_blog
5+
SET interactPolicy = 'users'
6+
WHERE interactPolicy = '';
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

+5
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',
@@ -5287,6 +5288,7 @@
52875288
'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php',
52885289
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
52895290
'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
5291+
'PhamePostEditEngineLock' => 'applications/phame/editor/PhamePostEditEngineLock.php',
52905292
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
52915293
'PhamePostFerretEngine' => 'applications/phame/search/PhamePostFerretEngine.php',
52925294
'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php',
@@ -12167,6 +12169,7 @@
1216712169
'PhameDescriptionView' => 'AphrontTagView',
1216812170
'PhameDraftListView' => 'AphrontTagView',
1216912171
'PhameHomeController' => 'PhamePostController',
12172+
'PhameInheritBlogPolicyRule' => 'PhabricatorPolicyRule',
1217012173
'PhameLiveController' => 'PhameController',
1217112174
'PhameNextPostView' => 'AphrontTagView',
1217212175
'PhamePost' => array(
@@ -12180,6 +12183,7 @@
1218012183
'PhabricatorDestructibleInterface',
1218112184
'PhabricatorTokenReceiverInterface',
1218212185
'PhabricatorConduitResultInterface',
12186+
'PhabricatorEditEngineLockableInterface',
1218312187
'PhabricatorFulltextInterface',
1218412188
'PhabricatorFerretInterface',
1218512189
),
@@ -12190,6 +12194,7 @@
1219012194
'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
1219112195
'PhamePostEditController' => 'PhamePostController',
1219212196
'PhamePostEditEngine' => 'PhabricatorEditEngine',
12197+
'PhamePostEditEngineLock' => 'PhabricatorEditEngineLock',
1219312198
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
1219412199
'PhamePostFerretEngine' => 'PhabricatorFerretEngine',
1219512200
'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine',

‎src/applications/auth/management/PhabricatorAuthManagementRevokeWorkflow.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function execute(PhutilArgumentParser $args) {
6060

6161
$type = $args->getArg('type');
6262
$is_everything = $args->getArg('everything');
63-
if (!strlen($type) && !$is_everything) {
63+
if ($type === null && !$is_everything) {
6464
if ($is_list) {
6565
// By default, "bin/revoke --list" implies "--everything".
6666
$types = $all_types;
@@ -94,7 +94,7 @@ public function execute(PhutilArgumentParser $args) {
9494
$from = $args->getArg('from');
9595

9696
if ($is_list) {
97-
if (strlen($from) || $is_everywhere) {
97+
if ($from !== null || $is_everywhere) {
9898
throw new PhutilArgumentUsageException(
9999
pht(
100100
'You can not "--list" and revoke credentials (with "--from" or '.

‎src/applications/diffusion/protocol/DiffusionCommandEngine.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ public function getSudoAsDaemon() {
117117
return $this->sudoAsDaemon;
118118
}
119119

120+
protected function shouldAlwaysSudo() {
121+
return false;
122+
}
123+
120124
public function newFuture() {
121125
$argv = $this->newCommandArgv();
122126
$env = $this->newCommandEnvironment();
123127
$is_passthru = $this->getPassthru();
124128

125-
if ($this->getSudoAsDaemon()) {
129+
if ($this->getSudoAsDaemon() || $this->shouldAlwaysSudo()) {
126130
$command = call_user_func_array('csprintf', $argv);
127131
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
128132
$argv = array('%C', $command);

‎src/applications/diffusion/protocol/DiffusionGitCommandEngine.php

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ protected function newFormattedCommand($pattern, array $argv) {
1313
return array($pattern, $argv);
1414
}
1515

16+
protected function shouldAlwaysSudo() {
17+
18+
// See T13673. In Git, always try to use "sudo" to execute commands as the
19+
// daemon user (if such a user is configured), because Git 2.35.2 and newer
20+
// (and some older versions of Git with backported security patches) refuse
21+
// to execute if the top level repository directory is not owned by the
22+
// current user.
23+
24+
// Previously, we used "sudo" only when performing writes to the
25+
// repository directory.
26+
27+
return true;
28+
}
29+
1630
protected function newCustomEnvironment() {
1731
$env = array();
1832

‎src/applications/herald/storage/transcript/HeraldTranscript.php

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public static function saveXHeraldRulesHeader($phid, $header) {
6666
}
6767

6868
private static function combineXHeraldRulesHeaders($u, $v) {
69+
if ($u === null) {
70+
return $v;
71+
}
72+
6973
$u = preg_split('/[, ]+/', $u);
7074
$v = preg_split('/[, ]+/', $v);
7175

‎src/applications/maniphest/storage/ManiphestTask.php

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ final class ManiphestTask extends ManiphestDAO
2424
PhabricatorPolicyCodexInterface,
2525
PhabricatorUnlockableInterface {
2626

27-
const MARKUP_FIELD_DESCRIPTION = 'markup:desc';
28-
2927
protected $authorPHID;
3028
protected $ownerPHID;
3129

‎src/applications/phame/controller/blog/PhameBlogManageController.php

-5
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ private function buildPropertyView(PhameBlog $blog) {
143143
),
144144
$feed_uri));
145145

146-
$engine = id(new PhabricatorMarkupEngine())
147-
->setViewer($viewer)
148-
->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)
149-
->process();
150-
151146
$description = $blog->getDescription();
152147
if (strlen($description)) {
153148
$description = new PHUIRemarkupView($viewer, $description);

‎src/applications/phame/controller/blog/PhameBlogViewController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public function handleRequest(AphrontRequest $request) {
103103
->setDescription($description)
104104
->setImage($blog->getProfileImageURI());
105105

106-
$crumbs = $this->buildApplicationCrumbs();
106+
$crumbs = $this->buildApplicationCrumbs()
107+
->setBorder(false);
107108

108109
$page = $this->newPage()
109110
->setTitle($blog->getName())

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

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

2222
public function getTransactionTypes() {
2323
$types = parent::getTransactionTypes();
24+
2425
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
2526
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
27+
$types[] = PhabricatorTransactions::TYPE_INTERACT_POLICY;
2628

2729
return $types;
2830
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
final class PhamePostEditEngineLock
4+
extends PhabricatorEditEngineLock {
5+
6+
public function willPromptUserForLockOverrideWithDialog(
7+
AphrontDialogView $dialog) {
8+
9+
return $dialog
10+
->setTitle(pht('Edit Locked Post'))
11+
->appendParagraph(
12+
pht('Comments are disabled for this post. Edit it anyway?'))
13+
->addSubmitButton(pht('Edit Post'));
14+
}
15+
16+
public function willBlockUserInteractionWithDialog(
17+
AphrontDialogView $dialog) {
18+
19+
return $dialog
20+
->setTitle(pht('Post Locked'))
21+
->appendParagraph(
22+
pht('You can not interact with this post because it is locked.'));
23+
}
24+
25+
public function getLockedObjectDisplayText() {
26+
return pht('Comments have been disabled for this post.');
27+
}
28+
29+
}

‎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/PhameBlog.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ final class PhameBlog extends PhameDAO
1313
PhabricatorFulltextInterface,
1414
PhabricatorFerretInterface {
1515

16-
const MARKUP_FIELD_DESCRIPTION = 'markup:description';
17-
1816
protected $name;
1917
protected $subtitle;
2018
protected $description;
@@ -26,6 +24,7 @@ final class PhameBlog extends PhameDAO
2624
protected $creatorPHID;
2725
protected $viewPolicy;
2826
protected $editPolicy;
27+
protected $interactPolicy;
2928
protected $status;
3029
protected $mailKey;
3130
protected $profileImagePHID;
@@ -56,10 +55,9 @@ protected function getConfiguration() {
5655
'profileImagePHID' => 'phid?',
5756
'headerImagePHID' => 'phid?',
5857

59-
// T6203/NULLABILITY
60-
// These policies should always be non-null.
61-
'editPolicy' => 'policy?',
62-
'viewPolicy' => 'policy?',
58+
'editPolicy' => 'policy',
59+
'viewPolicy' => 'policy',
60+
'interactPolicy' => 'policy',
6361
),
6462
self::CONFIG_KEY_SCHEMA => array(
6563
'key_phid' => null,
@@ -92,7 +90,9 @@ public static function initializeNewBlog(PhabricatorUser $actor) {
9290
->setCreatorPHID($actor->getPHID())
9391
->setStatus(self::STATUS_ACTIVE)
9492
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
95-
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
93+
->setEditPolicy(PhabricatorPolicies::POLICY_USER)
94+
->setInteractPolicy(PhabricatorPolicies::POLICY_USER);
95+
9696
return $blog;
9797
}
9898

@@ -233,6 +233,7 @@ public function getHeaderImageFile() {
233233
public function getCapabilities() {
234234
return array(
235235
PhabricatorPolicyCapability::CAN_VIEW,
236+
PhabricatorPolicyCapability::CAN_INTERACT,
236237
PhabricatorPolicyCapability::CAN_EDIT,
237238
);
238239
}
@@ -242,6 +243,8 @@ public function getPolicy($capability) {
242243
switch ($capability) {
243244
case PhabricatorPolicyCapability::CAN_VIEW:
244245
return $this->getViewPolicy();
246+
case PhabricatorPolicyCapability::CAN_INTERACT:
247+
return $this->getInteractPolicy();
245248
case PhabricatorPolicyCapability::CAN_EDIT:
246249
return $this->getEditPolicy();
247250
}

0 commit comments

Comments
 (0)
Failed to load comments.