2014-10-03 14:52:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacDevice
|
|
|
|
extends AlmanacDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
|
|
|
|
protected $name;
|
2014-10-17 14:02:14 +02:00
|
|
|
protected $nameIndex;
|
|
|
|
protected $mailKey;
|
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
|
|
|
|
|
|
|
public static function initializeNewDevice() {
|
|
|
|
return id(new AlmanacDevice())
|
|
|
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
|
|
|
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
|
|
|
|
}
|
2014-10-03 14:52:41 +02:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
2014-10-17 14:02:14 +02:00
|
|
|
'name' => 'text128',
|
|
|
|
'nameIndex' => 'bytes12',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_name' => array(
|
|
|
|
'columns' => array('nameIndex'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'key_nametext' => array(
|
|
|
|
'columns' => array('name'),
|
|
|
|
),
|
2014-10-03 14:52:41 +02:00
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(AlmanacDevicePHIDType::TYPECONST);
|
|
|
|
}
|
|
|
|
|
2014-10-17 14:02:14 +02:00
|
|
|
public function save() {
|
|
|
|
AlmanacNames::validateServiceOrDeviceName($this->getName());
|
|
|
|
|
|
|
|
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
|
|
|
|
|
|
|
|
if (!$this->mailKey) {
|
|
|
|
$this->mailKey = Filesystem::readRandomCharacters(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
return '/almanac/device/view/'.$this->getName().'/';
|
|
|
|
}
|
|
|
|
|
2014-10-03 14:52:41 +02:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
2014-10-17 14:02:14 +02:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
2014-10-03 14:52:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
2014-10-17 14:02:14 +02:00
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
2014-10-03 14:52:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|