Changeset View
Changeset View
Standalone View
Standalone View
src/applications/owners/storage/PhabricatorOwnersPackage.php
<?php | <?php | ||||
final class PhabricatorOwnersPackage | final class PhabricatorOwnersPackage | ||||
extends PhabricatorOwnersDAO | extends PhabricatorOwnersDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorCustomFieldInterface, | PhabricatorCustomFieldInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorConduitResultInterface, | PhabricatorConduitResultInterface, | ||||
PhabricatorFulltextInterface, | PhabricatorFulltextInterface, | ||||
PhabricatorFerretInterface, | PhabricatorFerretInterface, | ||||
PhabricatorNgramsInterface { | PhabricatorNgramsInterface { | ||||
protected $name; | protected $name; | ||||
protected $auditingEnabled; | |||||
protected $autoReview; | protected $autoReview; | ||||
protected $description; | protected $description; | ||||
protected $status; | protected $status; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $dominion; | protected $dominion; | ||||
protected $properties = array(); | protected $properties = array(); | ||||
protected $auditingState; | |||||
private $paths = self::ATTACHABLE; | private $paths = self::ATTACHABLE; | ||||
private $owners = self::ATTACHABLE; | private $owners = self::ATTACHABLE; | ||||
private $customFields = self::ATTACHABLE; | private $customFields = self::ATTACHABLE; | ||||
private $pathRepositoryMap = array(); | private $pathRepositoryMap = array(); | ||||
const STATUS_ACTIVE = 'active'; | const STATUS_ACTIVE = 'active'; | ||||
const STATUS_ARCHIVED = 'archived'; | const STATUS_ARCHIVED = 'archived'; | ||||
const AUTOREVIEW_NONE = 'none'; | const AUTOREVIEW_NONE = 'none'; | ||||
const AUTOREVIEW_SUBSCRIBE = 'subscribe'; | const AUTOREVIEW_SUBSCRIBE = 'subscribe'; | ||||
const AUTOREVIEW_SUBSCRIBE_ALWAYS = 'subscribe-always'; | const AUTOREVIEW_SUBSCRIBE_ALWAYS = 'subscribe-always'; | ||||
const AUTOREVIEW_REVIEW = 'review'; | const AUTOREVIEW_REVIEW = 'review'; | ||||
const AUTOREVIEW_REVIEW_ALWAYS = 'review-always'; | const AUTOREVIEW_REVIEW_ALWAYS = 'review-always'; | ||||
const AUTOREVIEW_BLOCK = 'block'; | const AUTOREVIEW_BLOCK = 'block'; | ||||
const AUTOREVIEW_BLOCK_ALWAYS = 'block-always'; | const AUTOREVIEW_BLOCK_ALWAYS = 'block-always'; | ||||
const AUDITING_NONE = 'none'; | |||||
const AUDITING_AUDIT = 'audit'; | |||||
const DOMINION_STRONG = 'strong'; | const DOMINION_STRONG = 'strong'; | ||||
const DOMINION_WEAK = 'weak'; | const DOMINION_WEAK = 'weak'; | ||||
const PROPERTY_IGNORED = 'ignored'; | const PROPERTY_IGNORED = 'ignored'; | ||||
public static function initializeNewPackage(PhabricatorUser $actor) { | public static function initializeNewPackage(PhabricatorUser $actor) { | ||||
$app = id(new PhabricatorApplicationQuery()) | $app = id(new PhabricatorApplicationQuery()) | ||||
->setViewer($actor) | ->setViewer($actor) | ||||
->withClasses(array('PhabricatorOwnersApplication')) | ->withClasses(array('PhabricatorOwnersApplication')) | ||||
->executeOne(); | ->executeOne(); | ||||
$view_policy = $app->getPolicy( | $view_policy = $app->getPolicy( | ||||
PhabricatorOwnersDefaultViewCapability::CAPABILITY); | PhabricatorOwnersDefaultViewCapability::CAPABILITY); | ||||
$edit_policy = $app->getPolicy( | $edit_policy = $app->getPolicy( | ||||
PhabricatorOwnersDefaultEditCapability::CAPABILITY); | PhabricatorOwnersDefaultEditCapability::CAPABILITY); | ||||
return id(new PhabricatorOwnersPackage()) | return id(new PhabricatorOwnersPackage()) | ||||
->setAuditingEnabled(0) | ->setAuditingState(PhabricatorOwnersAuditRule::AUDITING_NONE) | ||||
->setAutoReview(self::AUTOREVIEW_NONE) | ->setAutoReview(self::AUTOREVIEW_NONE) | ||||
->setDominion(self::DOMINION_STRONG) | ->setDominion(self::DOMINION_STRONG) | ||||
->setViewPolicy($view_policy) | ->setViewPolicy($view_policy) | ||||
->setEditPolicy($edit_policy) | ->setEditPolicy($edit_policy) | ||||
->attachPaths(array()) | ->attachPaths(array()) | ||||
->setStatus(self::STATUS_ACTIVE) | ->setStatus(self::STATUS_ACTIVE) | ||||
->attachOwners(array()) | ->attachOwners(array()) | ||||
->setDescription(''); | ->setDescription(''); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | return array( | ||||
self::CONFIG_TIMESTAMPS => false, | self::CONFIG_TIMESTAMPS => false, | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
'properties' => self::SERIALIZATION_JSON, | 'properties' => self::SERIALIZATION_JSON, | ||||
), | ), | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'sort', | 'name' => 'sort', | ||||
'description' => 'text', | 'description' => 'text', | ||||
'auditingEnabled' => 'bool', | 'auditingState' => 'text32', | ||||
'status' => 'text32', | 'status' => 'text32', | ||||
'autoReview' => 'text32', | 'autoReview' => 'text32', | ||||
'dominion' => 'text32', | 'dominion' => 'text32', | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function getPHIDType() { | public function getPHIDType() { | ||||
▲ Show 20 Lines • Show All 421 Lines • ▼ Show 20 Lines | public function getMonogram() { | ||||
return 'O'.$this->getID(); | return 'O'.$this->getID(); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
// TODO: Move these to "/O123" for consistency. | // TODO: Move these to "/O123" for consistency. | ||||
return '/owners/package/'.$this->getID().'/'; | return '/owners/package/'.$this->getID().'/'; | ||||
} | } | ||||
public function getAuditingState() { | public function newAuditingRule() { | ||||
if ($this->getAuditingEnabled()) { | return PhabricatorOwnersAuditRule::newFromState($this->getAuditingState()); | ||||
return self::AUDITING_AUDIT; | |||||
} else { | |||||
return self::AUDITING_NONE; | |||||
} | |||||
} | } | ||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (isset($review_map[$review_value])) { | ||||
$review_label = pht('Unknown ("%s")', $review_value); | $review_label = pht('Unknown ("%s")', $review_value); | ||||
} | } | ||||
$review = array( | $review = array( | ||||
'value' => $review_value, | 'value' => $review_value, | ||||
'label' => $review_label, | 'label' => $review_label, | ||||
); | ); | ||||
$audit_value = $this->getAuditingState(); | $audit_rule = $this->newAuditingRule(); | ||||
if ($this->getAuditingEnabled()) { | |||||
$audit_label = pht('Auditing Enabled'); | |||||
} else { | |||||
$audit_label = pht('No Auditing'); | |||||
} | |||||
$audit = array( | $audit = array( | ||||
'value' => $audit_value, | 'value' => $audit_rule->getKey(), | ||||
'label' => $audit_label, | 'label' => $audit_rule->getDisplayName(), | ||||
); | ); | ||||
$dominion_value = $this->getDominion(); | $dominion_value = $this->getDominion(); | ||||
$dominion_map = self::getDominionOptionsMap(); | $dominion_map = self::getDominionOptionsMap(); | ||||
if (isset($dominion_map[$dominion_value])) { | if (isset($dominion_map[$dominion_value])) { | ||||
$dominion_label = $dominion_map[$dominion_value]['name']; | $dominion_label = $dominion_map[$dominion_value]['name']; | ||||
$dominion_short = $dominion_map[$dominion_value]['short']; | $dominion_short = $dominion_map[$dominion_value]['short']; | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |