@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+53 -19
+2
resources/sql/autopatches/20181218.pholio.01.imageauthor.sql
··· 1 + ALTER TABLE {$NAMESPACE}_pholio.pholio_image 2 + ADD authorPHID VARBINARY(64) NOT NULL;
+1
src/__phutil_library_map__.php
··· 10947 10947 'PholioImage' => array( 10948 10948 'PholioDAO', 10949 10949 'PhabricatorPolicyInterface', 10950 + 'PhabricatorExtendedPolicyInterface', 10950 10951 ), 10951 10952 'PholioImageDescriptionTransaction' => 'PholioImageTransactionType', 10952 10953 'PholioImageFileTransaction' => 'PholioImageTransactionType',
+1
src/applications/pholio/controller/PholioImageUploadController.php
··· 23 23 } 24 24 25 25 $image = PholioImage::initializeNewImage() 26 + ->setAuthorPHID($viewer->getPHID()) 26 27 ->attachFile($file) 27 28 ->setName($title) 28 29 ->setDescription($description)
+2
src/applications/pholio/controller/PholioMockEditController.php
··· 141 141 142 142 if ($replaces_image_phid) { 143 143 $replace_image = PholioImage::initializeNewImage() 144 + ->setAuthorPHID($viewer->getPHID()) 144 145 ->setReplacesImagePHID($replaces_image_phid) 145 146 ->setFilePhid($file_phid) 146 147 ->attachFile($file) ··· 154 155 $posted_mock_images[] = $replace_image; 155 156 } else if (!$existing_image) { // this is an add 156 157 $add_image = PholioImage::initializeNewImage() 158 + ->setAuthorPHID($viewer->getPHID()) 157 159 ->setFilePhid($file_phid) 158 160 ->attachFile($file) 159 161 ->setName(strlen($title) ? $title : $file->getName())
+10 -9
src/applications/pholio/controller/PholioMockViewController.php
··· 82 82 $add_comment = $this->buildAddCommentView($mock, $comment_form_id); 83 83 84 84 $crumbs = $this->buildApplicationCrumbs(); 85 - $crumbs->addTextCrumb('M'.$mock->getID(), '/M'.$mock->getID()); 85 + $crumbs->addTextCrumb($mock->getMonogram(), $mock->getURI()); 86 86 $crumbs->setBorder(true); 87 87 88 88 $thumb_grid = id(new PholioMockThumbGridView()) ··· 92 92 $view = id(new PHUITwoColumnView()) 93 93 ->setHeader($header) 94 94 ->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 + )); 102 103 103 104 return $this->newPage() 104 - ->setTitle('M'.$mock->getID().' '.$title) 105 + ->setTitle(pht('%s %s', $mock->getMonogram(), $title)) 105 106 ->setCrumbs($crumbs) 106 107 ->setPageObjectPHIDs(array($mock->getPHID())) 107 108 ->addQuicksandConfig(
+1
src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
··· 42 42 $images = array(); 43 43 foreach ($files as $file) { 44 44 $image = PholioImage::initializeNewImage() 45 + ->setAuthorPHID($author_phid) 45 46 ->setFilePHID($file->getPHID()) 46 47 ->setSequence($sequence++) 47 48 ->attachMock($mock);
+36 -10
src/applications/pholio/storage/PholioImage.php
··· 2 2 3 3 final class PholioImage extends PholioDAO 4 4 implements 5 - PhabricatorPolicyInterface { 5 + PhabricatorPolicyInterface, 6 + PhabricatorExtendedPolicyInterface { 6 7 8 + protected $authorPHID; 7 9 protected $mockID; 8 10 protected $filePHID; 9 11 protected $name; ··· 57 59 } 58 60 59 61 public function getFile() { 60 - $this->assertAttached($this->file); 61 - return $this->file; 62 + return $this->assertAttached($this->file); 62 63 } 63 64 64 65 public function attachMock(PholioMock $mock) { ··· 67 68 } 68 69 69 70 public function getMock() { 70 - $this->assertAttached($this->mock); 71 - return $this->mock; 71 + return $this->assertAttached($this->mock); 72 72 } 73 73 74 74 public function attachInlineComments(array $inline_comments) { ··· 83 83 } 84 84 85 85 86 - /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 86 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 87 87 88 88 89 89 public function getCapabilities() { 90 - return $this->getMock()->getCapabilities(); 90 + return array( 91 + PhabricatorPolicyCapability::CAN_VIEW, 92 + PhabricatorPolicyCapability::CAN_EDIT, 93 + ); 91 94 } 92 95 93 96 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(); 95 105 } 96 106 97 - // really the *mock* controls who can see an image 98 107 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(); 100 126 } 101 127 102 128 }