Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct the acl definition, correct navigation yml, remove unuse… #20

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class FavoriteController extends AbstractController
#[Acl(
id: 'synolia_favorite_frontend_view',
type: 'entity',
class: 'SynoliaFavoriteBundle\Entity\Favorite',
class: Favorite::class,
permission: 'VIEW',
group_name: 'commerce'
groupName: 'commerce'
)]
public function indexAction(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Synolia/Bundle/FavoriteBundle/Entity/Favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'ownership' => [
'organization_field_name' => 'organization',
'organization_column_name' => 'organization_id',
'frontend_owner_type' => 'FRONTEND_USER',
'frontend_owner_type' => 'FRONTEND_CUSTOMER',
'frontend_owner_field_name' => 'customerUser',
'frontend_owner_column_name' => 'customer_user_id', ],
'security' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,15 @@
namespace Synolia\Bundle\FavoriteBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;
use Oro\Bundle\CustomerBundle\Entity\CustomerUser;
use Oro\Bundle\OrganizationBundle\Entity\Organization;
use Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper;
use Synolia\Bundle\FavoriteBundle\Entity\Favorite;

class FavoriteRepository extends EntityRepository
{
public function findAllFilteredByAcl(AclHelper $aclHelper): array
{
return $aclHelper->apply($this->createQueryBuilder('f'))->getResult();
}

public function getFavoritesProductsCollection(CustomerUser $user, Organization $organization): array
{
return $this->createQueryBuilder('f')
->resetDQLPart('select')
->addSelect('IDENTITY(f.product) as product_id')
->andWhere('f.customerUser = :user')
->andWhere('f.organization = :organization')
->setParameters([
'user' => $user,
'organization' => $organization,
])
->getQuery()->getArrayResult();
}

public function getFavoritesProductsInSingleArray(CustomerUser $user, Organization $organization): array
{
$newArray = [];
$favorites = $this->getFavoritesProductsCollection($user, $organization);

foreach ($favorites as $favorite) {
$newArray[] = $favorite['product_id'];
}

return $newArray;
}

public function findAllProductIdsFilteredByAcl(AclHelper $aclHelper): array
{
$ids = [];
$favorites = $this->findAllFilteredByAcl($aclHelper);
$favorites = $aclHelper->apply($this->createQueryBuilder('f'))->getResult();

/** @var Favorite $favorite */
foreach ($favorites as $favorite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public function onResultAfter(SearchResultAfter $event): void
return;
}

if (!$this->security->isGranted('IS_AUTHENTICATED_FULLY')) {
return;
}

/** @var FavoriteRepository $favoriteRepo */
$favoriteRepo = $this->entityManager->getRepository(Favorite::class);
$favProductIds = $favoriteRepo->findAllProductIdsFilteredByAcl($this->aclHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ navigation:
children:
synolia_favorite_index: ~
oro_customer_menu_refreshing_teal:
scope_type: menu_fronend_visibility
scope_type: menu_frontend_visibility
children:
oro_customer_frontend_customer_user_profiles_and_addresses:
children:
Expand Down
Loading