2013-11-07 02:00:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class NuanceSource
|
|
|
|
extends NuanceDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
|
|
|
|
protected $name;
|
|
|
|
protected $type;
|
|
|
|
protected $data;
|
|
|
|
protected $mailKey;
|
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'data' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
|
|
|
NuancePHIDTypeSource::TYPECONST);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save() {
|
|
|
|
if (!$this->getMailKey()) {
|
|
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
|
|
}
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
return '/nuance/source/view/'.$this->getID().'/';
|
|
|
|
}
|
|
|
|
|
2013-11-08 21:45:14 +01:00
|
|
|
public static function initializeNewSource(PhabricatorUser $actor) {
|
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($actor)
|
|
|
|
->withClasses(array('PhabricatorApplicationNuance'))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$view_policy = $app->getPolicy(
|
|
|
|
NuanceCapabilitySourceDefaultView::CAPABILITY);
|
|
|
|
$edit_policy = $app->getPolicy(
|
|
|
|
NuanceCapabilitySourceDefaultEdit::CAPABILITY);
|
|
|
|
|
2013-11-20 22:41:19 +01:00
|
|
|
$definitions = NuanceSourceDefinition::getAllDefinitions();
|
|
|
|
$lucky_definition = head($definitions);
|
|
|
|
|
2013-11-08 21:45:14 +01:00
|
|
|
return id(new NuanceSource())
|
|
|
|
->setViewPolicy($view_policy)
|
2013-11-20 22:41:19 +01:00
|
|
|
->setEditPolicy($edit_policy)
|
|
|
|
->setType($lucky_definition->getSourceTypeConstant());
|
|
|
|
|
2013-11-08 21:45:14 +01:00
|
|
|
}
|
|
|
|
|
2013-11-07 02:00:09 +01:00
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|