genetic-orange
genetic-orangeโ€ข2y ago

Hide *Button for forbidden actions

Hi! Is there a way to avoid the disabled button for actions an user cannot do (because unauthorized)? Right now my "basic user" should only be able to see (not edit) a list, and its detail. Using <EditButton> in the actions column instead makes the button appear as disabled (but still clickable). Is there a way to either : 1- disable also the click on the button 2- do not print the button at all if can is false
9 Replies
genetic-orange
genetic-orangeโ€ข2y ago
<DeleteButton> already has Solution #1, because it relies on the onClick, which is not triggered on a disabled button I'd love to see a prop "showWhenUnauthorized" (default true) that hides the button at all if can for that action is false
Omer
Omerโ€ข2y ago
Hey @kino90 , I hope you are very well. I am happy to see you again ๐Ÿป Item 1 is a BUG that definitely needs to be fixed. Can you create an issue for this? (https://github.com/pankod/refine/issues/new?assignees=&labels=bug&template=bug_report.yml&title=%5BBUG%5D) temporarily you can try this,
<CanAccess
resource="posts"
action="edit"
params={{ id: 1 }}
>
<EditButton ignoreAccessControlProvider />;
</CanAccess>
<CanAccess
resource="posts"
action="edit"
params={{ id: 1 }}
>
<EditButton ignoreAccessControlProvider />;
</CanAccess>
genetic-orange
genetic-orangeโ€ข2y ago
Thanks, I'll open the issue right now ๐Ÿ™‚ in the meantime I'll try with the <CanAccess> component! Thanks! ๐Ÿ˜‰
genetic-orange
genetic-orangeโ€ข2y ago
GitHub
[BUG] Disable click on <*Button>s when unauthorized ยท Issue #2828 ยท...
Describe the bug Right now my &quot;basic user&quot; should only be able to see (not edit) a list, and its detail. Using &lt;EditButton&gt; in the List actions column instead makes ...
Omer
Omerโ€ข2y ago
Thank you! @kino90 By the way, which UI library are you using?
genetic-orange
genetic-orangeโ€ข2y ago
Mantine ui, sorry.. but if I recall correctly there was the same issue in the antd lib
Omer
Omerโ€ข2y ago
Hey @kino90 , We've released @pankod/refine-mantine@1.9.0. Could you approve fix? https://github.com/refinedev/refine/releases/tag/%40pankod%2Frefine-mantine%401.9.0
genetic-orange
genetic-orangeโ€ข2y ago
Today and tomorrow I'm not at work, I'll test it next monday! Thanks for the quick fix! ๐Ÿš€