Skip to content

Commit

Permalink
chore: added access block for codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Jan 23, 2024
1 parent 699db4b commit a294d77
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ let make = () => {
/>
</AccessControl>
| list{"recon"} =>
<AccessControl isEnabled=featureFlagDetails.recon>
<AccessControl isEnabled=featureFlagDetails.recon permission=Access>
<Recon />
</AccessControl>
| list{"sdk"} =>
<AccessControl isEnabled={!featureFlagDetails.isLiveMode}>
<AccessControl isEnabled={!featureFlagDetails.isLiveMode} permission=Access>
<SDKPage />
</AccessControl>
| list{"3ds"} =>
Expand Down Expand Up @@ -397,7 +397,8 @@ let make = () => {
<BusinessDetails />
</AccessControl>
| list{"business-profiles"} =>
<AccessControl isEnabled=featureFlagDetails.businessProfile>
<AccessControl
isEnabled=featureFlagDetails.businessProfile permission=Access>
<BusinessProfile />
</AccessControl>
| list{"quick-start"} => determineQuickStartPageState()
Expand Down
6 changes: 4 additions & 2 deletions src/screens/HyperSwitch/Developer/APIKeys/KeyManagement.res
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,21 @@ module ApiKeyAddBtn = {
@react.component
let make = (~getAPIKeyDetails) => {
let mixpanelEvent = MixpanelHook.useSendEvent()
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)
let (showModal, setShowModal) = React.useState(_ => false)
let initialValues = Dict.make()
initialValues->Dict.set("expiration", Never->getStringFromRecordType->Js.Json.string)

<>
<ApiEditModal showModal setShowModal initialValues getAPIKeyDetails />
<Button
<ACLButton
text="Create New API Key"
leftIcon={CustomIcon(
<Icon
name="plus" size=12 className="jp-gray-900 fill-opacity-50 dark:jp-gray-text_darktheme"
/>,
)}
text="Create New API Key"
access=userPermissionJson.apiKeyWrite
buttonType=Secondary
buttonSize=Small
onClick={_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let make = (
) => {
open PaymentSettingsListEntity
let (offset, setOffset) = React.useState(_ => 0)
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)

let businessProfileValues =
HyperswitchAtom.businessProfilesAtom
Expand All @@ -20,11 +21,11 @@ let make = (
subTitle="Set up and monitor transaction webhooks for real-time notifications."
/>
<LoadedTable
title="Payment settings"
title=" "
hideTitle=true
resultsPerPage=7
visibleColumns
entity={webhookProfileTableEntity}
entity={webhookProfileTableEntity(~permission=userPermissionJson.merchantAccountWrite)}
showSerialNumber=true
actualData={businessProfileValues->Array.map(Js.Nullable.return)}
totalResults={businessProfileValues->Array.length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ let getItems: Js.Json.t => array<profileEntity> = json => {
LogicUtils.getArrayDataFromJson(json, itemToObjMapper)
}

let webhookProfileTableEntity = EntityType.makeEntity(
~uri="",
~getObjects=getItems,
~defaultColumns,
~allColumns,
~getHeading,
~dataKey="",
~getCell,
~getShowLink={
profile => `/payment-settings/${profile.profile_id}`
},
(),
)
let webhookProfileTableEntity = (~permission: AuthTypes.authorization) =>
EntityType.makeEntity(
~uri="",
~getObjects=getItems,
~defaultColumns,
~allColumns,
~getHeading,
~dataKey="",
~getCell,
~getShowLink={
profile => permission === Access ? `/payment-settings/${profile.profile_id}` : ""
},
(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module AddEntryBtn = {
[
("profile_name", `default${list->Array.length->string_of_int}`->Js.Json.string),
]->Dict.fromArray
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)
let modalBody =
<div>
{switch modalState {
Expand Down Expand Up @@ -88,8 +89,9 @@ module AddEntryBtn = {

<div>
<UIUtils.RenderIf condition=isFromSettings>
<Button
<ACLButton
text="Add"
access={userPermissionJson.merchantAccountWrite}
buttonSize=Small
buttonType={Primary}
rightIcon={FontAwesome("plus")}
Expand Down
8 changes: 5 additions & 3 deletions src/screens/HyperSwitch/Surcharge/Surcharge.res
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ let make = () => {
let (pageView, setPageView) = React.useState(_ => LANDING)
let showPopUp = PopUpState.useShowPopUp()
let (showWarning, setShowWarning) = React.useState(_ => true)
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)

let getWasm = async () => {
try {
Expand Down Expand Up @@ -275,11 +276,12 @@ let make = () => {
<p className="text-base font-normal text-grey-700 opacity-50">
{"Create advanced rules using various payment parameters like amount, currency,payment method etc to enforce a surcharge on your payments"->React.string}
</p>
<Button
<ACLButton
text="Create New"
buttonType={Primary}
access=userPermissionJson.surchargeDecisionManagerWrite
buttonType=Primary
customButtonStyle="!w-1/6"
leftIcon={FontAwesome("plus")}
leftIcon=FontAwesome("plus")
onClick={_ => handleCreateNew()}
/>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/screens/HyperSwitch/ThreeDSFlow/HSwitchThreeDS.res
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ let make = () => {
let (pageView, setPageView) = React.useState(_ => NEW)
let showPopUp = PopUpState.useShowPopUp()
let (showWarning, setShowWarning) = React.useState(_ => true)
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)

let getWasm = async () => {
try {
Expand Down Expand Up @@ -295,11 +296,12 @@ let make = () => {
<p className="text-base font-normal text-grey-700 opacity-50">
{"Create advanced rules using various payment parameters like amount, currency,payment method etc to enforce 3DS authentication for specific payments to reduce fraudulent transactions"->React.string}
</p>
<Button
<ACLButton
text="Create New"
buttonType={Primary}
access=userPermissionJson.threeDsDecisionManagerWrite
buttonType=Primary
customButtonStyle="!w-1/6"
leftIcon={FontAwesome("plus")}
leftIcon=FontAwesome("plus")
onClick={_ => handleCreateNew()}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/AccessControl.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open AuthTypes
@react.component
let make = (~isEnabled=true, ~permission=NoAccess, ~children) => {
let make = (~isEnabled=true, ~permission, ~children) => {
let isAccessAllowed = permission === Access
isEnabled && isAccessAllowed ? children : <UnauthorizedPage />
}

0 comments on commit a294d77

Please sign in to comment.