Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/storage/PhamePost.php
| Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | return array( | ||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| ); | ); | ||||
| } | } | ||||
| public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
| // Draft posts are visible only to the author. Published posts are visible | // Draft posts are visible only to the author. Published posts are visible | ||||
| // to whoever the blog is visible to. | // to whoever the blog is visible to. | ||||
| switch ($capability) { | switch ($capability) { | ||||
| case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
| if (!$this->isDraft() && $this->getBlog()) { | if (!$this->isDraft() && $this->getBlog()) { | ||||
| return $this->getBlog()->getViewPolicy(); | return $this->getBlog()->getViewPolicy(); | ||||
| } else { | } else if ($this->getBlog()) { | ||||
| return PhabricatorPolicies::POLICY_NOONE; | return $this->getBlog()->getEditPolicy(); | ||||
| } | } | ||||
| break; | break; | ||||
| case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
| if ($this->getBlog()) { | |||||
| return $this->getBlog()->getEditPolicy(); | |||||
| } else { | |||||
| return PhabricatorPolicies::POLICY_NOONE; | return PhabricatorPolicies::POLICY_NOONE; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
epriestley: At some point in the future we should make sure `getBlog()` always exists (I think this is an… | |||||
| public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
| // A blog post's author can always view it, and is the only user allowed | // A blog post's author can always view it. | ||||
| // to edit it. | |||||
| switch ($capability) { | switch ($capability) { | ||||
| case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
| case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
| return ($user->getPHID() == $this->getBloggerPHID()); | return ($user->getPHID() == $this->getBloggerPHID()); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines | |||||
At some point in the future we should make sure getBlog() always exists (I think this is an artifact of an earlier time when a post could belong to multiple blogs) and clean this up, but it's fine for now.