Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/storage/PhamePost.php
Show All 21 Lines | final class PhamePost extends PhameDAO | ||||
protected $phameTitle; | protected $phameTitle; | ||||
protected $body; | protected $body; | ||||
protected $visibility; | protected $visibility; | ||||
protected $configData; | protected $configData; | ||||
protected $datePublished; | protected $datePublished; | ||||
protected $blogPHID; | protected $blogPHID; | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $headerImagePHID; | protected $headerImagePHID; | ||||
protected $interactPolicy; | |||||
private $blog = self::ATTACHABLE; | private $blog = self::ATTACHABLE; | ||||
private $headerImageFile = self::ATTACHABLE; | private $headerImageFile = self::ATTACHABLE; | ||||
public static function initializePost( | public static function initializePost( | ||||
PhabricatorUser $blogger, | PhabricatorUser $blogger, | ||||
PhameBlog $blog) { | PhameBlog $blog) { | ||||
$post = id(new PhamePost()) | $post = id(new PhamePost()) | ||||
->setBloggerPHID($blogger->getPHID()) | ->setBloggerPHID($blogger->getPHID()) | ||||
->setBlogPHID($blog->getPHID()) | ->setBlogPHID($blog->getPHID()) | ||||
->attachBlog($blog) | ->attachBlog($blog) | ||||
->setDatePublished(PhabricatorTime::getNow()) | ->setDatePublished(PhabricatorTime::getNow()) | ||||
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED); | ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED) | ||||
->setInteractPolicy( | |||||
id(new PhameInheritBlogPolicyRule()) | |||||
->getObjectPolicyFullKey()); | |||||
return $post; | return $post; | ||||
} | } | ||||
public function attachBlog(PhameBlog $blog) { | public function attachBlog(PhameBlog $blog) { | ||||
$this->blog = $blog; | $this->blog = $blog; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | return array( | ||||
// These seem like they should always be non-null? | // These seem like they should always be non-null? | ||||
'blogPHID' => 'phid?', | 'blogPHID' => 'phid?', | ||||
'body' => 'text?', | 'body' => 'text?', | ||||
'configData' => 'text?', | 'configData' => 'text?', | ||||
// T6203/NULLABILITY | // T6203/NULLABILITY | ||||
// This one probably should be nullable? | // This one probably should be nullable? | ||||
'datePublished' => 'epoch', | 'datePublished' => 'epoch', | ||||
'interactPolicy' => 'policy', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_phid' => null, | 'key_phid' => null, | ||||
'phid' => array( | 'phid' => array( | ||||
'columns' => array('phid'), | 'columns' => array('phid'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'bloggerPosts' => array( | 'bloggerPosts' => array( | ||||
Show All 40 Lines | |||||
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ | /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
PhabricatorPolicyCapability::CAN_INTERACT, | |||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
// Draft and archived posts are visible only to the author and other | // Draft and archived posts are visible only to the author and other | ||||
// users who can edit the blog. Published posts are visible to whoever | // users who can edit the blog. Published posts are visible to whoever | ||||
// the blog is visible to. | // the blog is visible to. | ||||
switch ($capability) { | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
if (!$this->isDraft() && !$this->isArchived() && $this->getBlog()) { | if (!$this->isDraft() && !$this->isArchived() && $this->getBlog()) { | ||||
return $this->getBlog()->getViewPolicy(); | return $this->getBlog()->getViewPolicy(); | ||||
} else if ($this->getBlog()) { | } else if ($this->getBlog()) { | ||||
return $this->getBlog()->getEditPolicy(); | return $this->getBlog()->getEditPolicy(); | ||||
} else { | } else { | ||||
return PhabricatorPolicies::POLICY_NOONE; | return PhabricatorPolicies::POLICY_NOONE; | ||||
} | } | ||||
break; | break; | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
if ($this->getBlog()) { | if ($this->getBlog()) { | ||||
return $this->getBlog()->getEditPolicy(); | return $this->getBlog()->getEditPolicy(); | ||||
} else { | } else { | ||||
return PhabricatorPolicies::POLICY_NOONE; | return PhabricatorPolicies::POLICY_NOONE; | ||||
} | } | ||||
case PhabricatorPolicyCapability::CAN_INTERACT: | |||||
return $this->getInteractPolicy(); | |||||
} | } | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
// A blog post's author can always view it. | // A blog post's author can always view 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()); | ||||
case PhabricatorPolicyCapability::CAN_INTERACT: | |||||
return false; | |||||
} | } | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
return pht('The author of a blog post can always view and edit it.'); | return pht('The author of a blog post can always view and edit it.'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines |