Changeset View
Changeset View
Standalone View
Standalone View
src/applications/pholio/storage/PholioImage.php
<?php | <?php | ||||
final class PholioImage extends PholioDAO | final class PholioImage extends PholioDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface { | PhabricatorPolicyInterface, | ||||
PhabricatorExtendedPolicyInterface { | |||||
protected $authorPHID; | |||||
protected $mockID; | protected $mockID; | ||||
protected $filePHID; | protected $filePHID; | ||||
protected $name; | protected $name; | ||||
protected $description; | protected $description; | ||||
protected $sequence; | protected $sequence; | ||||
protected $isObsolete; | protected $isObsolete; | ||||
protected $replacesImagePHID = null; | protected $replacesImagePHID = null; | ||||
Show All 37 Lines | final class PholioImage extends PholioDAO | ||||
} | } | ||||
public function attachFile(PhabricatorFile $file) { | public function attachFile(PhabricatorFile $file) { | ||||
$this->file = $file; | $this->file = $file; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getFile() { | public function getFile() { | ||||
$this->assertAttached($this->file); | return $this->assertAttached($this->file); | ||||
return $this->file; | |||||
} | } | ||||
public function attachMock(PholioMock $mock) { | public function attachMock(PholioMock $mock) { | ||||
$this->mock = $mock; | $this->mock = $mock; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getMock() { | public function getMock() { | ||||
$this->assertAttached($this->mock); | return $this->assertAttached($this->mock); | ||||
return $this->mock; | |||||
} | } | ||||
public function attachInlineComments(array $inline_comments) { | public function attachInlineComments(array $inline_comments) { | ||||
assert_instances_of($inline_comments, 'PholioTransactionComment'); | assert_instances_of($inline_comments, 'PholioTransactionComment'); | ||||
$this->inlineComments = $inline_comments; | $this->inlineComments = $inline_comments; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInlineComments() { | public function getInlineComments() { | ||||
$this->assertAttached($this->inlineComments); | $this->assertAttached($this->inlineComments); | ||||
return $this->inlineComments; | return $this->inlineComments; | ||||
} | } | ||||
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return $this->getMock()->getCapabilities(); | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
); | |||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
return $this->getMock()->getPolicy($capability); | // If the image is attached to a mock, we use an extended policy to match | ||||
// the mock's permissions. | |||||
if ($this->getMockID()) { | |||||
return PhabricatorPolicies::getMostOpenPolicy(); | |||||
} | |||||
// If the image is not attached to a mock, only the author can see it. | |||||
return $this->getAuthorPHID(); | |||||
} | } | ||||
// really the *mock* controls who can see an image | |||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
return $this->getMock()->hasAutomaticCapability($capability, $viewer); | return false; | ||||
} | |||||
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | |||||
public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | |||||
if ($this->getMockID()) { | |||||
return array( | |||||
array( | |||||
$this->getMock(), | |||||
$capability, | |||||
), | |||||
); | |||||
} | |||||
return array(); | |||||
} | } | ||||
} | } |