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

403 on nova resource update and call wrong gate #6546

Closed
MattiaMarchiorato opened this issue Oct 3, 2024 · 5 comments
Closed

403 on nova resource update and call wrong gate #6546

MattiaMarchiorato opened this issue Oct 3, 2024 · 5 comments
Labels
needs more info More information is required

Comments

@MattiaMarchiorato
Copy link

  • Laravel Version: "laravel/framework": "^10.0"
  • Nova Version: "laravel/nova": "^4.27"
  • PHP Version: 8.3
  • Database Driver & Version: MySQL 8.0.30
  • Operating System and Version: Ubuntu 24.04
  • Browser type and version: chrome

Description:
On updating a nova resource the app hits 3 gates:
viewNova - allowed
create - allowed
[
"App\Models\QrCode"
]

create - denied
[
"App\Models\Suggestion"
]

There are no relations with models QrCode and Suggestion and there are no policies for suggestions.

Thanks

MM

@crynobone crynobone added the needs more info More information is required label Oct 3, 2024
@crynobone
Copy link
Member

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@MattiaMarchiorato
Copy link
Author

Hello @crynobone

You can create a fresh project with nova and telescope and add this UserPolicy


namespace App\Policies;

use App\Models\User;
use Illuminate\Auth\Access\Response;

class UserPolicy
{
    /**
     * Create a new policy instance.
     */
    public function __construct()
    {
        //
    }

    public function update(User $user, User $EditedUser): Response
    {
        if (($EditedUser->id === $user->id) || $user->isAdmin()) return Response::allow();

        return Response::deny('You do not own this qr code.');
    }
}

Then when you try to update an user you will see a lot of denied gateway
Screenshot 2024-10-04 alle 15 28 18

Please tell me if you fall in the same issue.

Thanks

MM

@MattiaMarchiorato
Copy link
Author

After a short analysis, get that the gate were denied if the method does not exist, this seems a bug to me.
For example, for some Models we just need maybe an update policy to restrict this action but not a view or create policy, am I wrong?

Thanks

MM

@ziming

This comment has been minimized.

@crynobone
Copy link
Member

After a short analysis, get that the gate were denied if the method does not exist, this seems a bug to me.

Expected behaviour and already described on the documentation: https://nova.laravel.com/docs/resources/authorization.html#undefined-policy-methods

@crynobone crynobone closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

3 participants