Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/storage/PhortuneCharge.php
<?php | <?php | ||||
/** | /** | ||||
* A charge is a charge (or credit) against an account and represents an actual | * A charge is a charge (or credit) against an account and represents an actual | ||||
* transfer of funds. Each charge is normally associated with a cart, but a | * transfer of funds. Each charge is normally associated with a cart, but a | ||||
* cart may have multiple charges. For example, a product may have a failed | * cart may have multiple charges. For example, a product may have a failed | ||||
* charge followed by a successful charge. | * charge followed by a successful charge. | ||||
*/ | */ | ||||
final class PhortuneCharge extends PhortuneDAO | final class PhortuneCharge extends PhortuneDAO | ||||
implements PhabricatorPolicyInterface { | implements | ||||
PhabricatorPolicyInterface, | |||||
PhabricatorExtendedPolicyInterface { | |||||
const STATUS_CHARGING = 'charge:charging'; | const STATUS_CHARGING = 'charge:charging'; | ||||
const STATUS_CHARGED = 'charge:charged'; | const STATUS_CHARGED = 'charge:charged'; | ||||
const STATUS_HOLD = 'charge:hold'; | const STATUS_HOLD = 'charge:hold'; | ||||
const STATUS_FAILED = 'charge:failed'; | const STATUS_FAILED = 'charge:failed'; | ||||
protected $accountPHID; | protected $accountPHID; | ||||
protected $authorPHID; | protected $authorPHID; | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
return $this->getAccount()->getPolicy($capability); | return PhabricatorPolicies::getMostOpenPolicy(); | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
return $this->getAccount()->hasAutomaticCapability($capability, $viewer); | if ($capability === PhabricatorPolicyCapability::CAN_VIEW) { | ||||
$any_edit = PhortuneMerchantQuery::canViewersEditMerchants( | |||||
array($viewer->getPHID()), | |||||
array($this->getMerchantPHID())); | |||||
if ($any_edit) { | |||||
return true; | |||||
} | } | ||||
} | |||||
return false; | |||||
} | |||||
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | |||||
public function describeAutomaticCapability($capability) { | public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | ||||
return pht('Charges inherit the policies of the associated account.'); | if ($this->hasAutomaticCapability($capability, $viewer)) { | ||||
return array(); | |||||
} | |||||
return array( | |||||
array( | |||||
$this->getAccount(), | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
), | |||||
); | |||||
} | } | ||||
} | } |