-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds utils for access checks (#3724)
* Adds utils for access checks * Add Route Support * Remove cache on route change * Partially deprecate the useAccessReview hook * Add pf link & remove debug code related * Simplify structure of accessReview logically * Added some clarity to teh README * Code cleanup -- syncing variable names & some extra TS * Added support for product admins having access over the deployment namespace * Fix bad logic -- poorly written & breaks tests - yay tests * Drop test related to admins only get to see settings * Removes unused import that breaks linter
- Loading branch information
1 parent
f9a26e5
commit 05a3f3c
Showing
20 changed files
with
595 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { AccessReviewResourceAttributes } from '~/k8sTypes'; | ||
import { useAccessAllowed } from './useAccessAllowed'; | ||
|
||
type AccessAllowedProps = { | ||
resourceAttributes: AccessReviewResourceAttributes; | ||
children: () => React.ReactNode; | ||
noAccessRender?: () => React.ReactNode; | ||
}; | ||
|
||
/** | ||
* Wraps content that is lazy rendered. Uses useAccessAllowed to handle rendering content easier. | ||
* Consider using verbModelAccess for resourceAttributes. | ||
* @see verbModelAccess | ||
* @see useAccessAllowed | ||
*/ | ||
export const AccessAllowed: React.FC<AccessAllowedProps> = ({ | ||
resourceAttributes, | ||
children, | ||
noAccessRender, | ||
}) => { | ||
const [isAllowed, isLoaded] = useAccessAllowed(resourceAttributes); | ||
|
||
if (!isLoaded) { | ||
return null; | ||
} | ||
|
||
if (!isAllowed) { | ||
return noAccessRender ? noAccessRender() : null; | ||
} | ||
|
||
return children(); | ||
}; |
Oops, something went wrong.