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

Add workaround for quick button inconsistency #5422

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Jan 13, 2024

WHY

BEFORE - What was wrong? What was happening before this PR?

Reported in #5421

Following a simple tutorial that should "just work", was not "just working" 🤷‍♂️

I've debugged the issue and the culprit is the fact that we ->studly($buttonName) to get the access string. So a button with the name comment would have the access string Comment.

AFTER - What is happening after this PR?

It checks both operation name strings. First the regular one and as a fallback the camelCased version of the operation.

HOW

How did you achieve that, in technical terms?

I could have just changed the stub and define the operation button with access => Str::studly($operationName) or just removed the studly() in the quick.blade.php file, but that would be a BC at the moment in any of those cases. But it's what I've planned for v7.

So I made it fallback to a camelCased version of the name as last resort to try to find access.
I don't think this would ever be a BC the way I implemented because it wouldn't be possible for you to have a moderate and a Moderate operations, or a SuperModerate and superModerate operations at the same time.

Is it a breaking change?

I don't think so, no.

How can we test the before & after?

Follow the tutorial in Backpack website https://backpackforlaravel.com/docs/6.x/crud-operations#creating-a-new-operation-with-a-form-1 . It will fail previously, it will work after.

@pxpm pxpm added Minor Bug A bug that happens only in a very niche or specific use case. Priority: MUST labels Jan 13, 2024
Comment on lines 42 to 47
// this shouldn't happen, but in v6 we introduced the "quick" button with an inconsistency with other buttons.
// the quick button name is converted with `Str::studly()` to get the access string and that makes it impossible
// for this function to determine the proper access key. For example, a quick button with the name `comment`
// would have the access key `Comment`, while create, update, delete etc have the access keys `create`, `update`, `delete` without transformation.
// we should remove the transformation in vendor\backpack\crud\src\resources\views\crud\buttons\quick.blade.php and remove this line from here in v7.
$condition = $condition ?? $this->get(Str::camel($operation).'.access');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pedro, what do you think, instead of this long comment... that we keep this as a feature, and don't remove it in v7?

Why am I suggesting this?

  • Because this is a DX problem that I've encountered too. It's easy to make typo with these, and it's a shitty thing to debug for 30 min. So streamlining the experience here could be a good DX win, as a result of fixing this bug.
  • In my opinion, using hasAccess('inline-edit') and hasAccess('InlineEdit') or hasAccess('inlineEdit')... should do the same thing.

Do you agree?

Copy link
Member

@tabacitu tabacitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the change. In fact, I'd make this the default going forward - that whatever gets passed to hasAccess() gets treated the same (InlineEdit, inline-edit, inlineEdit).

See my thoughts here #5422 (comment)

@tabacitu tabacitu assigned pxpm and unassigned tabacitu Jan 15, 2024
@pxpm
Copy link
Contributor Author

pxpm commented Jan 19, 2024

After our talk we decided to do this change on the blade file itself so it only concerns the quick button.

It's better to keep hasAccess() clean from string manipulations. Whatever string it receives, is the string it checks if there is access to.
We would risk introducing security issues if we tried to guess access for operations at this level, so we should be better with the solution for quick button in the blade file..

@pxpm pxpm merged commit 5044460 into main Jan 19, 2024
3 checks passed
@pxpm pxpm deleted the add-workaround-for-quick-button-inconsistency branch January 19, 2024 12:49
@pxpm
Copy link
Contributor Author

pxpm commented Jan 19, 2024

Also updated docs here: Laravel-Backpack/docs#541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A bug that happens only in a very niche or specific use case. Priority: MUST
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants