Skip to content

Commit

Permalink
chore: address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitanjli Chopra authored and Gitanjli Chopra committed Nov 26, 2024
1 parent f699389 commit 6545312
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/screens/Hooks/OMPCreateAccessHook.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let useOMPCreateAccessHook: array<string> => CommonAuthTypes.authorization = allowedRoles => {
let {userInfo: {roleId}} = React.useContext(UserInfoProvider.defaultContext)

allowedRoles->Array.includes(roleId) ? Access : NoAccess
}
13 changes: 8 additions & 5 deletions src/screens/OMPSwitch/OMPSwitchHelper.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ module AddNewMerchantProfileButton = {
~customHRTagStyle="",
~addItemBtnStyle="",
) => {
open OMPSwitchUtils
let {userInfo: {roleId}} = React.useContext(UserInfoProvider.defaultContext)

let cursorStyles = GroupAccessUtils.cursorStyles(hasCreateNewOMPAccess(user, roleId))
let allowedRoles = switch user {
| "merchant" => ["org_admin"]
| "profile" => ["org_admin", "merchant_admin"]
| _ => []
}
let hasOMPCreateAccess = OMPCreateAccessHook.useOMPCreateAccessHook(allowedRoles)
let cursorStyles = GroupAccessUtils.cursorStyles(hasOMPCreateAccess)

<ACLDiv
authorization={hasCreateNewOMPAccess(user, roleId)}
authorization={hasOMPCreateAccess}
noAccessDescription="You do not have the required permissions for this action. Please contact your admin."
onClick={_ => setShowModal(_ => true)}
isRelative=false
Expand Down
2 changes: 0 additions & 2 deletions src/screens/OMPSwitch/OMPSwitchTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ type ompList = {
merchantList: array<ompListTypes>,
profileList: array<ompListTypes>,
}

type adminType = [#org_admin | #merchant_admin | #non_admin]
32 changes: 0 additions & 32 deletions src/screens/OMPSwitch/OMPSwitchUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,3 @@ let analyticsViewList = (~checkUserEntity): ompViews => {
[]
}
}

let mapUserType = user => {
switch user {
| "merchant" => #Merchant
| "profile" => #Profile
| _ => #Merchant
}
}

let mapRoleId = roleId => {
switch roleId {
| "org_admin" => #org_admin
| "merchant_admin" => #merchant_admin
| _ => #non_admin
}
}

let allowedRoles = user =>
switch user->mapUserType {
| #Merchant => [#org_admin]
| #Profile => [#org_admin, #merchant_admin]
| _ => []
}

let hasCreateNewOMPAccess = (user, roleId): CommonAuthTypes.authorization => {
let roles = allowedRoles(user)
if roles->Array.includes(roleId->mapRoleId) {
Access
} else {
NoAccess
}
}

0 comments on commit 6545312

Please sign in to comment.