@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
1<?php
2
3final class PholioImage extends PholioDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorExtendedPolicyInterface {
7
8 protected $authorPHID;
9 protected $mockPHID;
10 protected $filePHID;
11 protected $name;
12 protected $description;
13 protected $sequence;
14 protected $isObsolete;
15 protected $replacesImagePHID = null;
16
17 private $inlineComments = self::ATTACHABLE;
18 private $file = self::ATTACHABLE;
19 private $mock = self::ATTACHABLE;
20
21 public static function initializeNewImage() {
22 return id(new self())
23 ->setName('')
24 ->setDescription('')
25 ->setIsObsolete(0);
26 }
27
28 protected function getConfiguration() {
29 return array(
30 self::CONFIG_AUX_PHID => true,
31 self::CONFIG_COLUMN_SCHEMA => array(
32 'mockPHID' => 'phid?',
33 'name' => 'text128',
34 'description' => 'text',
35 'sequence' => 'uint32',
36 'isObsolete' => 'bool',
37 'replacesImagePHID' => 'phid?',
38 ),
39 self::CONFIG_KEY_SCHEMA => array(
40 'key_mock' => array(
41 'columns' => array('mockPHID'),
42 ),
43 ),
44 ) + parent::getConfiguration();
45 }
46
47 public function getPHIDType() {
48 return PholioImagePHIDType::TYPECONST;
49 }
50
51 public function attachFile(PhabricatorFile $file) {
52 $this->file = $file;
53 return $this;
54 }
55
56 public function getFile() {
57 return $this->assertAttached($this->file);
58 }
59
60 public function attachMock(PholioMock $mock) {
61 $this->mock = $mock;
62 return $this;
63 }
64
65 public function getMock() {
66 return $this->assertAttached($this->mock);
67 }
68
69 public function hasMock() {
70 return (bool)$this->getMockPHID();
71 }
72
73 /**
74 * @param array<PholioTransactionComment> $inline_comments
75 */
76 public function attachInlineComments(array $inline_comments) {
77 assert_instances_of($inline_comments, PholioTransactionComment::class);
78 $this->inlineComments = $inline_comments;
79 return $this;
80 }
81
82 public function getInlineComments() {
83 $this->assertAttached($this->inlineComments);
84 return $this->inlineComments;
85 }
86
87 public function getURI() {
88 if ($this->hasMock()) {
89 $mock = $this->getMock();
90
91 $mock_uri = $mock->getURI();
92 $image_id = $this->getID();
93
94 return "{$mock_uri}/{$image_id}/";
95 }
96
97 // For now, standalone images have no URI. We could provide one at some
98 // point, although it's not clear that there's any motivation to do so.
99
100 return null;
101 }
102
103
104/* -( PhabricatorPolicyInterface )----------------------------------------- */
105
106
107 public function getCapabilities() {
108 return array(
109 PhabricatorPolicyCapability::CAN_VIEW,
110 PhabricatorPolicyCapability::CAN_EDIT,
111 );
112 }
113
114 public function getPolicy($capability) {
115 // If the image is attached to a mock, we use an extended policy to match
116 // the mock's permissions.
117 if ($this->hasMock()) {
118 return PhabricatorPolicies::getMostOpenPolicy();
119 }
120
121 // If the image is not attached to a mock, only the author can see it.
122 return $this->getAuthorPHID();
123 }
124
125 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
126 return false;
127 }
128
129
130/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
131
132
133 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
134 if ($this->hasMock()) {
135 return array(
136 array(
137 $this->getMock(),
138 $capability,
139 ),
140 );
141 }
142
143 return array();
144 }
145
146}