|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This aims to be a simple controller that only kicks off the rendering on the react |
|
5
|
|
|
* components. It passes a model to the frontend with URLS to dispatchers that takes |
|
6
|
|
|
* care of various actions, like git fetching, planning, approvals and so on. |
|
7
|
|
|
*/ |
|
8
|
|
|
class EnvironmentOverview extends Dispatcher { |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
const ACTION_OVERVIEW = 'overview'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var array |
|
14
|
|
|
*/ |
|
15
|
|
|
private static $action_types = [ |
|
|
|
|
|
|
16
|
|
|
self::ACTION_OVERVIEW |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The "deployment" action here should only go to index, it gets used by |
|
21
|
|
|
* the frontend routing. |
|
22
|
|
|
*/ |
|
23
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
24
|
|
|
'deployment' |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
public function init() { |
|
28
|
|
|
parent::init(); |
|
29
|
|
|
$this->project = $this->getCurrentProject(); |
|
|
|
|
|
|
30
|
|
|
if (!$this->project) { |
|
|
|
|
|
|
31
|
|
|
return $this->project404Response(); |
|
32
|
|
|
} |
|
33
|
|
|
// Performs canView permission check by limiting visible projects |
|
34
|
|
|
$this->environment = $this->getCurrentEnvironment($this->project); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* |
|
39
|
|
|
* @param \SS_HTTPRequest $request |
|
40
|
|
|
* |
|
41
|
|
|
* @return \HTMLText|\SS_HTTPResponse |
|
42
|
|
|
*/ |
|
43
|
|
|
public function index(\SS_HTTPRequest $request) { |
|
44
|
|
|
if (!$this->environment) { |
|
|
|
|
|
|
45
|
|
|
return $this->environment404Response(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->setCurrentActionType(self::ACTION_OVERVIEW); |
|
49
|
|
|
|
|
50
|
|
|
return $this->customise([ |
|
51
|
|
|
'Environment' => $this->environment |
|
|
|
|
|
|
52
|
|
|
])->renderWith(['EnvironmentOverview', 'DNRoot']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function Link() { |
|
59
|
|
|
return $this->environment->Link(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* The model includes the CSRF tokens and the various API |
|
64
|
|
|
* endpoints that the front end might be interested in. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $name |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getModel($name = '') { |
|
71
|
|
|
$approversList = []; |
|
72
|
|
|
|
|
73
|
|
|
// virtual stacks have a special case in that they need to look at the base project |
|
74
|
|
|
// due to the team setup being on the base. |
|
75
|
|
|
if ($this->getCurrentProject() instanceof VirtualProject) { |
|
|
|
|
|
|
76
|
|
|
$baseProject = $this->getCurrentProject()->BaseProject(); |
|
77
|
|
|
} else { |
|
78
|
|
|
$baseProject = $this->getCurrentProject(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
foreach ($baseProject->listMembers() as $data) { |
|
82
|
|
|
if ($baseProject->allowed(\ApprovalsDispatcher::ALLOW_APPROVAL, \Member::get()->byId($data['MemberID']))) { |
|
83
|
|
|
$approversList[$data['MemberID']] = [ |
|
84
|
|
|
'id' => $data['MemberID'], |
|
85
|
|
|
'email' => $data['Email'], |
|
86
|
|
|
'role' => $data['RoleTitle'], |
|
87
|
|
|
'name' => $data['FullName'] |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$base = Director::absoluteBaseURL(); |
|
93
|
|
|
return [ |
|
94
|
|
|
'basename' => Director::baseURL() . $this->getCurrentEnvironment()->Link(self::ACTION_OVERVIEW), |
|
95
|
|
|
'dispatchers' => [ |
|
96
|
|
|
'git' => $base . $this->getCurrentProject()->Link('git'), |
|
97
|
|
|
'deploys' => $base . $this->getCurrentEnvironment()->Link('deploys'), |
|
98
|
|
|
'approvals' => $base . $this->getCurrentEnvironment()->Link('approvals') |
|
99
|
|
|
], |
|
100
|
|
|
'api_auth' => [ |
|
101
|
|
|
'name' => $this->getSecurityToken()->getName(), |
|
102
|
|
|
'value' => $this->getSecurityToken()->getValue() |
|
103
|
|
|
], |
|
104
|
|
|
'environment' => [ |
|
105
|
|
|
'id' => $this->environment->ID, |
|
|
|
|
|
|
106
|
|
|
'name' => $this->environment->Name, |
|
|
|
|
|
|
107
|
|
|
'project_name' => $this->getCurrentProject()->Name, |
|
108
|
|
|
'usage' => $this->environment->Usage, |
|
|
|
|
|
|
109
|
|
|
'supported_options' => $this->environment->getSupportedOptions()->map('name', 'defaultValue'), |
|
|
|
|
|
|
110
|
|
|
'approvers' => $approversList |
|
111
|
|
|
], |
|
112
|
|
|
'user' => [ |
|
113
|
|
|
'can_approve' => \ApprovalsDispatcher::can_approve($this->getCurrentEnvironment()), |
|
|
|
|
|
|
114
|
|
|
'can_bypass_approval' => \ApprovalsDispatcher::can_bypass_approval($this->getCurrentEnvironment()), |
|
|
|
|
|
|
115
|
|
|
'can_abort_deployment' => \DeployDispatcher::can_abort_deployment($this->getCurrentEnvironment()) |
|
|
|
|
|
|
116
|
|
|
] |
|
117
|
|
|
]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.