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

feat(core): add onUnauthorized callback to <CanAccess /> component #4906

Merged

Conversation

alicanerdurmaz
Copy link
Member

@alicanerdurmaz alicanerdurmaz commented Sep 4, 2023

feat: added onUnauthorized callback to <CanAccess /> component. This callback to be called when useCan returns false.

<CanAccess
    onUnauthorized={({ resource, reason, action, params }) =>
        console.log(
            `You cannot access ${resource}-${params.id} resource with ${action} action because ${reason}`,
        )
    }
>
    <YourComponent />
</CanAccess>

Test plan (required)

image

Self Check before Merge

Please check all items below before review.

  • Corresponding issues are created/updated or not needed
  • Docs are updated/provided or not needed
  • Examples are updated/provided or not needed
  • TypeScript definitions are updated/provided or not needed
  • Tests are updated/provided or not needed
  • Changesets are provided or not needed

@changeset-bot
Copy link

changeset-bot bot commented Sep 4, 2023

🦋 Changeset detected

Latest commit: 4bc3073

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for refine-doc-live-previews ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/refine-doc-live-previews/deploys/64ff90f6c69e6e0008e8bb89
😎 Deploy Preview https://deploy-preview-4906--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for stupendous-taffy-33f80c ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/stupendous-taffy-33f80c/deploys/64ff90f6ad258800083e3ee5
😎 Deploy Preview https://deploy-preview-4906--stupendous-taffy-33f80c.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nx-cloud
Copy link

nx-cloud bot commented Sep 4, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4bc3073. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


🟥 Failed Commands
lerna run test --stream --scope @refinedev/* --scope create-refine-app
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 4, 2023 14:15 Inactive
@alicanerdurmaz alicanerdurmaz force-pushed the ref-38-can-access-should-accept-onUnauthorized-callback branch from 60a5432 to c79065f Compare September 4, 2023 14:16
@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for aquamarine-panda-e208bf ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/aquamarine-panda-e208bf/deploys/64ff90f623906900080a1a2b
😎 Deploy Preview https://deploy-preview-4906--aquamarine-panda-e208bf.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@alicanerdurmaz alicanerdurmaz marked this pull request as ready for review September 4, 2023 14:16
@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for imaginative-sundae-1fd394 ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/imaginative-sundae-1fd394/deploys/64ff90f6b40a230008f330a0
😎 Deploy Preview https://deploy-preview-4906--imaginative-sundae-1fd394.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for zippy-semolina-4ad81e ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/zippy-semolina-4ad81e/deploys/64ff90f66da6ec00080be33a
😎 Deploy Preview https://deploy-preview-4906--zippy-semolina-4ad81e.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 4, 2023

Deploy Preview for lighthearted-pastelito-e86ad1 ready!

Name Link
🔨 Latest commit 4bc3073
🔍 Latest deploy log https://app.netlify.com/sites/lighthearted-pastelito-e86ad1/deploys/64ff90f6b45c790009fc6c22
😎 Deploy Preview https://deploy-preview-4906--lighthearted-pastelito-e86ad1.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 5, 2023 06:52 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-mui-4906 September 5, 2023 06:53 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-4906 September 5, 2023 07:22 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 5, 2023 08:52 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-mui-4906 September 5, 2023 08:53 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-4906 September 5, 2023 09:17 Inactive
Copy link
Member

@BatuhanW BatuhanW left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

Added a minor comment.


import { useCan, useResource } from "@hooks";
import { BaseKey, IResourceItem, ITreeMenu } from "../../interfaces";

type Params = {
Copy link
Member

Choose a reason for hiding this comment

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

I think this name is too generic. Optionally, we can rename it to something more specific, so it will be easier to read.

@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 6, 2023 06:43 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-mui-4906 September 6, 2023 06:43 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-4906 September 6, 2023 07:09 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-mui-4906 September 6, 2023 09:19 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 6, 2023 09:20 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-4906 September 6, 2023 09:42 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-mui-4906 September 7, 2023 06:32 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-antd-4906 September 7, 2023 06:32 Inactive
@refine-bot refine-bot temporarily deployed to deploy-preview-website-4906 September 7, 2023 06:52 Inactive
Co-authored-by: Salih Özdemir <[email protected]>
@omeraplak omeraplak added this pull request to the merge queue Sep 11, 2023
Merged via the queue into next with commit 58d3d60 Sep 11, 2023
14 of 16 checks passed
@omeraplak omeraplak deleted the ref-38-can-access-should-accept-onUnauthorized-callback branch September 11, 2023 22:13
MahirMahdi pushed a commit to MahirMahdi/refine that referenced this pull request Sep 16, 2023
refinedev#4906)

* feat(core): add onUnauthorized callback to CanAccess component

* chore(core): changeset

* chore(core): refactor inline types to type

* chore(core): use only can state on effect dependencies

* test(core): test callback only trigger once

* chore(core): change type name

* chore: typo fix

Co-authored-by: Salih Özdemir <[email protected]>

---------

Co-authored-by: Batuhan Wilhelm <[email protected]>
Co-authored-by: Omer Aplak <[email protected]>
Co-authored-by: Salih Özdemir <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants