|
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
|
|
View Code Duplication |
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
|
|
|
$base = Director::absoluteBaseURL(); |
|
72
|
|
|
return [ |
|
73
|
|
|
'basename' => Director::baseURL() . $this->getCurrentEnvironment()->Link('overview'), |
|
74
|
|
|
'dispatchers' => [ |
|
75
|
|
|
'git' => $base . $this->getCurrentProject()->Link('git'), |
|
76
|
|
|
'plan' => $base . $this->getCurrentEnvironment()->Link('plan'), |
|
77
|
|
|
'deploys' => $base . $this->getCurrentEnvironment()->Link('deploys'), |
|
78
|
|
|
'approvals' => $base . $this->getCurrentEnvironment()->Link('approvals') |
|
79
|
|
|
], |
|
80
|
|
|
'api_auth' => [ |
|
81
|
|
|
'name' => $this->getSecurityToken()->getName(), |
|
82
|
|
|
'value' => $this->getSecurityToken()->getValue() |
|
83
|
|
|
], |
|
84
|
|
|
'environment' => [ |
|
85
|
|
|
'id' => $this->environment->ID, |
|
|
|
|
|
|
86
|
|
|
'name' => $this->environment->Name, |
|
|
|
|
|
|
87
|
|
|
'usage' => $this->environment->Usage |
|
|
|
|
|
|
88
|
|
|
], |
|
89
|
|
|
'user' => [ |
|
90
|
|
|
'can_deploy_without_approval' => $this->getCurrentProject()->allowed( |
|
91
|
|
|
ApprovalsDispatcher::ALLOW_APPROVAL, |
|
92
|
|
|
Member::currentUser() |
|
|
|
|
|
|
93
|
|
|
) |
|
94
|
|
|
] |
|
95
|
|
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
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.