Created
June 4, 2020 06:46
-
-
Save developerruhul/b0452bd449dc05c5bff269ec9bd5b105 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const features = { | |
| SUPPORT_PAGE: 1, | |
| OTHER_PAGE: 2, | |
| EXTRACT: 4, | |
| }; | |
| const permission = { | |
| 1: { | |
| forbidden: '*', | |
| allowed: [4], | |
| }, | |
| 100: { | |
| forbidden: null, | |
| allowed: '*', | |
| }, | |
| 99: { | |
| forbidden: [1], | |
| allowed: '*', | |
| }, | |
| admin: { | |
| forbidden: null, | |
| allowed: '*', | |
| }, | |
| }; | |
| const hasPermission = (userLevel = 1, feat) => { | |
| permission[userLevel].allowed.includes(feat); | |
| }; | |
| const ScreenshotComponent = () => { | |
| const user = { level: "admin" }; | |
| const hasAccess = hasPermission(user.level, 'SUPPORT-PAGE'); | |
| if (!hasAccess) return null; | |
| return <div>Your screenshot feature</div>; | |
| }; | |
| export default ScreenshotComponent; | |
| class Group { | |
| constructor(forbidden, allowed) { | |
| this.forbidden = forbidden | |
| this.allowed = allowed | |
| } | |
| hasAccess(feature="SUPPORT_PAGE") { | |
| return this.allowed.includes(feature) | |
| } | |
| addPermission() { | |
| } | |
| } | |
| const user = { | |
| userlevel: "admin" | |
| } | |
| const admin = new Group(null, "*"); | |
| const support = new Group([1], "*"); | |
| const trial = new Group("*", [4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment