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

Allow multiple optional parameters to be passed down to applyScope() #225

Closed
LordSimal opened this issue Jan 5, 2023 · 0 comments
Closed
Milestone

Comments

@LordSimal
Copy link
Contributor

LordSimal commented Jan 5, 2023

To adjust ORM queries one has to use the ->applyScope() method of the AuthorizationComponent.

But in certain scenarios it would be helpfull to pass down arguments to the ->applyScope() method because the query needs to be adjusted according to

  • the current logged in user AND
  • the state of a specific service object or maybe request parameters.

The proposed solution would look like that:

public function index(MyService $myService)
{
    $this->Authorization->skipAuthorization();
    $query = $this->Products->find();
    $query = $this->Authorization->applyScope($query, 'index', $myService);
    $products = $this->paginate($query);

    $this->set(compact('products'));
}

And in the ProductsTablePolicy.php it would look like this:

class ProductsTablePolicy
{
    public function scopeIndex(IdentityInterface $user, Query $query, $myService)
    {
        return $query->where(['Products.price >' => 0]);
    }
}

This would be of course a BC break because we would have to adjust at least the IdentityInterface::applyScope as well as the AuthorizationServiceInterface::applyScope

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant