Last active
August 8, 2020 10:49
-
-
Save pepa-linha/4890472485dacbc7aea0fb4672d64ecc to your computer and use it in GitHub Desktop.
Nette ACL - assertions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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