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: Added Access Type & Remove the Read & ReadWrite Type #267

Merged
merged 6 commits into from
Jan 18, 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
75 changes: 11 additions & 64 deletions src/components/EntityScaffold.res
Original file line number Diff line number Diff line change
@@ -1,85 +1,32 @@
module ComingSoon = {
@react.component
let make = (~title) => {
<div className="h-full w-full flex flex-col items-center justify-center">
<div className="text-2xl text-gray-500 pb-4"> {React.string(title)} </div>
<div> {React.string("Coming soon...")} </div>
</div>
}
}

module ShowPage = {
@react.component
let make = (~entityName, ~id) => {
<div className="h-full w-fit flex flex-col m-12">
<div className="text-2xl text-gray-500 pb-4">
{React.string(`Show ${entityName} `)}
<span className="text-sm"> {React.string(`#${id}`)} </span>
</div>
<div> {React.string("Coming soon...")} </div>
</div>
}
}

module UnauthorizedPage = {
@react.component
let make = (~entityName) => {
<div className="h-full w-fit flex flex-col m-12">
<div className="text-2xl text-gray-500 pb-4"> {React.string(entityName)} </div>
<div> {React.string("You don't have access to this module. Contact admin for access")} </div>
</div>
}
}

@react.component
let make = (
~entityName="",
~remainingPath,
~isAdminAccount=false,
~access: AuthTypes.authorization=ReadWrite,
~renderList=() => <ComingSoon title="List" />,
~renderNewForm=() => <ComingSoon title="New Form" />,
~access: AuthTypes.authorization=Access,
~renderList,
~renderNewForm=?,
~renderShow=?,
~renderOrder=?,
~renderEdit=_id => <ComingSoon title="Edit Form" />,
~renderEditWithMultiId=(_id1, _id2) => <ComingSoon title="Edit Form" />,
~renderClone=_id => <ComingSoon title="Clone Form" />,
) => {
if access === NoAccess {
<UnauthorizedPage entityName />
<UnauthorizedPage />
} else {
switch remainingPath {
| list{"new"} =>
switch access {
| ReadWrite => renderNewForm()
| _ => <UnauthorizedPage entityName />
}
| list{id, "clone"} =>
switch access {
| ReadWrite => renderClone(id)
| _ => <UnauthorizedPage entityName />
| Access =>
switch renderNewForm {
| Some(element) => element()
| None => React.null
}
| NoAccess => <UnauthorizedPage />
}
| list{id} =>
let page = switch renderShow {
| Some(fn) => fn(id)
| None => <ShowPage entityName id />
| None => React.null
}
page
| list{id, "edit"} =>
switch access {
| ReadWrite => renderEdit(id)
| _ => <UnauthorizedPage entityName />
}
| list{id1, id2, "edit"} =>
switch access {
| ReadWrite => renderEditWithMultiId(id1, id2)
| _ => <UnauthorizedPage entityName />
}
| list{"order", id} =>
switch renderOrder {
| Some(fn) => fn(id)
| None => <NotFoundPage />
}
| list{} => renderList()
| _ => <NotFoundPage />
}
Expand Down
19 changes: 19 additions & 0 deletions src/components/UnauthorizedPage.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@react.component
let make = (~message="You don't have access to this module. Contact admin for access") => {
let {setDashboardPageState} = React.useContext(GlobalProvider.defaultContext)
React.useEffect0(() => {
RescriptReactRouter.replace("/unauthorized")
None
})
<NoDataFound message renderType={Locked}>
<Button
text={"Go to Home"}
buttonType=Primary
onClick={_ => {
setDashboardPageState(_ => #HOME)
RescriptReactRouter.replace("/home")
}}
customButtonStyle="mt-4 !p-2"
/>
</NoDataFound>
}
11 changes: 2 additions & 9 deletions src/components/form/BoolInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ let make = (
~boolCustomClass="",
~addAttributeId="",
) => {
let accessLevel = React.useContext(FormAuthContext.formAuthContext)
let boolInput = baseInput->ffInputToBoolInput
let boolValue: Js.Json.t = boolInput.value

Expand All @@ -126,14 +125,8 @@ let make = (
let setIsSelected = boolInput.onChange

isCheckBox
? <CheckBoxIcon
isSelected setIsSelected isDisabled={isDisabled || accessLevel == AuthTypes.Read}
/>
? <CheckBoxIcon isSelected setIsSelected isDisabled={isDisabled} />
: <BaseComponent
isSelected
setIsSelected
isDisabled={isDisabled || accessLevel == AuthTypes.Read}
boolCustomClass
addAttributeId
isSelected setIsSelected isDisabled={isDisabled} boolCustomClass addAttributeId
/>
}
2 changes: 1 addition & 1 deletion src/context/FormAuthContext.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let formAuthContext = React.createContext(AuthTypes.ReadWrite)
let formAuthContext = React.createContext(AuthTypes.Access)

let make = React.Context.provider(formAuthContext)
12 changes: 6 additions & 6 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ let make = () => {
<EntityScaffold
entityName="Payments"
remainingPath
access=ReadWrite
access=Access
renderList={() => <Orders />}
renderShow={id => <ShowOrder id />}
/>
Expand All @@ -250,7 +250,7 @@ let make = () => {
<EntityScaffold
entityName="Refunds"
remainingPath
access=ReadWrite
access=Access
renderList={() => <Refund />}
renderShow={id => <ShowRefund id />}
/>
Expand All @@ -259,7 +259,7 @@ let make = () => {
<EntityScaffold
entityName="Disputes"
remainingPath
access=ReadWrite
access=Access
renderList={() => <Disputes />}
renderShow={id => <ShowDisputes id />}
/>
Expand All @@ -268,7 +268,7 @@ let make = () => {
<EntityScaffold
entityName="Customers"
remainingPath
access=ReadWrite
access=Access
renderList={() => <Customers />}
renderShow={id => <ShowCustomers id />}
/>
Expand All @@ -285,7 +285,7 @@ let make = () => {
<EntityScaffold
entityName="UserManagement"
remainingPath
access=ReadWrite
access=Access
renderList={() => <UserRoleEntry />}
renderShow={_ => <UserRoleShowData />}
/>
Expand Down Expand Up @@ -350,7 +350,7 @@ let make = () => {
| list{"quick-start"} => determineQuickStartPageState()
| list{"woocommerce"} => determineWooCommerce()
| list{"stripe-plus-paypal"} => determineStripePlusPayPal()

| list{"unauthorized"} => <UnauthorizedPage />
| _ =>
RescriptReactRouter.replace(`${hyperSwitchFEPrefix}/home`)
<Home />
Expand Down
44 changes: 22 additions & 22 deletions src/entryPoints/hyperswitch/SidebarValues.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ let home = isHomeEnabled =>
name: "Home",
icon: "hswitch-home",
link: "/home",
access: ReadWrite,
access: Access,
})
: emptyComponent

let payments = SubLevelLink({
name: "Payments",
link: `/payments`,
access: ReadWrite,
access: Access,
searchOptions: [("View payment operations", "")],
})

let refunds = SubLevelLink({
name: "Refunds",
link: `/refunds`,
access: ReadWrite,
access: Access,
searchOptions: [("View refund operations", "")],
})

let disputes = SubLevelLink({
name: "Disputes",
link: `/disputes`,
access: ReadWrite,
access: Access,
searchOptions: [("View dispute operations", "")],
})

let customers = SubLevelLink({
name: "Customers",
link: `/customers`,
access: ReadWrite,
access: Access,
searchOptions: [("View customers", "")],
})

Expand All @@ -105,7 +105,7 @@ let connectors = (isConnectorsEnabled, isLiveMode) => {
name: "Processors",
link: `/connectors`,
icon: "connectors",
access: ReadWrite,
access: Access,
searchOptions: HSwitchUtils.getSearchOptionsForProcessors(
~processorList=isLiveMode
? ConnectorUtils.connectorListForLive
Expand All @@ -119,21 +119,21 @@ let connectors = (isConnectorsEnabled, isLiveMode) => {
let paymentAnalytcis = SubLevelLink({
name: "Payments",
link: `/analytics-payments`,
access: ReadWrite,
access: Access,
searchOptions: [("View analytics", "")],
})

let refundAnalytics = SubLevelLink({
name: "Refunds",
link: `/analytics-refunds`,
access: ReadWrite,
access: Access,
searchOptions: [("View analytics", "")],
})

let userJourneyAnalytics = SubLevelLink({
name: "User Journey",
link: `/analytics-user-journey`,
access: ReadWrite,
access: Access,
iconTag: "betaTag",
searchOptions: [("View analytics", "")],
})
Expand All @@ -153,7 +153,7 @@ let analytics = (isAnalyticsEnabled, userJourneyAnalyticsFlag) =>
let routing = SubLevelLink({
name: "Routing",
link: `/routing`,
access: ReadWrite,
access: Access,
searchOptions: [
("Manage default routing configuration", "/default"),
("Create new volume based routing", "/volume"),
Expand All @@ -165,14 +165,14 @@ let routing = SubLevelLink({
let threeDs = SubLevelLink({
name: "3DS Decision Manager",
link: `/3ds`,
access: ReadWrite,
access: Access,
searchOptions: [("Configure 3ds", "")],
})

let surcharge = SubLevelLink({
name: "Surcharge",
link: `/surcharge`,
access: ReadWrite,
access: Access,
searchOptions: [("Add Surcharge", "")],
})

Expand All @@ -189,14 +189,14 @@ let workflow = (isWorkflowEnabled, isSurchargeEnabled) =>
let userManagement = SubLevelLink({
name: "Team",
link: `/users`,
access: ReadWrite,
access: Access,
searchOptions: [("View team management", "")],
})

let accountSettings = SubLevelLink({
name: "Account Settings",
link: `/account-settings`,
access: ReadWrite,
access: Access,
searchOptions: [
("View profile", "/profile"),
("Change password", "/profile"),
Expand All @@ -207,14 +207,14 @@ let accountSettings = SubLevelLink({
let businessDetails = SubLevelLink({
name: "Business Details",
link: `/business-details`,
access: ReadWrite,
access: Access,
searchOptions: [("Configure business details", "")],
})

let businessProfiles = SubLevelLink({
name: "Business Profiles",
link: `/business-profiles`,
access: ReadWrite,
access: Access,
searchOptions: [("Configure business profiles", "")],
})

Expand Down Expand Up @@ -242,22 +242,22 @@ let settings = (~isSampleDataEnabled, ~isUserManagementEnabled, ~isBusinessProfi
let apiKeys = SubLevelLink({
name: "API Keys",
link: `/developer-api-keys`,
access: ReadWrite,
access: Access,
searchOptions: [("View API Keys", "")],
})

let systemMetric = SubLevelLink({
name: "System Metrics",
link: `/developer-system-metrics`,
access: ReadWrite,
access: Access,
iconTag: "betaTag",
searchOptions: [("View System Metrics", "")],
})

let paymentSettings = SubLevelLink({
name: "Payment Settings",
link: `/payment-settings`,
access: ReadWrite,
access: Access,
searchOptions: [("View payment settings", ""), ("View webhooks", ""), ("View return url", "")],
})

Expand All @@ -282,7 +282,7 @@ let fraudAndRisk = isfraudAndRiskEnabled =>
name: "Fraud & Risk",
icon: "shield-alt",
link: `/fraud-risk-management`,
access: isfraudAndRiskEnabled ? ReadWrite : NoAccess,
access: isfraudAndRiskEnabled ? Access : NoAccess,
searchOptions: [],
})
: emptyComponent
Expand All @@ -293,7 +293,7 @@ let payoutConnectors = isPayoutConnectorsEnabled =>
name: "Payout Processors",
link: `/payoutconnectors`,
icon: "connectors",
access: ReadWrite,
access: Access,
searchOptions: HSwitchUtils.getSearchOptionsForProcessors(
~processorList=ConnectorUtils.payoutConnectorList,
~getNameFromString=ConnectorUtils.getConnectorNameString,
Expand All @@ -307,7 +307,7 @@ let reconTag = (recon, isReconEnabled) =>
name: "Reconcilation",
icon: isReconEnabled ? "recon" : "recon-lock",
link: `/recon`,
access: ReadWrite,
access: Access,
})
: emptyComponent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ let getAccessValue = (~permissionValue: permissionType, permissionList) => {
ele === permissionValue
})

isPermissionFound->Option.isSome ? Read : NoAccess
isPermissionFound->Option.isSome ? Access : NoAccess
}
2 changes: 1 addition & 1 deletion src/screens/login/AuthTypes.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
type authorization = NoAccess | Read | ReadWrite
type authorization = NoAccess | Access
Loading