Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/storage/PhameBlog.php
| Show All 14 Lines | final class PhameBlog extends PhameDAO | ||||
| protected $name; | protected $name; | ||||
| protected $description; | protected $description; | ||||
| protected $domain; | protected $domain; | ||||
| protected $configData; | protected $configData; | ||||
| protected $creatorPHID; | protected $creatorPHID; | ||||
| protected $viewPolicy; | protected $viewPolicy; | ||||
| protected $editPolicy; | protected $editPolicy; | ||||
| protected $joinPolicy; | |||||
| protected $mailKey; | protected $mailKey; | ||||
| private static $requestBlog; | private static $requestBlog; | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
| 'configData' => self::SERIALIZATION_JSON, | 'configData' => self::SERIALIZATION_JSON, | ||||
| ), | ), | ||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'name' => 'text64', | 'name' => 'text64', | ||||
| 'description' => 'text', | 'description' => 'text', | ||||
| 'domain' => 'text128?', | 'domain' => 'text128?', | ||||
| 'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
| // T6203/NULLABILITY | // T6203/NULLABILITY | ||||
| // These policies should always be non-null. | // These policies should always be non-null. | ||||
| 'joinPolicy' => 'policy?', | |||||
| 'editPolicy' => 'policy?', | 'editPolicy' => 'policy?', | ||||
| 'viewPolicy' => 'policy?', | 'viewPolicy' => '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, | ||||
| Show All 17 Lines | public function generatePHID() { | ||||
| return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
| PhabricatorPhameBlogPHIDType::TYPECONST); | PhabricatorPhameBlogPHIDType::TYPECONST); | ||||
| } | } | ||||
| public static function initializeNewBlog(PhabricatorUser $actor) { | public static function initializeNewBlog(PhabricatorUser $actor) { | ||||
| $blog = id(new PhameBlog()) | $blog = id(new PhameBlog()) | ||||
| ->setCreatorPHID($actor->getPHID()) | ->setCreatorPHID($actor->getPHID()) | ||||
| ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ||||
| ->setEditPolicy(PhabricatorPolicies::POLICY_USER) | ->setEditPolicy(PhabricatorPolicies::POLICY_USER); | ||||
| ->setJoinPolicy(PhabricatorPolicies::POLICY_USER); | |||||
| return $blog; | return $blog; | ||||
| } | } | ||||
| public function getSkinRenderer(AphrontRequest $request) { | public function getSkinRenderer(AphrontRequest $request) { | ||||
| $spec = PhameSkinSpecification::loadOneSkinSpecification( | $spec = PhameSkinSpecification::loadOneSkinSpecification( | ||||
| $this->getSkin()); | $this->getSkin()); | ||||
| if (!$spec) { | if (!$spec) { | ||||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 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_JOIN, | |||||
| ); | ); | ||||
| } | } | ||||
| public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
| switch ($capability) { | switch ($capability) { | ||||
| case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
| return $this->getViewPolicy(); | return $this->getViewPolicy(); | ||||
| case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
| return $this->getEditPolicy(); | return $this->getEditPolicy(); | ||||
| case PhabricatorPolicyCapability::CAN_JOIN: | |||||
| return $this->getJoinPolicy(); | |||||
| } | } | ||||
| } | } | ||||
| public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
| $can_edit = PhabricatorPolicyCapability::CAN_EDIT; | $can_edit = PhabricatorPolicyCapability::CAN_EDIT; | ||||
| $can_join = PhabricatorPolicyCapability::CAN_JOIN; | |||||
| switch ($capability) { | switch ($capability) { | ||||
| case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
| // Users who can edit or post to a blog can always view it. | // Users who can edit or post to a blog can always view it. | ||||
| if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_edit)) { | if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_edit)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_join)) { | |||||
| return true; | |||||
| } | |||||
| break; | |||||
| case PhabricatorPolicyCapability::CAN_JOIN: | |||||
| // Users who can edit a blog can always post to it. | |||||
| if (PhabricatorPolicyFilter::hasCapability($user, $this, $can_edit)) { | |||||
| return true; | |||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
| switch ($capability) { | switch ($capability) { | ||||
| case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
| return pht( | return pht( | ||||
| 'Users who can edit or post on a blog can always view it.'); | 'Users who can edit a blog can always view it.'); | ||||
| case PhabricatorPolicyCapability::CAN_JOIN: | |||||
| return pht( | |||||
| 'Users who can edit a blog can always post on it.'); | |||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ | /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines | |||||