From ec3b1ec32af302bd79e2ef7bae28503ea0fe24c5 Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Mon, 14 Oct 2019 10:02:01 -0300 Subject: [PATCH] Adds validation for colors when editing/creating tags, and creates the INVALID_COLOR error --- server/controllers/ticket/create-tag.php | 4 ++++ server/controllers/ticket/edit-tag.php | 4 ++++ server/data/ERRORS.php | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/server/controllers/ticket/create-tag.php b/server/controllers/ticket/create-tag.php index 8e91734b..63f6448f 100644 --- a/server/controllers/ticket/create-tag.php +++ b/server/controllers/ticket/create-tag.php @@ -36,6 +36,10 @@ class CreateTagController extends Controller { 'name' => [ 'validation' => DataValidator::length(2, 100), 'error' => ERRORS::INVALID_NAME + ], + 'color' => [ + 'validation' => DataValidator::hexRgbColor()->startsWith('#'), + 'error' => ERRORS::INVALID_COLOR ] ] ]; diff --git a/server/controllers/ticket/edit-tag.php b/server/controllers/ticket/edit-tag.php index 0ce66228..646ab9b1 100644 --- a/server/controllers/ticket/edit-tag.php +++ b/server/controllers/ticket/edit-tag.php @@ -37,6 +37,10 @@ class EditTagController extends Controller { 'tagId' => [ 'validation' => DataValidator::dataStoreId('tag'), 'error' => ERRORS::INVALID_TAG + ], + 'color' => [ + 'validation' => DataValidator::hexRgbColor()->startsWith('#'), + 'error' => ERRORS::INVALID_COLOR ] ] ]; diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 2a5ee462..831086a9 100755 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -247,6 +247,10 @@ * @apiDefine UNAVAILABLE_STATS * @apiError {String} UNAVAILABLE_STATS Stats are currently unavailable */ +/** + * @apiDefine INVALID_COLOR + * @apiError {String} INVALID_COLOR The color should be in hexadecimal, preceded by a '#' + */ class ERRORS { const INVALID_CREDENTIALS = 'INVALID_CREDENTIALS'; @@ -312,4 +316,5 @@ class ERRORS { const INVALID_CUSTOM_FIELD_OPTIONS = 'INVALID_CUSTOM_FIELD_OPTIONS'; const INVALID_CUSTOM_FIELD_OPTION = 'INVALID_CUSTOM_FIELD_OPTION'; const UNAVAILABLE_STATS = 'UNAVAILABLE_STATS'; + const INVALID_COLOR = 'INVALID_COLOR'; }