0

I a have two problems 1, I want to show order status base on user role, for instance if

Order table I have 3 status "pending", "received", "cancelled" with datatype "Enum". I have user role. on the same page I have uploaded an image using vichbundle successfully but I can't see it

"USER_ADMIN" and "USERS_PRODUCT" example if condition below.

if(USER_ADMIN)
{
  SHOW pending and cenceled products
}elseif(USERS_PRODUT){
   SHOW Received 
}

ProductCrudeController

use App\Entity\Items;
use App\Entity\Users;
use App\Entity\Orders;
use App\Entity\Orderstatus;
use App\Entity\Shippingorder;
use App\Entity\Purchasedorder;
use App\Entity\Shippingcompany;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Vich\UploaderBundle\Form\Type\VichFileType;


class PurchasedorderCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Purchasedorder::class;
    }

    
    public function configureFields(string $pageName): iterable
    {
        return [
            //IdField::new('id'),
            DateField::new('purchaseddate'),
            AssociationField::new('items'),

            //AssociationField::new('orders'),
            //AssociationField::new('orders.shippingorder')
           // AssociationField::new('Shippingcompany'),
            
           
        ];
    }
    

    public function configureActions(Actions $actions): Actions
{
    //return $actions->setPermission(Action::NEW, 'ROLE_ADMIN')
        //->setPermission(Action::DELETE, 'ROLE_SUPER_ADMIN')
    //;
    return $actions
        // ...
        ->add(Crud::PAGE_INDEX, Action::DETAIL);
        //$viewInvoice = Action::new('viewInvoice');
        $viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
            ->linkToCrudAction('renderInvoice');
            return $actions
            // ...
            ->add(Crud::PAGE_DETAIL, $viewInvoice);
}

public function configureCrud(Crud $crud): Crud
{
    
    return $crud
        // ...
        ->showEntityActionsAsDropdown()
    ;
}

public function configureFilters(Filters $filters): Filters
{
    return $filters
        ->add('orders')
        
    ;
}

Thank you in advance

shaedrich
  • 5,457
  • 3
  • 26
  • 42

1 Answers1

0

Restrict Access to Actions

Use the setPermission() method to define the security permission required to see the action link/button:

public function configureActions(Actions $actions): Actions
{
    $viewPending = Action::new('pending', 'View preding', 'fa fa-file-invoice')
        ->linkToCrudAction('renderPending');

    $viewRecieved = Action::new('recieved', 'View recieved', 'fa fa-file-invoice')
        ->linkToCrudAction('renderRecieved');
    ...

    return $actions
        // ...
        ->add(Crud::PAGE_DETAIL, $viewInvoice)
        // use the 'setPermission()' method to set the permission of actions
        // (the same permission is granted to the action on all pages)
        ->setPermission('pending', 'USER_ADMIN')

        // ...
        ->add(Crud::PAGE_DETAIL, $viewRecieved)
        // use the 'setPermission()' method to set the permission of actions
        // (the same permission is granted to the action on all pages)
        ->setPermission('recieved', 'USER_PRODUCT')
    ;
}
Dylan Delobel
  • 786
  • 10
  • 26