| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | use FluentBoards\App\Models\Board; |
| 6 | 6 | use FluentBoards\App\Models\Stage; |
| 7 | 7 | use FluentBoards\App\Modules\MCP\Helpers\MCPHelper; |
| 8 | 8 | use FluentBoards\App\Services\BoardService; |
| 9 | +use FluentBoards\App\Services\Constant; | |
| 9 | 10 | use FluentBoards\App\Services\FolderService; |
| 10 | 11 | use FluentBoards\App\Services\Helper; |
| 11 | 12 | use FluentBoards\App\Services\LabelService; |
| 12 | 13 | use FluentBoards\App\Services\PermissionManager; |
| @@ -118,8 +119,13 @@ | ||
| 118 | 119 | if (is_wp_error($memberIds)) { |
| 119 | 120 | return $memberIds; |
| 120 | 121 | } |
| 121 | 122 | |
| 123 | + $labelPresetValidation = self::validateLabelPresets($params['labels'] ?? null); | |
| 124 | + if (is_wp_error($labelPresetValidation)) { | |
| 125 | + return $labelPresetValidation; | |
| 126 | + } | |
| 127 | + | |
| 122 | 128 | $description = isset($params['description']) ? MCPHelper::sanitizeMarkdown($params['description']) : ''; |
| 123 | 129 | |
| 124 | 130 | $boardData = Helper::sanitizeBoard([ |
| 125 | 131 | 'title' => $title, |
| @@ -342,8 +348,9 @@ | ||
| 342 | 348 | $labelData = Helper::sanitizeLabel([ |
| 343 | 349 | 'label' => $label['title'] ?? ($label['label'] ?? ''), |
| 344 | 350 | 'bg_color' => $label['bg_color'] ?? '', |
| 345 | 351 | 'color' => $label['color'] ?? '', |
| 352 | + 'color_preset' => $label['color_preset'] ?? '', | |
| 346 | 353 | ]); |
| 347 | 354 | |
| 348 | 355 | if (empty($labelData['label']) && empty($labelData['bg_color'])) { |
| 349 | 356 | continue; |
| @@ -352,10 +359,45 @@ | ||
| 352 | 359 | $labelService->createLabel([ |
| 353 | 360 | 'label' => $labelData['label'] ?? '', |
| 354 | 361 | 'bg_color' => !empty($labelData['bg_color']) ? $labelData['bg_color'] : '#f3f4f6', |
| 355 | 362 | 'color' => !empty($labelData['color']) ? $labelData['color'] : '#1B2533', |
| 363 | + 'color_preset' => $labelData['color_preset'] ?? '', | |
| 356 | 364 | ], $boardId); |
| 357 | 365 | } |
| 366 | + } | |
| 367 | + | |
| 368 | + /** | |
| 369 | + * Validate label preset ids before the board is persisted. | |
| 370 | + * | |
| 371 | + * @param mixed $labels | |
| 372 | + * @return true|\WP_Error | |
| 373 | + */ | |
| 374 | + private static function validateLabelPresets($labels) | |
| 375 | + { | |
| 376 | + if (!is_array($labels)) { | |
| 377 | + return true; | |
| 378 | + } | |
| 379 | + | |
| 380 | + foreach ($labels as $label) { | |
| 381 | + if (!is_array($label)) { | |
| 382 | + continue; | |
| 383 | + } | |
| 384 | + | |
| 385 | + $labelData = Helper::sanitizeLabel([ | |
| 386 | + Constant::LABEL_COLOR_PRESET_SETTING => $label[Constant::LABEL_COLOR_PRESET_SETTING] ?? null, | |
| 387 | + ]); | |
| 388 | + $presetId = $labelData[Constant::LABEL_COLOR_PRESET_SETTING] ?? null; | |
| 389 | + | |
| 390 | + if ($presetId === null || $presetId === '') { | |
| 391 | + continue; | |
| 392 | + } | |
| 393 | + | |
| 394 | + if (!is_string($presetId) || !Constant::getLabelColorPreset($presetId)) { | |
| 395 | + return MCPHelper::error('invalid_param', __('Invalid label color preset', 'fluent-boards')); | |
| 396 | + } | |
| 397 | + } | |
| 398 | + | |
| 399 | + return true; | |
| 358 | 400 | } |
| 359 | 401 | |
| 360 | 402 | private static function addBoardMembers($boardService, $boardId, $memberIds) |
| 361 | 403 | { |