@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 123 lines 2.7 kB view raw
1<?php 2 3final class PhabricatorFileAttachment 4 extends PhabricatorFileDAO 5 implements 6 PhabricatorPolicyInterface, 7 PhabricatorExtendedPolicyInterface { 8 9 protected $objectPHID; 10 protected $filePHID; 11 protected $attacherPHID; 12 protected $attachmentMode; 13 14 private $object = self::ATTACHABLE; 15 private $file = self::ATTACHABLE; 16 17 const MODE_ATTACH = 'attach'; 18 const MODE_REFERENCE = 'reference'; 19 const MODE_DETACH = 'detach'; 20 21 protected function getConfiguration() { 22 return array( 23 self::CONFIG_COLUMN_SCHEMA => array( 24 'objectPHID' => 'phid', 25 'filePHID' => 'phid', 26 'attacherPHID' => 'phid?', 27 'attachmentMode' => 'text32', 28 ), 29 self::CONFIG_KEY_SCHEMA => array( 30 'key_object' => array( 31 'columns' => array('objectPHID', 'filePHID'), 32 'unique' => true, 33 ), 34 'key_file' => array( 35 'columns' => array('filePHID'), 36 ), 37 ), 38 ) + parent::getConfiguration(); 39 } 40 41 public static function getModeList() { 42 return array( 43 self::MODE_ATTACH, 44 self::MODE_REFERENCE, 45 self::MODE_DETACH, 46 ); 47 } 48 49 public static function getModeNameMap() { 50 return array( 51 self::MODE_ATTACH => pht('Attached'), 52 self::MODE_REFERENCE => pht('Referenced'), 53 ); 54 } 55 56 public function isPolicyAttachment() { 57 switch ($this->getAttachmentMode()) { 58 case self::MODE_ATTACH: 59 return true; 60 default: 61 return false; 62 } 63 } 64 65 public function attachObject($object) { 66 $this->object = $object; 67 return $this; 68 } 69 70 public function getObject() { 71 return $this->assertAttached($this->object); 72 } 73 74 public function attachFile(?PhabricatorFile $file = null) { 75 $this->file = $file; 76 return $this; 77 } 78 79 public function getFile() { 80 return $this->assertAttached($this->file); 81 } 82 83 public function canDetach() { 84 switch ($this->getAttachmentMode()) { 85 case self::MODE_ATTACH: 86 return true; 87 } 88 89 return false; 90 } 91 92 93/* -( PhabricatorPolicyInterface )----------------------------------------- */ 94 95 96 public function getCapabilities() { 97 return array( 98 PhabricatorPolicyCapability::CAN_VIEW, 99 ); 100 } 101 102 public function getPolicy($capability) { 103 switch ($capability) { 104 case PhabricatorPolicyCapability::CAN_VIEW: 105 return PhabricatorPolicies::getMostOpenPolicy(); 106 } 107 } 108 109 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 110 return false; 111 } 112 113 114/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ 115 116 117 public function getExtendedPolicy($capability, PhabricatorUser $viewer) { 118 return array( 119 array($this->getObject(), $capability), 120 ); 121 } 122 123}