Skip to content

Commit

Permalink
allow pre-mod filtering emails during local auth sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Aug 31, 2023
1 parent da1bb5f commit c8fd685
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/core/server/app/handlers/api/auth/local/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
UsernameAlreadyExists,
} from "coral-server/errors";
import { hasEnabledAuthIntegration } from "coral-server/models/tenant";
import { LocalProfile, User } from "coral-server/models/user";
import { LocalProfile, premodUser, User } from "coral-server/models/user";
import { create, usernameAlreadyExists } from "coral-server/services/users";
import { sendConfirmationEmail } from "coral-server/services/users/auth";
import { shouldPremodDueToLikelySpamEmail } from "coral-server/services/users/emailPremodFilter";
import { RequestHandler, TenantCoralRequest } from "coral-server/types/express";

import { GQLUSER_ROLE } from "coral-server/graph/schema/__generated__/types";
Expand Down Expand Up @@ -117,6 +118,10 @@ export const signupHandler = ({
now
);

if (shouldPremodDueToLikelySpamEmail(tenant, user)) {
await premodUser(mongo, tenant.id, user.id);
}

// Send off to the passport handler.
return handleSuccessfulLogin(user, signingConfig, req, res, next);
} catch (err) {
Expand Down
34 changes: 24 additions & 10 deletions src/core/server/services/users/user.emailPremodFilter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
createUserFixture,
} from "coral-server/test/fixtures";

import { GQLFEATURE_FLAG } from "coral-server/graph/schema/__generated__/types";

import {
EMAIL_PREMOD_FILTER_PERIOD_LIMIT,
shouldPremodDueToLikelySpamEmail,
Expand All @@ -14,9 +12,13 @@ const tooManyPeriodsEmail = "[email protected]";
const justEnoughPeriodsEmail = "[email protected]";
const noPeriodsEmail = "[email protected]";

it("does not premod filter emails when feature flag is disabled", () => {
it("does not premod filter emails when feature is disabled", () => {
const tenant = createTenantFixture({
featureFlags: [],
premoderateEmailAddress: {
tooManyPeriods: {
enabled: false,
},
},
});

const user = createUserFixture({
Expand All @@ -27,9 +29,13 @@ it("does not premod filter emails when feature flag is disabled", () => {
expect(!result);
});

it(`does not premod filter emails when feature flag enabled and has less than ${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} periods`, () => {
it(`does not premod filter emails when feature enabled and has less than ${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} periods`, () => {
const tenant = createTenantFixture({
featureFlags: [GQLFEATURE_FLAG.EMAIL_PREMOD_FILTER],
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

const user = createUserFixture({
Expand All @@ -40,9 +46,13 @@ it(`does not premod filter emails when feature flag enabled and has less than ${
expect(result);
});

it(`does not premod filter emails when feature flag enabled and has no periods`, () => {
it(`does not premod filter emails when feature enabled and has no periods`, () => {
const tenant = createTenantFixture({
featureFlags: [GQLFEATURE_FLAG.EMAIL_PREMOD_FILTER],
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

const user = createUserFixture({
Expand All @@ -53,9 +63,13 @@ it(`does not premod filter emails when feature flag enabled and has no periods`,
expect(result);
});

it(`does premod filter emails when feature flag is enabled and has too many (${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} or more) periods`, () => {
it(`does premod filter emails when feature is enabled and has too many (${EMAIL_PREMOD_FILTER_PERIOD_LIMIT} or more) periods`, () => {
const tenant = createTenantFixture({
featureFlags: [GQLFEATURE_FLAG.EMAIL_PREMOD_FILTER],
premoderateEmailAddress: {
tooManyPeriods: {
enabled: true,
},
},
});

const user = createUserFixture({
Expand Down

0 comments on commit c8fd685

Please sign in to comment.