public function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
$project = $this->Project();
if ($project && $project->exists()) {
$viewerGroups = $project->Viewers();
$groups = $viewerGroups->sort('Title')->map()->toArray();
$members = [];
foreach ($viewerGroups as $group) {
foreach ($group->Members()->map() as $k => $v) {
$members[$k] = $v;
}
}
asort($members);
} else {
$groups = [];
$members = [];
}
// Main tab
$fields->addFieldsToTab('Root.Main', [TextField::create('ProjectName', 'Project')->setValue(($project = $this->Project()) ? $project->Name : null)->performReadonlyTransformation(), TextField::create('Name', 'Environment name')->setDescription('A descriptive name for this environment, e.g. staging, uat, production'), $this->obj('Usage')->scaffoldFormField('Environment usage'), TextField::create('URL', 'Server URL')->setDescription('This url will be used to provide the front-end with a link to this environment'), TextField::create('Filename')->setDescription('The capistrano environment file name')->performReadonlyTransformation()]);
// Backend identifier - pick from a named list of configurations specified in YML config
$backends = $this->config()->get('allowed_backends', Config::FIRST_SET);
// If there's only 1 backend, then user selection isn't needed
if (sizeof($backends) > 1) {
$fields->addFieldToTab('Root.Main', DropdownField::create('BackendIdentifier', 'Deployment backend')->setSource($backends)->setDescription('What kind of deployment system should be used to deploy to this environment'));
}
$fields->addFieldsToTab('Root.UserPermissions', [$this->buildPermissionField('ViewerGroups', 'Viewers', $groups, $members)->setTitle('Who can view this environment?')->setDescription('Groups or Users who can view this environment'), $this->buildPermissionField('DeployerGroups', 'Deployers', $groups, $members)->setTitle('Who can deploy?')->setDescription('Groups or Users who can deploy to this environment'), $this->buildPermissionField('TickAllSnapshotGroups', 'TickAllSnapshot', $groups, $members)->setTitle("<em>All snapshot permissions</em>")->addExtraClass('tickall')->setDescription('UI shortcut to select all snapshot-related options - not written to the database.'), $this->buildPermissionField('CanRestoreGroups', 'CanRestoreMembers', $groups, $members)->setTitle('Who can restore?')->setDescription('Groups or Users who can restore archives from Deploynaut into this environment'), $this->buildPermissionField('CanBackupGroups', 'CanBackupMembers', $groups, $members)->setTitle('Who can backup?')->setDescription('Groups or Users who can backup archives from this environment into Deploynaut'), $this->buildPermissionField('ArchiveDeleterGroups', 'ArchiveDeleters', $groups, $members)->setTitle('Who can delete?')->setDescription("Groups or Users who can delete archives from this environment's staging area."), $this->buildPermissionField('ArchiveUploaderGroups', 'ArchiveUploaders', $groups, $members)->setTitle('Who can upload?')->setDescription('Users who can upload archives linked to this environment into Deploynaut.<br />' . 'Linking them to an environment allows limiting download permissions (see below).'), $this->buildPermissionField('ArchiveDownloaderGroups', 'ArchiveDownloaders', $groups, $members)->setTitle('Who can download?')->setDescription(<<<PHP
Users who can download archives from this environment to their computer.<br />
Since this implies access to the snapshot, it is also a prerequisite for restores
to other environments, alongside the "Who can restore" permission.<br>
Should include all users with upload permissions, otherwise they can't download
their own uploads.
PHP
)]);
// The Main.DeployConfig
if ($this->Project()->exists()) {
$this->setDeployConfigurationFields($fields);
}
// The DataArchives
$dataArchiveConfig = GridFieldConfig_RecordViewer::create();
$dataArchiveConfig->removeComponentsByType('GridFieldAddNewButton');
if (class_exists('GridFieldBulkManager')) {
$dataArchiveConfig->addComponent(new GridFieldBulkManager());
}
$dataArchive = GridField::create('DataArchives', 'Data Archives', $this->DataArchives(), $dataArchiveConfig);
$fields->addFieldToTab('Root.DataArchive', $dataArchive);
// Deployments
$deploymentsConfig = GridFieldConfig_RecordEditor::create();
$deploymentsConfig->removeComponentsByType('GridFieldAddNewButton');
if (class_exists('GridFieldBulkManager')) {
$deploymentsConfig->addComponent(new GridFieldBulkManager());
}
$deployments = GridField::create('Deployments', 'Deployments', $this->Deployments(), $deploymentsConfig);
$fields->addFieldToTab('Root.Deployments', $deployments);
Requirements::javascript('deploynaut/javascript/environment.js');
// Add actions
$action = new FormAction('check', 'Check Connection');
$action->setUseButtonTag(true);
$dataURL = Director::absoluteBaseURL() . 'naut/api/' . $this->Project()->Name . '/' . $this->Name . '/ping';
$action->setAttribute('data-url', $dataURL);
$fields->insertBefore($action, 'Name');
// Allow extensions
$this->extend('updateCMSFields', $fields);
return $fields;
}