fix software inputfilter

parent d1152c52
This diff is collapsed.
......@@ -192,6 +192,12 @@ return function (Slim\App $app) {
);
};
$container[Middleware\InputFilterSoftware::class] = function ($c) {
return new Middleware\InputFilterSoftware(
$c->get(InputFilter\Software::class)
);
};
$container[Middleware\FetchSchoolFromIdentity::class] = function ($c) {
return new Middleware\FetchSchoolFromIdentity($c['authentication_service']);
};
......@@ -227,6 +233,10 @@ return function (Slim\App $app) {
);
};
$container[InputFilter\Software::class] = function ($c) {
return new InputFilter\Software();
};
});
$events('on', 'app.bootstrap', function ($app, $container) {
......@@ -255,7 +265,8 @@ return function (Slim\App $app) {
$this->delete('/assets', Action\Assets\DeleteAsset::class);
$this->get('/software', Action\Software\ListAll::class)->setName('school.software');
$this->post('/software', Action\Software\PersistSoftware::class);
$this->post('/software', Action\Software\PersistSoftware::class)
->add(Middleware\InputFilterSoftware::class);
$this->delete('/software', Action\Software\DeleteSoftware::class);
})->add(Middleware\FetchSchoolFromIdentity::class);
......
......@@ -141,7 +141,15 @@
that.model.add(response);
}
that.hide();
});
}).fail(function (xhr, err) {
var messages;
if (422 === xhr.status) {
messages = JSON.parse(xhr.responseText).messages || {};
utils.formMessages.render(that.form, messages);
} else {
alert('Προέκυψε κάποιο σφάλμα');
}
});;
},
removeSoftware: function () {
var that = this;
......
......@@ -38,11 +38,6 @@ class Software
->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 3]));
$school_id = new Input('school_id');
$school_id->setRequired(true)
->getValidatorChain()
->attach(new Validator\Digits());
$lab_id = new Input('lab_id');
$lab_id->setRequired(false)
->getValidatorChain()
......@@ -58,13 +53,15 @@ class Software
$url = new Input('url');
$url->setRequired(false)
->getValidatorChain()
->attach(new Validator\Hostname());
->attach(new Validator\Uri([
'allowRelative' => false,
'allowAbsolute' => true,
]));
$this->inputFilter = new InputFilter();
$this->inputFilter
->add($id)
->add($softwarecategory_id)
->add($school_id)
->add($lab_id)
->add($title)
->add($vendor)
......
......@@ -118,7 +118,7 @@ class LabService implements LabServiceInterface
$responsible = sprintf("%s %s", $responsible->name, $responsible->surname);
}
$lab = $bean->export();
$lab = $bean->export();
$lab['attachment_file'] = basename($lab['attachment']);
return array_merge($lab, [
......
......@@ -66,8 +66,8 @@ class SoftwareService implements SoftwareServiceInterface
private function persistSoftware($software, array $data)
{
if (!$data['lab_id']) {
$data['lab_id'] = NULL;
if (!isset($data['lab_id']) || empty($data['lab_id'])) {
$data['lab_id'] = null;
}
$software->softwarecategory_id = $data['softwarecategory_id'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment