Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/storage/PhrictionDocument.php
<?php | <?php | ||||
final class PhrictionDocument extends PhrictionDAO | final class PhrictionDocument extends PhrictionDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
PhabricatorTokenReceiverInterface, | PhabricatorTokenReceiverInterface, | ||||
PhabricatorDestructibleInterface { | PhabricatorDestructibleInterface { | ||||
protected $slug; | protected $slug; | ||||
protected $depth; | protected $depth; | ||||
protected $contentID; | protected $contentID; | ||||
protected $status; | protected $status; | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $viewPolicy; | |||||
protected $editPolicy; | |||||
private $contentObject = self::ATTACHABLE; | private $contentObject = self::ATTACHABLE; | ||||
private $ancestors = array(); | private $ancestors = array(); | ||||
// TODO: This should be `self::ATTACHABLE`, but there are still a lot of call | // TODO: This should be `self::ATTACHABLE`, but there are still a lot of call | ||||
// sites which load PhrictionDocuments directly. | // sites which load PhrictionDocuments directly. | ||||
private $project = null; | private $project = null; | ||||
Show All 36 Lines | public static function initializeNewDocument(PhabricatorUser $actor, $slug) { | ||||
$document->setSlug($slug); | $document->setSlug($slug); | ||||
$content = new PhrictionContent(); | $content = new PhrictionContent(); | ||||
$content->setSlug($slug); | $content->setSlug($slug); | ||||
$default_title = PhabricatorSlug::getDefaultTitle($slug); | $default_title = PhabricatorSlug::getDefaultTitle($slug); | ||||
$content->setTitle($default_title); | $content->setTitle($default_title); | ||||
$document->attachContent($content); | $document->attachContent($content); | ||||
$default_policy = PhabricatorPolicies::getMostOpenPolicy(); | |||||
$document->setViewPolicy($default_policy); | |||||
$document->setEditPolicy($default_policy); | |||||
epriestley: This one too. | |||||
Not Done Inline Actionsah, i need to default the policy to something in here... will update in a min or three. btrahan: ah, i need to default the policy to something in here... will update in a min or three. | |||||
return $document; | return $document; | ||||
} | } | ||||
public function save() { | public function save() { | ||||
if (!$this->getMailKey()) { | if (!$this->getMailKey()) { | ||||
$this->setMailKey(Filesystem::readRandomCharacters(20)); | $this->setMailKey(Filesystem::readRandomCharacters(20)); | ||||
} | } | ||||
return parent::save(); | return parent::save(); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
if ($this->hasProject()) { | switch ($capability) { | ||||
return $this->getProject()->getPolicy($capability); | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
return $this->getViewPolicy(); | |||||
case PhabricatorPolicyCapability::CAN_EDIT: | |||||
return $this->getEditPolicy(); | |||||
} | } | ||||
return PhabricatorPolicies::POLICY_USER; | |||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
if ($this->hasProject()) { | |||||
return $this->getProject()->hasAutomaticCapability($capability, $user); | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
if ($this->hasProject()) { | |||||
return pht( | |||||
"This is a project wiki page, and inherits the project's policies."); | |||||
} | |||||
switch ($capability) { | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
return pht( | return pht( | ||||
'To view a wiki document, you must also be able to view all '. | 'To view a wiki document, you must also be able to view all '. | ||||
'of its parents.'); | 'of its parents.'); | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | |||||
return pht( | |||||
'To edit a wiki document, you must also be able to edit all '. | |||||
'of its parents.'); | |||||
epriestleyUnsubmitted Not Done Inline ActionsI don't think this is currently true. You have to be able to view all of the parents, but do not need to be able to edit them, I think. I believe there are two messy cases here:
Moves add some more magic to this. epriestley: I don't think this is currently true. You have to be able to view all of the parents, but do… | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
/* -( PhabricatorSubscribableInterface )----------------------------------- */ | /* -( PhabricatorSubscribableInterface )----------------------------------- */ | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |
This one too.