refinedev / refine

A React Framework for building internal tools, admin panels, dashboards & B2B apps with unmatched flexibility.
https://refine.dev
MIT License
25.95k stars 1.96k forks source link

[BUG] Access Control lower cases resources intermittently #6004

Open JoeGaffney opened 1 month ago

JoeGaffney commented 1 month ago

Describe the bug

Sometimes resource names can get changed to lower case even though they are Camel cased.

            {
              name: "auditLogs",
              list: "/administration/auditLogs",
              show: "/administration/auditLogs/show/:id",
              meta: {
                icon: <></>,
                parent: "administration",
                label: "Audit Logs",
              },
            },

Will then appear as auditlogs in the access control Can method

Steps To Reproduce

Create a camelCase resouce.

Log the resource name in the accessControl.

export const accessControlProvider = {{ can: async ({{ resource, action, params }}) => {{ console.log(resource) console.log("Resource Name:", params?.resource?.name); ... }}, }};

Expected behavior

Not to change the casing

Packages

Additional Context

Was mentioned on discord to put a ticket in @aliemir said he has a solution.

Potentially somehow related to kbar?

BatuhanW commented 1 month ago

Hey @JoeGaffney thanks for the issue. We are open to contributions for this one.

JayBhensdadia commented 4 weeks ago

Hey @BatuhanW i would like to work on this issue. can you please assign it to me?

BatuhanW commented 4 weeks ago

Hey @JayBhensdadia assigned to you.

Please make sure to thoroughly read and follow our contribution guide. PRs that doesn't follow our contribution guide, will be closed.

https://refine.dev/docs/guides-concepts/contributing/

JayBhensdadia commented 3 weeks ago

sure

aliemir commented 3 weeks ago

This issue is related with our sider components (ThemedSiderV2 etc.). In the <CanAccess /> wrappers of the menu items we're sending the resource.name with toLowerCase(). Since we don't have this transform in any other usages of useCan or <CanAccess /> I don't think this is going to be a breaking change because user already needs to handle both lower cased and non-transformed resource names 🤔

JoeGaffney commented 3 weeks ago

ah that makes sense with the pattern I was seeing ( some cases changes and others not)

I did have a resource defined with only a show and not a list in the resources that was camel and was not affected. So would not appear in the side panel and thus probably not go through the canAccess first from the sider