SyliusResourceBundle: lack of a feature to pass a mandatory parameter to repository in controller

14 views
Skip to first unread message

Vidy Videni

unread,
Jan 6, 2016, 9:47:06 PM1/6/16
to Sylius
I have a controller that is used by different user, administrator can list all resources, but another role can't only list resources that are owned by himself,  the list functionality logic for the two roles  is same, the only difference is that  I need to pass a extra parameter to  query builder when  the second role uses  that function. I check the source code of the ResourceController, there is no way to pass a mandatory parameter to criteria for it would be override by criteria when it is configured in routing file. I think there should be a way that we can do this.

public function indexAction(Request $request)
{
$this->isGrantedOr403('index');

$criteria = $this->config->getCriteria();


$sorting = $this->config->getSorting();

$repository = $this->getRepository();


if ($this->config->isPaginated()) {
$resources = $this->resourceResolver->getResource(
$repository,
'createPaginator',
array($criteria, $sorting)
);
$resources->setCurrentPage($request->get('page', 1), true, true);
$resources->setMaxPerPage($this->config->getPaginationMaxPerPage());

if ($this->config->isApiRequest()) {
$resources = $this->getPagerfantaFactory()->createRepresentation(
$resources,
new Route(
$request->attributes->get('_route'),
array_merge($request->attributes->get('_route_params'), $request->query->all())
)
);
}
} else {
$resources = $this->resourceResolver->getResource(
$repository,
'findBy',
array($criteria, $sorting, $this->config->getLimit())
);
}

$view = $this
->view()
->setTemplate($this->config->getTemplate('index.html'))
->setTemplateVar($this->config->getPluralResourceName())
->setData($resources)
;

return $this->handleView($view);
}

Vidy Videni

unread,
Jan 6, 2016, 9:50:24 PM1/6/16
to Sylius
but another role can't only list resources that are owned by himself

this description has a mistake , it should be 
but another role can only list resources that are owned by himself
Reply all
Reply to author
Forward
0 new messages