public function createAction()
{
$this->checkPermissions(Acl::RESOURCE_SCRIPTS_ENVIRONMENT, Acl::PERM_SCRIPTS_ENVIRONMENT_MANAGE);
$object = $this->request->getJsonBody();
/* @var $scriptAdapter ScriptAdapter */
$scriptAdapter = $this->adapter('script');
//Pre validates the request object
$scriptAdapter->validateObject($object, Request::METHOD_POST);
//Read only property. It is needed before toEntity() call to set envId and accountId properties properly
$object->scope = $this->getScope();
$script = $scriptAdapter->toEntity($object);
$script->id = null;
$user = $this->getUser();
$script->createdByEmail = $user->getEmail();
$script->createdById = $user->getId();
$scriptAdapter->validateEntity($script);
//Saves entity
$script->save();
//Responds with 201 Created status
$this->response->setStatus(201);
return $this->result($scriptAdapter->toData($script));
}