-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: access to page function and shorts related session (#1335)
- Loading branch information
1 parent
be0cc2e
commit aa92ccb
Showing
6 changed files
with
52 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,38 @@ | ||
import { PartnerAccesses } from '@/lib/store/partnerAccessSlice'; | ||
import { PartnerAdmin } from '@/lib/store/partnerAdminSlice'; | ||
|
||
const hasAccessToPage = ( | ||
export default function hasAccessToPage( | ||
loggedIn: boolean, | ||
availablePreLogin: boolean, | ||
partnersWithAccess: Array<string>, | ||
partnerAccesses: PartnerAccesses, | ||
partnerAdmin: PartnerAdmin, | ||
referralPartner?: string | null, | ||
) => { | ||
// if page is available prelogin | ||
): boolean { | ||
if (!availablePreLogin && !loggedIn) { | ||
return false; | ||
} | ||
|
||
if (availablePreLogin && !loggedIn) { | ||
// if available to bumble and has referal partner in local storage return true | ||
const referralPartnerCapitalized = | ||
referralPartner && referralPartner?.charAt(0).toUpperCase() + referralPartner?.slice(1); | ||
if (referralPartnerCapitalized && partnersWithAccess.includes(referralPartnerCapitalized)) { | ||
return true; | ||
} | ||
// if available to general public and has no referral partner in local storage return true | ||
if (partnersWithAccess.includes('Public') && !referralPartner) { | ||
const isPublicUser = !partnerAccesses.length && !partnerAdmin.id && !referralPartner; | ||
|
||
if (isPublicUser) { | ||
if (partnersWithAccess.includes('Public')) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
if (!availablePreLogin && !loggedIn) { | ||
return false; | ||
} | ||
|
||
const isPublicUser = (partnerAccesses !== null && partnerAccesses.length) === 0; | ||
// determine if public user has access | ||
if (isPublicUser && partnersWithAccess.includes('Public')) { | ||
return true; | ||
if (!loggedIn) { | ||
const referralPartnerCapitalized = | ||
referralPartner && referralPartner?.charAt(0).toUpperCase() + referralPartner?.slice(1); | ||
return !!referralPartnerCapitalized && partnersWithAccess.includes(referralPartnerCapitalized); | ||
} | ||
// determine if partner admin has access | ||
if (partnerAdmin.partner?.name && partnersWithAccess.includes(partnerAdmin.partner?.name)) { | ||
|
||
if (partnerAdmin.partner?.name && partnersWithAccess.includes(partnerAdmin.partner.name)) { | ||
return true; | ||
} | ||
// determine if partner user has access | ||
const isPartnerUserWithAccess = partnerAccesses.reduce<boolean>( | ||
(hasAccessAlready, partnerAccess) => { | ||
if (hasAccessAlready) return hasAccessAlready; | ||
if (partnersWithAccess.includes(partnerAccess.partner.name)) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
false, | ||
); | ||
return isPartnerUserWithAccess; | ||
}; | ||
|
||
export default hasAccessToPage; | ||
return partnerAccesses.some((partnerAccess) => | ||
partnersWithAccess.includes(partnerAccess.partner.name), | ||
); | ||
} |