Skip to content

Commit

Permalink
PIM-10485 : get category tree for channel context without filter user…
Browse files Browse the repository at this point in the history
… right
  • Loading branch information
Antoine Trouve committed Jun 22, 2022
1 parent 308651e commit c743b55
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Akeneo\Channel\Infrastructure\Component\Model\ChannelInterface;
use Akeneo\Channel\Infrastructure\Component\Repository\ChannelRepositoryInterface;
use Akeneo\Pim\Enrichment\Bundle\Controller\InternalApi\CategoryController;
use Akeneo\Platform\Bundle\FrameworkBundle\Security\SecurityFacadeInterface;
use Akeneo\Tool\Component\StorageUtils\Factory\SimpleFactoryInterface;
use Akeneo\Tool\Component\StorageUtils\Remover\RemoverInterface;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function __construct(
private SimpleFactoryInterface $channelFactory,
private ValidatorInterface $validator,
private SecurityFacadeInterface $securityFacade,
private CategoryController $categoryInternalApi
) {
}

Expand Down Expand Up @@ -74,6 +76,15 @@ public function getAction(Request $request, string $identifier): JsonResponse
);
}

/**
* Gets Category tree without user right filter
* @return JsonResponse
*/
public function listChannelCategoryTreeAction(): JsonResponse
{
return $this->categoryInternalApi->listAction(false);
}

/**
* Saves new channel
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ services:
- '@pim_catalog.factory.channel'
- '@validator'
- '@oro_security.security_facade'
- '@pim_enrich.controller.rest.category'

pim_api.controller.currency:
public: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pim_enrich_channel_rest_get:
requirements:
code: '[a-zA-Z0-9_]+'

pim_enrich_channel_category_tree_rest_get:
path: /rest/category-tree
defaults: { _controller: pim_enrich.controller.rest.channel:listChannelCategoryTreeAction}
methods: [GET]

pim_enrich_channel_rest_post:
path: /rest
defaults: { _controller: pim_enrich.controller.rest.channel:postAction }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,19 @@
*/
class CategoryController
{
/** @var CategoryRepositoryInterface */
protected $repository;

/** @var CategoryExtension */
protected $twigExtension;

/** @var NormalizerInterface */
protected $normalizer;

/** @var CollectionFilterInterface */
protected $collectionFilter;

public function __construct(
CategoryRepositoryInterface $repository,
CategoryExtension $twigExtension,
NormalizerInterface $normalizer,
CollectionFilterInterface $collectionFilter
protected CategoryRepositoryInterface $repository,
protected CategoryExtension $twigExtension,
protected NormalizerInterface $normalizer,
protected CollectionFilterInterface $collectionFilter
) {
$this->repository = $repository;
$this->twigExtension = $twigExtension;
$this->normalizer = $normalizer;
$this->collectionFilter = $collectionFilter;
}

/**
* List children categories
*
* @param Request $request The request object
* @param int $identifier The parent category identifier
* @param Request $request The request object
* @param int $identifier The parent category identifier
*
* @return JsonResponse
*/
Expand Down Expand Up @@ -83,27 +67,24 @@ public function listSelectedChildrenAction(Request $request, $identifier): JsonR
*
* @return JsonResponse
*/
public function listAction()
public function listAction(bool $applyUserRight = true): JsonResponse
{
$categories = $this->repository->findBy(
[
'parent' => null,
]
);

$categories = $this->collectionFilter->filterCollection($categories, 'pim.internal_api.product_category.view');
if ($applyUserRight) {
$categories = $this->collectionFilter->filterCollection($categories, 'pim.internal_api.product_category.view');
}

return new JsonResponse(
$this->normalizer->normalize($categories, 'internal_api')
);
}

/**
* @param string $identifier
*
* @return JsonResponse
*/
public function getAction($identifier)
public function getAction(string $identifier): JsonResponse
{
$category = $this->repository->findOneByIdentifier($identifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ config:
urls:
get: pim_enrich_family_variant_rest_get
channel:
module: pim/base-fetcher
module: pim/channel-fetcher
options:
urls:
list: pim_enrich_channel_rest_index
get: pim_enrich_channel_rest_get
list_channel_category_tree: pim_enrich_channel_category_tree_rest_get
locale:
module: pim/locale-fetcher
options:
Expand Down Expand Up @@ -576,6 +577,7 @@ config:
pim/product-fetcher: pimui/js/fetcher/product-fetcher
pim/product-model-fetcher: pimui/js/fetcher/product-model-fetcher
pim/family-fetcher: pimui/js/fetcher/family-fetcher
pim/channel-fetcher: pimui/js/fetcher/channel-fetcher

# Remover
pim/remover/base: pimui/js/remover/base-remover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ define([
return this;
}

FetcherRegistry.getFetcher('category')
.fetchAll()
FetcherRegistry.getFetcher('channel')
.fetchCategoryTree()
.then(
function (categories) {
if (0 === this.getFormData().category_tree.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

define(['underscore', 'pim/base-fetcher'], function (_, BaseFetcher) {
return BaseFetcher.extend({
/**
* Fetch only the parent category tree
* User right will not be apply.
* @return {Promise}
*/
fetchCategoryTree: function () {
return this.getJSON(this.options.urls.list_channel_category_tree).then(_.identity).promise();
},
});
});

0 comments on commit c743b55

Please sign in to comment.