Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
297 stars 18 forks source link

[Bug/Wrong way] when limited access resource by searchQuery #119

Closed ThanhSonITNIC closed 1 week ago

ThanhSonITNIC commented 3 weeks ago

Description

Product (hasMany Pricing) Pricing (belongsTo Tax): product_id, tax_id, salesman_display

PricingResource: _only return for salesman when salesman_display is true_

public function searchQuery(RestRequest $request, Builder $query)
{
    if (auth()->user()->isSalesman()) {
        return $query->where('salesman_display', true);
    }

    return $query;
}

GautierDele commented 3 weeks ago

Hello,

I think i'm seeing what you mean, for me each resource needs to be secured its own way so you should also impact the tax query in your way because your resource could also be accessed directly and it won't be secured

Tell me if it's fixing your problem

ThanhSonITNIC commented 3 weeks ago

hmm, TaxResource should be public for all, Pricing is limited. Schema including Product.Pricing.Tax: this mean Tax only belongs when Pricing is present

GautierDele commented 2 weeks ago

then if the resource should be public you shouldn't impact the "search query" but instead apply a filter on your include