diff --git a/migration/20.10/2010.sql b/migration/20.10/2010.sql index 43cb51711ced69629dc7cac53a55ba76db164494..13d542339cfacb144ed0892b29ef083983986158 100755 --- a/migration/20.10/2010.sql +++ b/migration/20.10/2010.sql @@ -294,6 +294,12 @@ UPDATE actions SET component = 'checkReplyRecordManagementAction' where action_p UPDATE res_attachments SET attachment_type = 'acknowledgement_record_management' WHERE attachment_type = 'simple_attachment' AND format = 'xml' AND title = 'Accusé de réception' AND relation = 1 AND status = 'TRA'; UPDATE res_attachments SET attachment_type = 'reply_record_management' WHERE attachment_type = 'simple_attachment' AND format = 'xml' AND title = 'Réponse au transfert' AND relation = 1 AND status = 'TRA'; +/* CUSTOM FIELDS */ +ALTER TABLE custom_fields DROP COLUMN IF EXISTS mode; +DROP TYPE IF EXISTS custom_fields_modes; +CREATE TYPE custom_fields_modes AS ENUM ('form', 'technical'); +ALTER TABLE custom_fields ADD COLUMN mode custom_fields_modes DEFAULT 'form'; + /* RE CREATE VIEWS */ CREATE OR REPLACE VIEW res_view_letterbox AS SELECT r.res_id, diff --git a/src/app/customField/controllers/CustomFieldController.php b/src/app/customField/controllers/CustomFieldController.php index 30b81f199d0a6d57ea41c7aca16d52ddad0131f7..527738ff634cfe0d8a51d345eda411fde100a7db 100644 --- a/src/app/customField/controllers/CustomFieldController.php +++ b/src/app/customField/controllers/CustomFieldController.php @@ -80,6 +80,8 @@ class CustomFieldController return $response->withStatus(400)->withJson(['errors' => 'Body type is empty, not a string or value is incorrect']); } elseif (!empty($body['values']) && !Validator::arrayType()->notEmpty()->validate($body['values'])) { return $response->withStatus(400)->withJson(['errors' => 'Body values is not an array']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['mode']) || !in_array($body['mode'], ['form', 'technical'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body mode is empty, not a string or value is incorrect']); } $fields = CustomFieldModel::get(['select' => [1], 'where' => ['label = ?'], 'data' => [$body['label']]]); @@ -99,6 +101,7 @@ class CustomFieldController $id = CustomFieldModel::create([ 'label' => $body['label'], 'type' => $body['type'], + 'mode' => $body['mode'], 'values' => empty($body['values']) ? '[]' : json_encode($body['values']) ]); @@ -130,6 +133,8 @@ class CustomFieldController return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string']); } elseif (!empty($body['values']) && !Validator::arrayType()->notEmpty()->validate($body['values'])) { return $response->withStatus(400)->withJson(['errors' => 'Body values is not an array']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['mode']) || !in_array($body['mode'], ['form', 'technical'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body mode is empty, not a string or value is incorrect']); } $field = CustomFieldModel::getById(['select' => ['type', 'values'], 'id' => $args['id']]); @@ -195,6 +200,7 @@ class CustomFieldController CustomFieldModel::update([ 'set' => [ 'label' => $body['label'], + 'mode' => $body['mode'], 'values' => empty($body['values']) ? '[]' : json_encode($body['values']) ], 'where' => ['id = ?'],