Skip to content

Instantly share code, notes, and snippets.

@pepa-linha
Last active August 8, 2020 10:49
Show Gist options
  • Save pepa-linha/4890472485dacbc7aea0fb4672d64ecc to your computer and use it in GitHub Desktop.
Save pepa-linha/4890472485dacbc7aea0fb4672d64ecc to your computer and use it in GitHub Desktop.
Nette ACL - assertions
<?php
public function formSuccess (Form $form, ArrayHash $values)
{
if (!$user->isAllowed($this->product, 'write-review')) {
// tady bych chtěl ty hlášky taky :-)
$form->addError(...);
return;
}
}
{if $user->isAllowed($product, 'write-review')}
<a>Napsat recenzi</a>
{else}
{* jak tady vypsat hlášky odpovídající řádkům "return false" v aserci, aniž bych znovu někde volal "findOrderWithProduct" *}
{/if}
<?php
$permission->allow(User::ROLE_MEMBER, Product::class, 'write-review', function (Permission $permission) {
$product = $permission->getQueriedResource();
$orderWithProduct = $this->orderRepository->findOrderWithProduct($product, $this->user);
// uživatel vubec produkt neobjednal
if ($orderWithProduct === null) {
return false;
}
// uživatel produkt objednal, ale nesplnil podmínku, od jaké doby objednání je možné recenzi napsat
if ($orderWithProduct->created > ...) {
return false;
}
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment