Skip to content
Snippets Groups Projects
Commit f3eff388 authored by Quentin Ribac's avatar Quentin Ribac
Browse files

FIX #20786 TIME 1:00 cannot delete or set visible signed_response; WIP signable_by_default

parent 31e01d0f
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,7 @@ class AttachmentTypeController
'visible' => $rawAttachmentsType['visible'],
'emailLink' => $rawAttachmentsType['email_link'],
'signable' => $rawAttachmentsType['signable'],
'signedByDefault' => $rawAttachmentsType['signed_by_default'],
'icon' => $rawAttachmentsType['icon'],
'chrono' => $rawAttachmentsType['chrono'],
'versionEnabled' => $rawAttachmentsType['version_enabled'],
......@@ -75,6 +76,7 @@ class AttachmentTypeController
'visible' => $attachmentType['visible'],
'emailLink' => $attachmentType['email_link'],
'signable' => $attachmentType['signable'],
'signedByDefault' => $attachmentType['signed_by_default'],
'icon' => $attachmentType['icon'],
'chrono' => $attachmentType['chrono'],
'versionEnabled' => $attachmentType['version_enabled'],
......@@ -111,6 +113,7 @@ class AttachmentTypeController
'visible' => empty($body['visible']) ? 'false' : 'true',
'email_link' => empty($body['emailLink']) ? 'false' : 'true',
'signable' => empty($body['signable']) ? 'false' : 'true',
'signed_by_default' => empty($body['signedByDefault']) ? 'false' : 'true',
'chrono' => empty($body['chrono']) ? 'false' : 'true',
'icon' => $body['icon'] ?? null,
'version_enabled' => empty($body['versionEnabled']) ? 'false' : 'true',
......@@ -134,9 +137,9 @@ class AttachmentTypeController
return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string']);
}
$attachmentType = AttachmentTypeModel::getById(['select' => [1], 'id' => $args['id']]);
if (empty($attachmentType)) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment type does not exist']);
$attachmentType = AttachmentTypeModel::getById(['select' => ['type_id'], 'id' => $args['id']]);
if (empty($attachmentType['type_id']) || $body['typeId'] != $attachmentType['type_id']) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment type not found or altered']);
}
$set = ['label' => $body['label']];
......@@ -149,6 +152,9 @@ class AttachmentTypeController
if (isset($body['signable'])) {
$set['signable'] = empty($body['signable']) ? 'false' : 'true';
}
if (isset($body['signedByDefault'])) {
$set['signed_by_default'] = empty($body['signedByDefault']) ? 'false' : 'true';
}
if (isset($body['chrono'])) {
$set['chrono'] = empty($body['chrono']) ? 'false' : 'true';
}
......@@ -162,6 +168,13 @@ class AttachmentTypeController
$set['icon'] = $body['icon'];
}
if ($set['visible'] == 'true' && in_array($body['typeId'], AttachmentTypeController::UNLISTED_ATTACHMENT_TYPES)) {
return $response->withStatus(400)->withJson(['errors' => 'This attachment type cannot be made visible']);
}
if ($set['signed_by_default'] == 'true' && $body['typeId'] == 'signed_response') {
return $response->withStatus(400)->withJson(['errors' => 'This option cannot be enabled on this type']);
}
AttachmentTypeModel::update([
'set' => $set,
'where' => ['id = ?'],
......@@ -182,6 +195,10 @@ class AttachmentTypeController
return $response->withStatus(400)->withJson(['errors' => 'Attachment type does not exist']);
}
if (in_array($attachmentType['type_id'], AttachmentTypeController::UNLISTED_ATTACHMENT_TYPES)) {
return $response->withStatus(400)->withJson(['errors' => 'This attachment type cannot be deleted']);
}
$attachments = AttachmentModel::get(['select' => [1], 'where' => ['attachment_type = ?', 'status != ?'], 'data' => [$attachmentType['type_id'], 'DEL']]);
if (!empty($attachments)) {
return $response->withStatus(400)->withJson(['errors' => 'Type is used in attachments', 'lang' => 'attachmentTypeUsed']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment