Skip to content

Commit 3797727

Browse files
xIrusuxclaude
andauthored
Workflow listing API: names, places Endpoints (#1910)
* feat: add workflow names and places listing API Adds GET /workflows/names and GET /workflows/places?workflowName=, used by the Workflow Pending Items dashboard widget's configuration dropdowns. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Add workflow transitions collection endpoint GET /workflows/transitions returns the transitions available from a given workflow place (name + label), used by the Workflow Pending Items widget to offer bulk transition actions. * removed transition endpoints and kept required name and details EP also refactored based on AI guidelines * updates based on BE features * fix tests * re add missing workflow get element translations --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e6b798e commit 3797727

10 files changed

Lines changed: 413 additions & 0 deletions

File tree

config/element_workflow.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ services:
2626
Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowElementsServiceInterface:
2727
class: Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowElementsService
2828

29+
Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowMetaServiceInterface:
30+
class: Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowMetaService
31+
2932
# Repositories
3033
Pimcore\Bundle\StudioBackendBundle\Workflow\Repository\WorkflowElementsRepositoryInterface:
3134
class: Pimcore\Bundle\StudioBackendBundle\Workflow\Repository\WorkflowElementsRepository
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Attribute\Response\Content;
15+
16+
use OpenApi\Attributes\JsonContent;
17+
use Pimcore\Bundle\StudioBackendBundle\Workflow\Attribute\Response\Property\WorkflowStringCollection;
18+
19+
/**
20+
* @internal
21+
*/
22+
final class WorkflowStringListContent extends JsonContent
23+
{
24+
public function __construct()
25+
{
26+
parent::__construct(
27+
required: ['items'],
28+
properties: [
29+
new WorkflowStringCollection(),
30+
],
31+
type: 'object',
32+
);
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Attribute\Response\Property;
15+
16+
use OpenApi\Attributes\Items;
17+
use OpenApi\Attributes\Property;
18+
19+
/**
20+
* @internal
21+
*/
22+
final class WorkflowStringCollection extends Property
23+
{
24+
public function __construct()
25+
{
26+
parent::__construct(
27+
'items',
28+
title: 'items',
29+
type: 'array',
30+
items: new Items(type: 'string'),
31+
);
32+
}
33+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Controller;
15+
16+
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
18+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
19+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
21+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
22+
use Pimcore\Bundle\StudioBackendBundle\Workflow\Attribute\Response\Content\WorkflowStringListContent;
23+
use Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowMetaServiceInterface;
24+
use Symfony\Component\HttpFoundation\JsonResponse;
25+
use Symfony\Component\Routing\Attribute\Route;
26+
use Symfony\Component\Serializer\SerializerInterface;
27+
28+
/**
29+
* @internal
30+
*/
31+
final class NamesCollectionController extends AbstractApiController
32+
{
33+
private const string ROUTE = '/workflows/names';
34+
35+
public function __construct(
36+
SerializerInterface $serializer,
37+
private readonly WorkflowMetaServiceInterface $workflowMetaService,
38+
) {
39+
parent::__construct($serializer);
40+
}
41+
42+
#[Route(path: self::ROUTE, name: 'pimcore_studio_api_workflows_names', methods: ['GET'])]
43+
//#[IsGranted('STUDIO_API')]
44+
#[Get(
45+
path: self::PREFIX . self::ROUTE,
46+
operationId: 'workflow_get_names',
47+
description: 'workflow_get_names_description',
48+
summary: 'workflow_get_names_summary',
49+
tags: [Tags::Workflows->name]
50+
)]
51+
#[SuccessResponse(
52+
description: 'workflow_get_names_success_response',
53+
content: new WorkflowStringListContent()
54+
)]
55+
#[DefaultResponses([
56+
HttpResponseCodes::UNAUTHORIZED,
57+
])]
58+
public function getNames(): JsonResponse
59+
{
60+
return $this->jsonResponse([
61+
'items' => $this->workflowMetaService->getWorkflowNames(),
62+
]);
63+
}
64+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Controller;
15+
16+
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
18+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\StringParameter;
19+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
22+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
23+
use Pimcore\Bundle\StudioBackendBundle\Workflow\Attribute\Response\Content\WorkflowStringListContent;
24+
use Pimcore\Bundle\StudioBackendBundle\Workflow\MappedParameter\WorkflowPlacesParameters;
25+
use Pimcore\Bundle\StudioBackendBundle\Workflow\Service\WorkflowMetaServiceInterface;
26+
use Symfony\Component\HttpFoundation\JsonResponse;
27+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
28+
use Symfony\Component\Routing\Attribute\Route;
29+
use Symfony\Component\Serializer\SerializerInterface;
30+
31+
/**
32+
* @internal
33+
*/
34+
final class PlacesCollectionController extends AbstractApiController
35+
{
36+
private const string ROUTE = '/workflows/places';
37+
38+
public function __construct(
39+
SerializerInterface $serializer,
40+
private readonly WorkflowMetaServiceInterface $workflowMetaService,
41+
) {
42+
parent::__construct($serializer);
43+
}
44+
45+
#[Route(path: self::ROUTE, name: 'pimcore_studio_api_workflows_places', methods: ['GET'])]
46+
//#[IsGranted('STUDIO_API')]
47+
#[Get(
48+
path: self::PREFIX . self::ROUTE,
49+
operationId: 'workflow_get_places',
50+
description: 'workflow_get_places_description',
51+
summary: 'workflow_get_places_summary',
52+
tags: [Tags::Workflows->name]
53+
)]
54+
#[StringParameter('workflowName', 'product_workflow', 'workflow_get_places_workflow_name')]
55+
#[SuccessResponse(
56+
description: 'workflow_get_places_success_response',
57+
content: new WorkflowStringListContent()
58+
)]
59+
#[DefaultResponses([
60+
HttpResponseCodes::UNAUTHORIZED,
61+
])]
62+
public function getPlaces(
63+
#[MapQueryString] WorkflowPlacesParameters $parameters = new WorkflowPlacesParameters()
64+
): JsonResponse {
65+
return $this->jsonResponse([
66+
'items' => $this->workflowMetaService->getPlaces($parameters->getWorkflowName()),
67+
]);
68+
}
69+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\MappedParameter;
15+
16+
/**
17+
* @internal
18+
*/
19+
final readonly class WorkflowPlacesParameters
20+
{
21+
public function __construct(
22+
private string $workflowName = '',
23+
) {
24+
}
25+
26+
public function getWorkflowName(): string
27+
{
28+
return $this->workflowName;
29+
}
30+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Service;
15+
16+
use Pimcore\Workflow\Manager;
17+
use function array_keys;
18+
use function in_array;
19+
20+
/**
21+
* @internal
22+
*/
23+
final readonly class WorkflowMetaService implements WorkflowMetaServiceInterface
24+
{
25+
public function __construct(
26+
private Manager $workflowManager,
27+
) {
28+
}
29+
30+
/**
31+
* @return string[]
32+
*/
33+
public function getWorkflowNames(): array
34+
{
35+
return $this->workflowManager->getAllWorkflows();
36+
}
37+
38+
/**
39+
* @return string[]
40+
*/
41+
public function getPlaces(string $workflowName): array
42+
{
43+
if ($workflowName === '' || !in_array($workflowName, $this->workflowManager->getAllWorkflows(), true)) {
44+
return [];
45+
}
46+
47+
$workflow = $this->workflowManager->getWorkflowByName($workflowName);
48+
if ($workflow === null) {
49+
return [];
50+
}
51+
52+
return array_keys($workflow->getDefinition()->getPlaces());
53+
}
54+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Workflow\Service;
15+
16+
/**
17+
* @internal
18+
*/
19+
interface WorkflowMetaServiceInterface
20+
{
21+
/**
22+
* @return string[]
23+
*/
24+
public function getWorkflowNames(): array;
25+
26+
/**
27+
* @return string[]
28+
*/
29+
public function getPlaces(string $workflowName): array;
30+
}

0 commit comments

Comments
 (0)