From 2c000dd2f03b47700f6f8763ff99d7e51a8c30c9 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Mon, 7 Oct 2019 13:19:44 +0100 Subject: [PATCH] FEAT #11277 TIME 0:10 set max tags length to 128 --- migration/19.12/1912.sql | 1 + sql/structure.sql | 2 +- src/app/tag/controllers/TagController.php | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql index b52123fbfe9..a2e3adb2188 100644 --- a/migration/19.12/1912.sql +++ b/migration/19.12/1912.sql @@ -301,6 +301,7 @@ UPDATE usergroups_services SET service_id = 'manage_tags_application' WHERE serv /* REFACTORING MODIFICATION */ ALTER TABLE notif_email_stack ALTER COLUMN attachments TYPE text; +ALTER TABLE tags ALTER COLUMN label TYPE character varying(128); /* REFACTORING SUPPRESSION */ diff --git a/sql/structure.sql b/sql/structure.sql index a514746b4a8..811f453fd8c 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -1059,7 +1059,7 @@ WITH (OIDS=FALSE); CREATE TABLE tags ( id serial NOT NULL, - label character varying(50) NOT NULL, + label character varying(128) NOT NULL, entity_id_owner character varying(32), CONSTRAINT tags_id_pkey PRIMARY KEY (id) ) diff --git a/src/app/tag/controllers/TagController.php b/src/app/tag/controllers/TagController.php index ccf72474aea..f39220960ca 100644 --- a/src/app/tag/controllers/TagController.php +++ b/src/app/tag/controllers/TagController.php @@ -63,6 +63,10 @@ class TagController return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string']); } + if (!Validator::length(1, 128)->validate($body['label'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body label has more than 128 characters']); + } + $id = TagModel::create([ 'label' => $body['label'] ]); @@ -88,13 +92,16 @@ class TagController return $response->withStatus(400)->withJson(['errors' => 'Route id must be an integer val']); } - $body = $request->getParsedBody(); if (!Validator::stringType()->notEmpty()->validate($body['label'])) { return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string']); } + if (!Validator::length(1, 128)->validate($body['label'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body label has more than 128 characters']); + } + TagModel::update([ 'set' => [ 'label' => $body['label'] -- GitLab