public function getPostSnapshotForm(\SS_HTTPRequest $request)
{
// Performs canView permission check by limiting visible projects
$project = $this->getCurrentProject();
if (!$project) {
return $this->project404Response();
}
if (!$project->canUploadArchive()) {
return new SS_HTTPResponse("Not allowed to upload", 401);
}
// Framing an environment as a "group of people with download access"
// makes more sense to the user here, while still allowing us to enforce
// environment specific restrictions on downloading the file later on.
$envs = $project->DNEnvironmentList()->filterByCallback(function ($item) {
return $item->canUploadArchive();
});
$envsMap = [];
foreach ($envs as $env) {
$envsMap[$env->ID] = $env->Name;
}
$form = Form::create($this, 'PostSnapshotForm', FieldList::create(DropdownField::create('Mode', 'What does this file contain?', DNDataArchive::get_mode_map()), DropdownField::create('EnvironmentID', 'Initial ownership of the file', $envsMap)->setEmptyString('Select an environment')), FieldList::create(FormAction::create('doPostSnapshot', 'Submit request')->addExtraClass('btn')), RequiredFields::create('File'));
$form->disableSecurityToken();
$form->addExtraClass('fields-wide');
// Tweak the action so it plays well with our fake URL structure.
$form->setFormAction($project->Link() . '/PostSnapshotForm');
return $form;
}