Skip to content

Commit aa3b2ec

Browse files
author
epriestley
committedDec 19, 2018
Give Pholio Images an authorPHID and use ExtendedPolicies to implement policy behavior
Summary: Depends on D19912. Ref T11351. Images currently use `getMock()->getPolicy()` stuff to define policies. This causes bugs with object policies like "Subscribers", since the policy engine tries to evaluate the subscribers //for the image// when the intent is to evaluate the subscribers for the mock. Move this to ExtendedPolicies to fix the behavior, and give Images sensible policy behavior when they aren't attached to a mock (specifically: only the user who created the image can see it). Test Plan: Applied migrations, created and edited mocks and images without anything blowing up. Set mock visibility to "Subscribers", everything worked great. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T11351 Differential Revision: https://secure.phabricator.com/D19913
1 parent c4c5d8a commit aa3b2ec

7 files changed

+53
-19
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_pholio.pholio_image
2+
ADD authorPHID VARBINARY(64) NOT NULL;

‎src/__phutil_library_map__.php

+1
Original file line numberDiff line numberDiff line change
@@ -10947,6 +10947,7 @@
1094710947
'PholioImage' => array(
1094810948
'PholioDAO',
1094910949
'PhabricatorPolicyInterface',
10950+
'PhabricatorExtendedPolicyInterface',
1095010951
),
1095110952
'PholioImageDescriptionTransaction' => 'PholioImageTransactionType',
1095210953
'PholioImageFileTransaction' => 'PholioImageTransactionType',

‎src/applications/pholio/controller/PholioImageUploadController.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function handleRequest(AphrontRequest $request) {
2323
}
2424

2525
$image = PholioImage::initializeNewImage()
26+
->setAuthorPHID($viewer->getPHID())
2627
->attachFile($file)
2728
->setName($title)
2829
->setDescription($description)

‎src/applications/pholio/controller/PholioMockEditController.php

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function handleRequest(AphrontRequest $request) {
141141

142142
if ($replaces_image_phid) {
143143
$replace_image = PholioImage::initializeNewImage()
144+
->setAuthorPHID($viewer->getPHID())
144145
->setReplacesImagePHID($replaces_image_phid)
145146
->setFilePhid($file_phid)
146147
->attachFile($file)
@@ -154,6 +155,7 @@ public function handleRequest(AphrontRequest $request) {
154155
$posted_mock_images[] = $replace_image;
155156
} else if (!$existing_image) { // this is an add
156157
$add_image = PholioImage::initializeNewImage()
158+
->setAuthorPHID($viewer->getPHID())
157159
->setFilePhid($file_phid)
158160
->attachFile($file)
159161
->setName(strlen($title) ? $title : $file->getName())

‎src/applications/pholio/controller/PholioMockViewController.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function handleRequest(AphrontRequest $request) {
8282
$add_comment = $this->buildAddCommentView($mock, $comment_form_id);
8383

8484
$crumbs = $this->buildApplicationCrumbs();
85-
$crumbs->addTextCrumb('M'.$mock->getID(), '/M'.$mock->getID());
85+
$crumbs->addTextCrumb($mock->getMonogram(), $mock->getURI());
8686
$crumbs->setBorder(true);
8787

8888
$thumb_grid = id(new PholioMockThumbGridView())
@@ -92,16 +92,17 @@ public function handleRequest(AphrontRequest $request) {
9292
$view = id(new PHUITwoColumnView())
9393
->setHeader($header)
9494
->setCurtain($curtain)
95-
->setMainColumn(array(
96-
$output,
97-
$thumb_grid,
98-
$details,
99-
$timeline,
100-
$add_comment,
101-
));
95+
->setMainColumn(
96+
array(
97+
$output,
98+
$thumb_grid,
99+
$details,
100+
$timeline,
101+
$add_comment,
102+
));
102103

103104
return $this->newPage()
104-
->setTitle('M'.$mock->getID().' '.$title)
105+
->setTitle(pht('%s %s', $mock->getMonogram(), $title))
105106
->setCrumbs($crumbs)
106107
->setPageObjectPHIDs(array($mock->getPHID()))
107108
->addQuicksandConfig(

‎src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function generateObject() {
4242
$images = array();
4343
foreach ($files as $file) {
4444
$image = PholioImage::initializeNewImage()
45+
->setAuthorPHID($author_phid)
4546
->setFilePHID($file->getPHID())
4647
->setSequence($sequence++)
4748
->attachMock($mock);

‎src/applications/pholio/storage/PholioImage.php

+36-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
final class PholioImage extends PholioDAO
44
implements
5-
PhabricatorPolicyInterface {
5+
PhabricatorPolicyInterface,
6+
PhabricatorExtendedPolicyInterface {
67

8+
protected $authorPHID;
79
protected $mockID;
810
protected $filePHID;
911
protected $name;
@@ -57,8 +59,7 @@ public function attachFile(PhabricatorFile $file) {
5759
}
5860

5961
public function getFile() {
60-
$this->assertAttached($this->file);
61-
return $this->file;
62+
return $this->assertAttached($this->file);
6263
}
6364

6465
public function attachMock(PholioMock $mock) {
@@ -67,8 +68,7 @@ public function attachMock(PholioMock $mock) {
6768
}
6869

6970
public function getMock() {
70-
$this->assertAttached($this->mock);
71-
return $this->mock;
71+
return $this->assertAttached($this->mock);
7272
}
7373

7474
public function attachInlineComments(array $inline_comments) {
@@ -83,20 +83,46 @@ public function getInlineComments() {
8383
}
8484

8585

86-
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */
86+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
8787

8888

8989
public function getCapabilities() {
90-
return $this->getMock()->getCapabilities();
90+
return array(
91+
PhabricatorPolicyCapability::CAN_VIEW,
92+
PhabricatorPolicyCapability::CAN_EDIT,
93+
);
9194
}
9295

9396
public function getPolicy($capability) {
94-
return $this->getMock()->getPolicy($capability);
97+
// If the image is attached to a mock, we use an extended policy to match
98+
// the mock's permissions.
99+
if ($this->getMockID()) {
100+
return PhabricatorPolicies::getMostOpenPolicy();
101+
}
102+
103+
// If the image is not attached to a mock, only the author can see it.
104+
return $this->getAuthorPHID();
95105
}
96106

97-
// really the *mock* controls who can see an image
98107
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
99-
return $this->getMock()->hasAutomaticCapability($capability, $viewer);
108+
return false;
109+
}
110+
111+
112+
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
113+
114+
115+
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
116+
if ($this->getMockID()) {
117+
return array(
118+
array(
119+
$this->getMock(),
120+
$capability,
121+
),
122+
);
123+
}
124+
125+
return array();
100126
}
101127

102128
}

0 commit comments

Comments
 (0)
Failed to load comments.