Skip to content

Commit

Permalink
fix: Dashboard default permission and signout fix (#451)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeeva Ramachandran <[email protected]>
  • Loading branch information
Riddhiagrawal001 and JeevaRamu0104 authored Feb 26, 2024
1 parent 91b5290 commit 75b6c42
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 73 deletions.
1 change: 0 additions & 1 deletion config/FeatureFlag.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions cypress/e2e/processors/processores-paypal_test.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 0 additions & 2 deletions src/entryPoints/FeatureFlagUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type featureFlag = {
forgetPassword: bool,
userJourneyAnalytics: bool,
surcharge: bool,
permissionBasedModule: bool,
disputeEvidenceUpload: bool,
paypalAutomaticFlow: bool,
inviteMultiple: bool,
Expand Down Expand Up @@ -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),
Expand Down
14 changes: 6 additions & 8 deletions src/entryPoints/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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()
}
Expand Down Expand Up @@ -425,9 +424,8 @@ let make = () => {
<ProdIntentForm />
</RenderIf>
<RenderIf
condition={featureFlagDetails.permissionBasedModule &&
userPermissionJson.merchantAccountWrite === Access &&
merchantDetailsTypedValue.merchant_name->Option.isNone}>
condition={userPermissionJson.merchantAccountWrite === Access &&
merchantDetailsTypedValue.merchant_name->Option.isNone}>
<CompanyNameModal showModal=companyNameModal setShowModal=setCompanyNameModal />
</RenderIf>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
9 changes: 8 additions & 1 deletion src/screens/Home/HomeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -166,7 +168,12 @@ module CheckoutCard = {
text: "Sign up Now",
onClick: {
_ => {
let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded)
let _ = APIUtils.handleLogout(
~fetchApi,
~setAuthStatus,
~setIsSidebarExpanded,
~clearRecoilValue,
)
}
},
},
Expand Down
8 changes: 7 additions & 1 deletion src/screens/Sidebar/Sidebar.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
)
}

<div className={`bg-sidebar-blue flex group border-r border-jp-gray-500 relative`}>
Expand Down
134 changes: 75 additions & 59 deletions src/screens/UserManagement/PermissionUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down

0 comments on commit 75b6c42

Please sign in to comment.