diff --git a/config/FeatureFlag.json b/config/FeatureFlag.json index 6ceee5320..353f46cf5 100644 --- a/config/FeatureFlag.json +++ b/config/FeatureFlag.json @@ -21,7 +21,6 @@ "forgot_password": false, "user_journey_analytics": false, "surcharge": false, - "permission_based_module": false, "dispute_evidence_upload": false, "paypal_automatic_flow": false, "invite_multiple": false, diff --git a/cypress/e2e/processors/processores-paypal_test.cy.js b/cypress/e2e/processors/processores-paypal_test.cy.js index 53a4f66a2..93af17928 100644 --- a/cypress/e2e/processors/processores-paypal_test.cy.js +++ b/cypress/e2e/processors/processores-paypal_test.cy.js @@ -8,6 +8,8 @@ beforeEach(() => { describe("Processors Create Module", () => { it("should successfully create the paypal test processor", () => { cy.url().should("eq", "http://localhost:9000/home"); + cy.get('input[name="merchant_name"]').type("paypal_test_cypress_api_key"); + cy.get("[data-button-for=startExploring]").click({ force: true }); cy.get("[data-testid=connectors]") .find(".justify-center") .click({ force: true }); diff --git a/src/entryPoints/FeatureFlagUtils.res b/src/entryPoints/FeatureFlagUtils.res index 22146482d..d4d1979ee 100644 --- a/src/entryPoints/FeatureFlagUtils.res +++ b/src/entryPoints/FeatureFlagUtils.res @@ -22,7 +22,6 @@ type featureFlag = { forgetPassword: bool, userJourneyAnalytics: bool, surcharge: bool, - permissionBasedModule: bool, disputeEvidenceUpload: bool, paypalAutomaticFlow: bool, inviteMultiple: bool, @@ -56,7 +55,6 @@ let featureFlagType = (featureFlags: JSON.t) => { forgetPassword: dict->getBool("forgot_password", false), userJourneyAnalytics: dict->getBool("user_journey_analytics", false), surcharge: dict->getBool("surcharge", false), - permissionBasedModule: dict->getBool("permission_based_module", false), disputeEvidenceUpload: dict->getBool("dispute_evidence_upload", false), paypalAutomaticFlow: dict->getBool("paypal_automatic_flow", false), inviteMultiple: dict->getBool("invite_multiple", false), diff --git a/src/entryPoints/HyperSwitchApp.res b/src/entryPoints/HyperSwitchApp.res index 82feeac25..52acc1419 100644 --- a/src/entryPoints/HyperSwitchApp.res +++ b/src/entryPoints/HyperSwitchApp.res @@ -94,6 +94,7 @@ let make = () => { let permissionJson = permissionsValue->Array.map(ele => ele->mapStringToPermissionType)->getPermissionJson setuserPermissionJson(._ => permissionJson) + permissionJson } catch { | Exn.Error(e) => { let err = Exn.message(e)->Option.getOr("Failed to Fetch!") @@ -106,16 +107,14 @@ let make = () => { try { let _ = await fetchSwitchMerchantList() let _ = await Window.connectorWasmInit() - if featureFlagDetails.permissionBasedModule { - let _ = await fetchPermissions() - } + let permissionJson = await fetchPermissions() if merchantId->isNonEmptyString { - if userPermissionJson.merchantConnectorAccountRead === Access { + if permissionJson.merchantConnectorAccountRead === Access { let _ = await fetchConnectorListResponse() } - if userPermissionJson.merchantAccountRead === Access { + if permissionJson.merchantAccountRead === Access { let _ = await fetchBusinessProfiles() let _ = await fetchMerchantAccountDetails() } @@ -425,9 +424,8 @@ let make = () => { Option.isNone}> + condition={userPermissionJson.merchantAccountWrite === Access && + merchantDetailsTypedValue.merchant_name->Option.isNone}> diff --git a/src/screens/APIUtils/APIUtils.res b/src/screens/APIUtils/APIUtils.res index 247f230a7..bd8760430 100644 --- a/src/screens/APIUtils/APIUtils.res +++ b/src/screens/APIUtils/APIUtils.res @@ -242,8 +242,8 @@ let handleLogout = async ( // let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ()) setAuthStatus(HyperSwitchAuthTypes.LoggedOut) setIsSidebarExpanded(_ => false) - LocalStorage.clear() clearRecoilValue() + LocalStorage.clear() RescriptReactRouter.push("/login") } diff --git a/src/screens/Home/HomeUtils.res b/src/screens/Home/HomeUtils.res index de362f857..24fe9b7aa 100644 --- a/src/screens/Home/HomeUtils.res +++ b/src/screens/Home/HomeUtils.res @@ -147,6 +147,8 @@ module CheckoutCard = { let (_authStatus, setAuthStatus) = React.useContext(AuthInfoProvider.authStatusContext) let {setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext) let isPlayground = HSLocalStorage.getIsPlaygroundFromLocalStorage() + let clearRecoilValue = ClearRecoilValueHook.useClearRecoilValue() + let connectorList = HyperswitchAtom.connectorListAtom ->Recoil.useRecoilValueFromAtom @@ -166,7 +168,12 @@ module CheckoutCard = { text: "Sign up Now", onClick: { _ => { - let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded) + let _ = APIUtils.handleLogout( + ~fetchApi, + ~setAuthStatus, + ~setIsSidebarExpanded, + ~clearRecoilValue, + ) } }, }, diff --git a/src/screens/Sidebar/Sidebar.res b/src/screens/Sidebar/Sidebar.res index 94f816c7f..826c5d28b 100644 --- a/src/screens/Sidebar/Sidebar.res +++ b/src/screens/Sidebar/Sidebar.res @@ -478,6 +478,7 @@ let make = ( let {isSidebarExpanded, setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext) let {setIsSidebarDetails} = React.useContext(SidebarProvider.defaultContext) let minWidthForPinnedState = MatchMedia.useMatchMedia("(min-width: 1280px)") + let clearRecoilValue = ClearRecoilValueHook.useClearRecoilValue() React.useEffect1(() => { if minWidthForPinnedState { @@ -527,7 +528,12 @@ let make = ( let transformClass = "transform md:translate-x-0 transition" let handleLogout = _ => { - let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded) + let _ = APIUtils.handleLogout( + ~fetchApi, + ~setAuthStatus, + ~setIsSidebarExpanded, + ~clearRecoilValue, + ) }
diff --git a/src/screens/UserManagement/PermissionUtils.res b/src/screens/UserManagement/PermissionUtils.res index 34eea349a..0e726a75b 100644 --- a/src/screens/UserManagement/PermissionUtils.res +++ b/src/screens/UserManagement/PermissionUtils.res @@ -139,69 +139,85 @@ let getAccessValue = (~permissionValue: permissionType, ~permissionList) => { } let defaultValueForPermission = { - paymentRead: Access, - paymentWrite: Access, - refundRead: Access, - refundWrite: Access, - apiKeyRead: Access, - apiKeyWrite: Access, - merchantAccountRead: Access, - merchantAccountWrite: Access, - merchantConnectorAccountRead: Access, - merchantConnectorAccountWrite: Access, - forexRead: Access, - routingRead: Access, - routingWrite: Access, - disputeRead: Access, - disputeWrite: Access, - mandateRead: Access, - mandateWrite: Access, - customerRead: Access, - customerWrite: Access, - fileRead: Access, - fileWrite: Access, - analytics: Access, - threeDsDecisionManagerWrite: Access, - threeDsDecisionManagerRead: Access, - surchargeDecisionManagerWrite: Access, - surchargeDecisionManagerRead: Access, - usersRead: Access, - usersWrite: Access, + paymentRead: NoAccess, + paymentWrite: NoAccess, + refundRead: NoAccess, + refundWrite: NoAccess, + apiKeyRead: NoAccess, + apiKeyWrite: NoAccess, + merchantAccountRead: NoAccess, + merchantAccountWrite: NoAccess, + merchantConnectorAccountRead: NoAccess, + merchantConnectorAccountWrite: NoAccess, + forexRead: NoAccess, + routingRead: NoAccess, + routingWrite: NoAccess, + disputeRead: NoAccess, + disputeWrite: NoAccess, + mandateRead: NoAccess, + mandateWrite: NoAccess, + customerRead: NoAccess, + customerWrite: NoAccess, + fileRead: NoAccess, + fileWrite: NoAccess, + analytics: NoAccess, + threeDsDecisionManagerWrite: NoAccess, + threeDsDecisionManagerRead: NoAccess, + surchargeDecisionManagerWrite: NoAccess, + surchargeDecisionManagerRead: NoAccess, + usersRead: NoAccess, + usersWrite: NoAccess, } +// TODO: Refactor to not call function for every permission let getPermissionJson = permissionList => { - let getAccessValueFromPermission = permissionValue => - getAccessValue(~permissionList, ~permissionValue) - { - paymentRead: PaymentRead->getAccessValueFromPermission, - paymentWrite: PaymentWrite->getAccessValueFromPermission, - refundRead: RefundRead->getAccessValueFromPermission, - refundWrite: RefundWrite->getAccessValueFromPermission, - apiKeyRead: ApiKeyRead->getAccessValueFromPermission, - apiKeyWrite: ApiKeyWrite->getAccessValueFromPermission, - merchantAccountRead: MerchantAccountRead->getAccessValueFromPermission, - merchantAccountWrite: MerchantAccountWrite->getAccessValueFromPermission, - merchantConnectorAccountRead: MerchantConnectorAccountRead->getAccessValueFromPermission, - merchantConnectorAccountWrite: MerchantConnectorAccountWrite->getAccessValueFromPermission, - forexRead: ForexRead->getAccessValueFromPermission, - routingRead: RoutingRead->getAccessValueFromPermission, - routingWrite: RoutingWrite->getAccessValueFromPermission, - disputeRead: DisputeRead->getAccessValueFromPermission, - disputeWrite: DisputeWrite->getAccessValueFromPermission, - mandateRead: MandateRead->getAccessValueFromPermission, - mandateWrite: MandateWrite->getAccessValueFromPermission, - customerRead: CustomerRead->getAccessValueFromPermission, - customerWrite: CustomerWrite->getAccessValueFromPermission, - fileRead: FileRead->getAccessValueFromPermission, - fileWrite: FileWrite->getAccessValueFromPermission, - analytics: Analytics->getAccessValueFromPermission, - threeDsDecisionManagerWrite: ThreeDsDecisionManagerWrite->getAccessValueFromPermission, - threeDsDecisionManagerRead: ThreeDsDecisionManagerRead->getAccessValueFromPermission, - surchargeDecisionManagerWrite: SurchargeDecisionManagerWrite->getAccessValueFromPermission, - surchargeDecisionManagerRead: SurchargeDecisionManagerRead->getAccessValueFromPermission, - usersRead: UsersRead->getAccessValueFromPermission, - usersWrite: UsersWrite->getAccessValueFromPermission, + paymentRead: getAccessValue(~permissionValue=PaymentRead, ~permissionList), + paymentWrite: getAccessValue(~permissionValue=PaymentWrite, ~permissionList), + refundRead: getAccessValue(~permissionValue=RefundRead, ~permissionList), + refundWrite: getAccessValue(~permissionValue=RefundWrite, ~permissionList), + apiKeyRead: getAccessValue(~permissionValue=ApiKeyRead, ~permissionList), + apiKeyWrite: getAccessValue(~permissionValue=ApiKeyWrite, ~permissionList), + merchantAccountRead: getAccessValue(~permissionValue=MerchantAccountRead, ~permissionList), + merchantAccountWrite: getAccessValue(~permissionValue=MerchantAccountWrite, ~permissionList), + merchantConnectorAccountRead: getAccessValue( + ~permissionValue=MerchantConnectorAccountRead, + ~permissionList, + ), + merchantConnectorAccountWrite: getAccessValue( + ~permissionValue=MerchantConnectorAccountWrite, + ~permissionList, + ), + forexRead: getAccessValue(~permissionValue=ForexRead, ~permissionList), + routingRead: getAccessValue(~permissionValue=RoutingRead, ~permissionList), + routingWrite: getAccessValue(~permissionValue=RoutingWrite, ~permissionList), + disputeRead: getAccessValue(~permissionValue=DisputeRead, ~permissionList), + disputeWrite: getAccessValue(~permissionValue=DisputeWrite, ~permissionList), + mandateRead: getAccessValue(~permissionValue=MandateRead, ~permissionList), + mandateWrite: getAccessValue(~permissionValue=MandateWrite, ~permissionList), + customerRead: getAccessValue(~permissionValue=CustomerRead, ~permissionList), + customerWrite: getAccessValue(~permissionValue=CustomerWrite, ~permissionList), + fileRead: getAccessValue(~permissionValue=FileRead, ~permissionList), + fileWrite: getAccessValue(~permissionValue=FileWrite, ~permissionList), + analytics: getAccessValue(~permissionValue=Analytics, ~permissionList), + threeDsDecisionManagerWrite: getAccessValue( + ~permissionValue=ThreeDsDecisionManagerWrite, + ~permissionList, + ), + threeDsDecisionManagerRead: getAccessValue( + ~permissionValue=ThreeDsDecisionManagerRead, + ~permissionList, + ), + surchargeDecisionManagerWrite: getAccessValue( + ~permissionValue=SurchargeDecisionManagerWrite, + ~permissionList, + ), + surchargeDecisionManagerRead: getAccessValue( + ~permissionValue=SurchargeDecisionManagerRead, + ~permissionList, + ), + usersRead: getAccessValue(~permissionValue=UsersRead, ~permissionList), + usersWrite: getAccessValue(~permissionValue=UsersWrite, ~permissionList), } }