Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: internal entity removal #1467

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entryPoints/AuthModule/UserInfo/UserInfoTypes.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type entity = [#Internal | #Organization | #Merchant | #Profile]
type entity = [#Organization | #Merchant | #Profile]
type userInfo = {
email: string,
isTwoFactorAuthSetup: bool,
Expand Down
9 changes: 3 additions & 6 deletions src/entryPoints/AuthModule/UserInfo/UserInfoUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let defaultValueOfUserInfo = {

let entityMapper = entity => {
switch entity->String.toLowerCase {
| "internal" => #Internal
| "organization" => #Organization
| "merchant" => #Merchant
| "profile" => #Profile
Expand All @@ -27,9 +26,7 @@ let entityMapper = entity => {

let transactionEntityMapper = entity => {
switch entity->String.toLowerCase {
| "internal"
| "merchant" =>
#Merchant
| "merchant" => #Merchant
| "profile" => #Profile
| _ => #Merchant
}
Expand All @@ -38,7 +35,7 @@ let transactionEntityMapper = entity => {
let analyticsEntityMapper = entity => {
switch entity->String.toLowerCase {
| "organization" => #Organization
| "merchant" | "internal" => #Merchant
| "merchant" => #Merchant
| "profile" => #Profile
| _ => #Merchant
}
Expand All @@ -61,7 +58,7 @@ let itemMapper = dict => {
name: dict->getString("name", defaultValueOfUserInfo.name),
orgId: dict->getString("org_id", defaultValueOfUserInfo.orgId),
recoveryCodesLeft: dict->getOptionInt("recovery_codes_left"),
roleId: dict->getString("role_id", defaultValueOfUserInfo.email),
roleId: dict->getString("role_id", defaultValueOfUserInfo.roleId),
verificationDaysLeft: dict->getOptionInt("verification_days_left"),
profileId: dict->getString("profile_id", ""),
userEntity: dict->getString("entity_type", "")->entityMapper,
Expand Down
14 changes: 7 additions & 7 deletions src/entryPoints/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ let make = () => {
let featureFlagDetails = featureFlagAtom->Recoil.useRecoilValueFromAtom
let (userPermissionJson, setuserPermissionJson) = Recoil.useRecoilState(userPermissionAtom)
let getEnumDetails = EnumVariantHook.useFetchEnumDetails()
let {userInfo: {orgId, merchantId, profileId}, checkUserEntity} = React.useContext(
let {userInfo: {orgId, merchantId, profileId, roleId}, checkUserEntity} = React.useContext(
UserInfoProvider.defaultContext,
)
let isInternalUser =
roleId->UserManagementUtils.stringToVariantMapper == InternalViewOnly ||
JeevaRamu0104 marked this conversation as resolved.
Show resolved Hide resolved
roleId->UserManagementUtils.stringToVariantMapper == InternalAdmin
let modeText = featureFlagDetails.isLiveMode ? "Live Mode" : "Test Mode"
let modeStyles = featureFlagDetails.isLiveMode
? "bg-hyperswitch_green_trans border-hyperswitch_green_trans text-hyperswitch_green"
Expand Down Expand Up @@ -151,12 +154,10 @@ let make = () => {
<Navbar
headerActions={<div className="relative flex items-center gap-4 my-2 ">
<GlobalSearchBar />
<RenderIf condition={checkUserEntity([#Internal])}>
<RenderIf condition={isInternalUser}>
<SwitchMerchantForInternal />
</RenderIf>
<RenderIf condition={!checkUserEntity([#Internal])}>
<ProfileSwitch />
</RenderIf>
<ProfileSwitch />
<div
className={`px-4 py-2 rounded whitespace-nowrap text-fs-13 ${modeStyles} font-semibold`}>
{modeText->React.string}
Expand Down Expand Up @@ -264,8 +265,7 @@ let make = () => {
</AccessControl>
| list{"developer-system-metrics"} =>
<AccessControl
isEnabled={checkUserEntity([#Internal]) &&
featureFlagDetails.systemMetrics}
isEnabled={isInternalUser && featureFlagDetails.systemMetrics}
permission=userPermissionJson.analyticsView>
<FilterContext key="SystemMetrics" index="SystemMetrics">
<SystemMetricsAnalytics />
Expand Down
18 changes: 14 additions & 4 deletions src/entryPoints/SidebarValues.res
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,16 @@ let paymentSettings = () => {
})
}

let developers = (isDevelopersEnabled, systemMetrics, ~permissionJson, ~checkUserEntity) => {
let isInternalUser = checkUserEntity([#Internal])
let developers = (
isDevelopersEnabled,
systemMetrics,
~permissionJson,
~checkUserEntity,
~roleId,
) => {
let isInternalUser =
roleId->UserManagementUtils.stringToVariantMapper == InternalViewOnly ||
roleId->UserManagementUtils.stringToVariantMapper == InternalAdmin
let isProfileUser = checkUserEntity([#Profile])
let apiKeys = apiKeys(permissionJson)
let paymentSettings = paymentSettings()
Expand Down Expand Up @@ -625,7 +633,9 @@ let reconAndSettlement = (recon, isReconEnabled, checkUserEntity) => {
let useGetSidebarValues = (~isReconEnabled: bool) => {
let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let permissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)
let {userInfo: {userEntity}, checkUserEntity} = React.useContext(UserInfoProvider.defaultContext)
let {userInfo: {userEntity, roleId}, checkUserEntity} = React.useContext(
UserInfoProvider.defaultContext,
)
let {
frm,
payOut,
Expand Down Expand Up @@ -670,7 +680,7 @@ let useGetSidebarValues = (~isReconEnabled: bool) => {
),
default->workflow(isSurchargeEnabled, ~permissionJson, ~isPayoutEnabled=payOut, ~userEntity),
recon->reconAndSettlement(isReconEnabled, checkUserEntity),
default->developers(systemMetrics, ~permissionJson, ~checkUserEntity),
default->developers(systemMetrics, ~permissionJson, ~checkUserEntity, ~roleId),
settings(~isConfigurePmtsEnabled=configurePmts, ~permissionJson, ~complianceCertificate),
]

Expand Down
19 changes: 4 additions & 15 deletions src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ let useGetURL = () => {
switch userEntity {
| #Organization
| #Merchant
| #Profile
| #Internal =>
| #Profile =>
`account/${merchantId}/profile/connectors`
}
}
Expand Down Expand Up @@ -226,8 +225,7 @@ let useGetURL = () => {
switch userEntity {
| #Organization
| #Merchant
| #Profile
| #Internal => `routing/list/profile`
| #Profile => `routing/list/profile`
}
}
| Post =>
Expand All @@ -249,7 +247,6 @@ let useGetURL = () => {
| #Organization => `analytics/v2/org/metrics/${domain}`
| #Merchant => `analytics/v2/merchant/metrics/${domain}`
| #Profile => `analytics/v2/profile/metrics/${domain}`
| _ => `analytics/v2/merchant/metrics/${domain}`
}

| _ => ""
Expand All @@ -274,7 +271,6 @@ let useGetURL = () => {
| #Organization => `analytics/v1/org/${domain}/info`
| #Merchant => `analytics/v1/merchant/${domain}/info`
| #Profile => `analytics/v1/profile/${domain}/info`
| _ => `analytics/v1/merchant/${domain}/info`
}

| _ => ""
Expand All @@ -286,7 +282,6 @@ let useGetURL = () => {
| #Organization => `analytics/v1/org/metrics/${domain}`
| #Merchant => `analytics/v1/merchant/metrics/${domain}`
| #Profile => `analytics/v1/profile/metrics/${domain}`
| _ => `analytics/v1/merchant/metrics/${domain}`
}

| _ => ""
Expand All @@ -302,7 +297,6 @@ let useGetURL = () => {
| #Organization => `analytics/v1/org/filters/${domain}`
| #Merchant => `analytics/v1/merchant/filters/${domain}`
| #Profile => `analytics/v1/profile/filters/${domain}`
| _ => `analytics/v1/merchant/filters/${domain}`
}

| _ => ""
Expand Down Expand Up @@ -331,8 +325,7 @@ let useGetURL = () => {
switch userEntity {
| #Organization
| #Merchant
| #Profile
| #Internal => `routing/payouts/list/profile`
| #Profile => `routing/payouts/list/profile`
}
}

Expand Down Expand Up @@ -365,23 +358,20 @@ let useGetURL = () => {
| #Organization => `analytics/v1/org/report/payments`
| #Merchant => `analytics/v1/merchant/report/payments`
| #Profile => `analytics/v1/profile/report/payments`
| _ => `analytics/v1/merchant/report/payments`
}

| REFUND_REPORT =>
switch transactionEntity {
| #Organization => `analytics/v1/org/report/refunds`
| #Merchant => `analytics/v1/merchant/report/refunds`
| #Profile => `analytics/v1/profile/report/refunds`
| _ => `analytics/v1/merchant/report/refunds`
}

| DISPUTE_REPORT =>
switch transactionEntity {
| #Organization => `analytics/v1/org/report/dispute`
| #Merchant => `analytics/v1/merchant/report/dispute`
| #Profile => `analytics/v1/profile/report/dispute`
| _ => `analytics/v1/merchant/report/dispute`
}

/* EVENT LOGS */
Expand Down Expand Up @@ -429,8 +419,7 @@ let useGetURL = () => {
switch userEntity {
| #Organization
| #Merchant
| #Profile
| #Internal =>
| #Profile =>
`account/${merchantId}/profile`
}
| Post =>
Expand Down
7 changes: 5 additions & 2 deletions src/screens/Sidebar/Sidebar.res
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ let make = (
let isMobileView = MatchMedia.useMobileChecker()
let sideBarRef = React.useRef(Nullable.null)
let {email} = useCommonAuthInfo()->Option.getOr(defaultAuthInfo)
let {checkUserEntity} = React.useContext(UserInfoProvider.defaultContext)
let {userInfo: {roleId}} = React.useContext(UserInfoProvider.defaultContext)
let isInternalUser =
roleId->UserManagementUtils.stringToVariantMapper == InternalViewOnly ||
roleId->UserManagementUtils.stringToVariantMapper == InternalAdmin
let (openItem, setOpenItem) = React.useState(_ => "")
let {isSidebarExpanded, setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext)

Expand Down Expand Up @@ -551,7 +554,7 @@ let make = (
</div>
</RenderIf>
</div>
<RenderIf condition={!checkUserEntity([#Internal])}>
<RenderIf condition={!isInternalUser}>
<SidebarSwitch isSidebarExpanded />
</RenderIf>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module NoteComponent = {
`You can only invite people for ${merchantId} here. To invite users to another merchant, please switch the merchant.`
| #Profile =>
`You can only invite people for ${profileId} here. To invite users to another profile, please switch the profile.`
| _ => ""
}

<div className="flex gap-2 items-start justify-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module OrganisationSelection = {

let disableSelect = switch userEntity {
| #Organization | #Merchant | #Profile => true
| _ => false
}

let handleOnChange = async (event, input: ReactFinalForm.fieldRenderPropsInput) => {
Expand Down Expand Up @@ -62,8 +61,7 @@ module MerchantSelection = {

let disableSelect = switch userEntity {
| #Merchant | #Profile => true
| #Organization
| _ => false
| #Organization => false
}

let handleOnChange = async (event, input: ReactFinalForm.fieldRenderPropsInput) => {
Expand Down Expand Up @@ -118,8 +116,7 @@ module ProfileSelection = {
let disableSelect = switch userEntity {
| #Profile => true
| #Organization
| #Merchant
| _ => false
| #Merchant => false
}

let handleOnChange = async (event, input: ReactFinalForm.fieldRenderPropsInput) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
type userManagementTypes = UsersTab | RolesTab

type internalUserType = InternalViewOnly | InternalAdmin | NonInternal

type permissionType =
| OperationsView
| OperationsManage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ let getUserManagementViewValues = (~checkUserEntity) => {
[default]
}
}

let stringToVariantMapper = roleId => {
open UserManagementTypes
switch roleId {
| "internal_view_only" => InternalViewOnly
| "internal_admin" => InternalAdmin
| _ => NonInternal
}
}
Loading