Skip to content

Commit

Permalink
fix: looser isUserSiteMatch (#4120)
Browse files Browse the repository at this point in the history
* fix: looser isUserSiteMatch

* fix: updated public url matching

* fix: update testing
  • Loading branch information
ColinBuyck authored Jun 13, 2024
1 parent f189e8c commit 986c835
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TWILIO_ACCOUNT_SID=
# account auth token for twilio
TWILIO_AUTH_TOKEN=
# url for the partner front end
PARTNERS_PORTAL_URL=http://localhost:3001/
PARTNERS_PORTAL_URL=http://localhost:3001
# sendgrid email api key
EMAIL_API_KEY=SG.ExampleApiKey
# controls the repetition of the afs cron job
Expand Down
22 changes: 17 additions & 5 deletions api/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,24 @@ export class UserService {
storedUser.userRoles?.isAdmin ||
storedUser.userRoles?.isJurisdictionalAdmin ||
storedUser.userRoles?.isPartner;
const isUserSiteMatch =
(isPartnerPortalUser && dto.appUrl === process.env.PARTNERS_PORTAL_URL) ||
(!isPartnerPortalUser &&
dto.appUrl === storedUser.jurisdictions?.[0]?.publicUrl);
const isUserSiteMatch = async () => {
if (isPartnerPortalUser) {
return dto.appUrl === process.env.PARTNERS_PORTAL_URL;
} else {
//temporary solution since users can currently log into other jurisdictions' public site
const juris = await this.prisma.jurisdictions.findFirst({
select: {
id: true,
},
where: {
publicUrl: dto.appUrl,
},
});
return !!juris;
}
};
// user on wrong site, return neutral message and don't send email
if (!isUserSiteMatch) return { success: true };
if (!(await isUserSiteMatch())) return { success: true };

const payload = {
id: storedUser.id,
Expand Down
4 changes: 4 additions & 0 deletions api/test/unit/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ describe('Testing user service', () => {
id,
resetToken: 'example reset token',
});
prisma.jurisdictions.findFirst = jest.fn().mockResolvedValue({
id,
});
emailService.forgotPassword = jest.fn();

await service.forgotPassword({ email, appUrl: 'http://localhost:3000' });
Expand Down Expand Up @@ -712,6 +715,7 @@ describe('Testing user service', () => {
id,
resetToken: 'example reset token',
});
prisma.jurisdictions.findFirst = jest.fn().mockResolvedValue(null);
emailService.forgotPassword = jest.fn();

await service.forgotPassword({
Expand Down

0 comments on commit 986c835

Please sign in to comment.