@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 PhabricatorSpacesNamespace
4 extends PhabricatorSpacesDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorApplicationTransactionInterface,
8 PhabricatorDestructibleInterface {
9
10 protected $namespaceName;
11 protected $viewPolicy;
12 protected $editPolicy;
13 protected $isDefaultNamespace;
14 protected $description;
15 protected $isArchived;
16
17 public static function initializeNewNamespace(PhabricatorUser $actor) {
18 $app = id(new PhabricatorApplicationQuery())
19 ->setViewer($actor)
20 ->withClasses(array(PhabricatorSpacesApplication::class))
21 ->executeOne();
22
23 $view_policy = $app->getPolicy(
24 PhabricatorSpacesCapabilityDefaultView::CAPABILITY);
25 $edit_policy = $app->getPolicy(
26 PhabricatorSpacesCapabilityDefaultEdit::CAPABILITY);
27
28 return id(new PhabricatorSpacesNamespace())
29 ->setIsDefaultNamespace(null)
30 ->setViewPolicy($view_policy)
31 ->setEditPolicy($edit_policy)
32 ->setDescription('')
33 ->setIsArchived(0);
34 }
35
36 protected function getConfiguration() {
37 return array(
38 self::CONFIG_AUX_PHID => true,
39 self::CONFIG_COLUMN_SCHEMA => array(
40 'namespaceName' => 'text255',
41 'isDefaultNamespace' => 'bool?',
42 'description' => 'text',
43 'isArchived' => 'bool',
44 ),
45 self::CONFIG_KEY_SCHEMA => array(
46 'key_default' => array(
47 'columns' => array('isDefaultNamespace'),
48 'unique' => true,
49 ),
50 ),
51 ) + parent::getConfiguration();
52 }
53
54 public function generatePHID() {
55 return PhabricatorPHID::generateNewPHID(
56 PhabricatorSpacesNamespacePHIDType::TYPECONST);
57 }
58
59 public function getMonogram() {
60 return 'S'.$this->getID();
61 }
62
63
64/* -( PhabricatorPolicyInterface )----------------------------------------- */
65
66
67 public function getCapabilities() {
68 return array(
69 PhabricatorPolicyCapability::CAN_VIEW,
70 PhabricatorPolicyCapability::CAN_EDIT,
71 );
72 }
73
74 public function getPolicy($capability) {
75 switch ($capability) {
76 case PhabricatorPolicyCapability::CAN_VIEW:
77 return $this->getViewPolicy();
78 case PhabricatorPolicyCapability::CAN_EDIT:
79 return $this->getEditPolicy();
80 }
81 }
82
83 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
84 return false;
85 }
86
87/* -( PhabricatorApplicationTransactionInterface )------------------------- */
88
89
90 public function getApplicationTransactionEditor() {
91 return new PhabricatorSpacesNamespaceEditor();
92 }
93
94 public function getApplicationTransactionTemplate() {
95 return new PhabricatorSpacesNamespaceTransaction();
96 }
97
98
99/* -( PhabricatorDestructibleInterface )----------------------------------- */
100
101
102 public function destroyObjectPermanently(
103 PhabricatorDestructionEngine $engine) {
104 $this->delete();
105 }
106
107}