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

BelongsToMany non-pivot action shouldn't use PivotId #5923

Closed
Peterragheb opened this issue Oct 2, 2023 · 14 comments
Closed

BelongsToMany non-pivot action shouldn't use PivotId #5923

Peterragheb opened this issue Oct 2, 2023 · 14 comments
Assignees
Labels
bug Verified bug by the Nova team

Comments

@Peterragheb
Copy link

  • Laravel Version: 10.25.1
  • Nova Version: 4.27.13
  • PHP Version: 8.1.23
  • Database Driver & Version: postgres
  • Operating System and Version: macOS 13.5.2
  • Browser type and version: Chrome 117.0.5938.132
  • Reproduction Repository:

Description:

Selecting resources to run actions on in BelongsToMany field passes the ID field's pivotValue regardless if it's a pivot action or not.

I think this is due to that now in the IndexConcerns.js file since selectedResourceIds returns the pivotValue on the ID field.
The request's toSelectedResourceQuery selects from related table with the pivot ids which returns 0 records and causes the action to return "Sorry! You are not authorized to perform this action."

Detailed steps to reproduce the issue on a fresh Nova installation:

  • Create a belongs to many relationship and add action to the related resource (not a pivot action)
  • Try running the action
@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)

@crynobone crynobone added the needs more info More information is required label Oct 2, 2023
@Peterragheb
Copy link
Author

Well I found the root cause of the issue. It's because I'm chaining ->withPivot(['id']) on the relationship definition.
In my opinion the pivot id shouldn't take priority over the related model Id when it's not a pivot action. However I'm not sure you consider this a bug and that you'd like to handle this case.

In case you want to reproduce this issue: here's a repo

  • run php artisan db:seed (this will create all the needed resources)
  • Open the Project resource detail page
  • select the user and try to run the "Test Action"

@crynobone
Copy link
Member

Pivot ID should have priority when it is available, since we can target the specific IDs instead of just relying on related IDs.

@crynobone crynobone closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
@crynobone crynobone removed the needs more info More information is required label Oct 2, 2023
@Grafikart
Copy link

Grafikart commented Oct 13, 2023

Pivot ID should have priority when it is available, since we can target the specific IDs instead of just relying on related IDs.

The behaviour changed between 4.26 and 4.27, without any mention in the changelog so it breaks apps on a minor change (which is unexpected, maybe keep this change for a 5.X version).
In my opinion PivotIDs should be sent in another field and not mixed with "id".

@crynobone
Copy link
Member

In my opinion PivotIDs should be sent in another field and not mixed with "id".

This would break other applications as well. Pivot ID should always have priority when it is available.

@Francois-Francois
Copy link

This would break other applications as well. Pivot ID should always have priority when it is available.

No because it was not the behavior until this release. What breaks applications now, is this unexpected and undocumented change.

@crynobone
Copy link
Member

Sorry but this is the expected behaviour, we probably missing some dusk tests to cover this usage causing the issue to occur.

If someone willing to create a reproducing repository to showcase what need to change I would be willing to take a look.

@Grafikart
Copy link

A reproductable repo was already given in previous answer.

If this is the intended behaviour it means Actions are broken on every relation using id as pivot, with a confusing error "you are not authorized..." and no way to fix this issue since the query created inside the action does not handle this correctly (it expects id to be used on the main Model, not the Pivot). The PHP code from toSelectedResourceQuery() does not reflect this intended behaviour. Then a fix could come from an edit to toSelectedResourceQuery()

@Francois-Francois
Copy link

@crynobone any feedback ?

@Francois-Francois
Copy link

@crynobone just a followup ?

@crynobone
Copy link
Member

Still under review. Will update the issue once a PR is in place.

@crynobone crynobone changed the title Possible bug in BelongsToMany action execution BelongsToMany non-pivot action shouldn't use PivotId Oct 30, 2023
@crynobone crynobone self-assigned this Oct 30, 2023
@crynobone crynobone added the bug Verified bug by the Nova team label Oct 30, 2023
@crynobone crynobone reopened this Oct 30, 2023
@davidhemphill
Copy link
Contributor

I believe this issue should be fixed. Please post a new issue if the issue persists.

@Peterragheb
Copy link
Author

Yes all good now. Thanks!

Copy link

github-actions bot commented Dec 6, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

5 participants