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

[#IP-284] add timestamp check on profile for is_email_enabled #174

Merged

Conversation

AleDore
Copy link
Contributor

@AleDore AleDore commented Jul 2, 2021

List of Changes

  • Add EMAIL_MODE_SWITCH_LIMIT_DATE in config properties
  • GetProfile returns isEmailEnabled set to false if profile timestamp is before a specific limit date (see previous bullet), otherwise return the value stored on cosmosdb
  • Refactor on StoreSpidLogs function for better unit testing

Motivation and Context

We want that a citizen with an old profile, or even a profile that was upserted before the release limit date, has email notification turned off for default

How Has This Been Tested?

It has been tested by performing:

  • yarn lint
  • yarn test

Types of changes

  • Chore (nothing changes by a user perspective)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

@AleDore AleDore changed the title Ip 284 add timestamp check on profile for is email enabled [#IP-284] add timestamp check on profile for is_email_enabled Jul 2, 2021
@pagopa-github-bot
Copy link
Contributor

Warnings
⚠️

Please include a Pivotal story at the beginning of the PR title (see below).

Example of PR titles that include pivotal stories:

  • single story: [#123456] my PR title
  • multiple stories: [#123456,#123457,#123458] my PR title

Generated by 🚫 dangerJS

@@ -21,6 +21,7 @@ import {
} from "@pagopa/ts-commons/lib/responses";
import { FiscalCode } from "@pagopa/ts-commons/lib/strings";

import * as date_fns from "date-fns";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we import only isBefore method?

Suggested change
import * as date_fns from "date-fns";
import { isBefore } from "date-fns";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ee889ae

@@ -76,6 +77,8 @@ export const IConfig = t.intersection([
SPID_LOGS_PUBLIC_KEY: NonEmptyString,
SUBSCRIPTIONS_FEED_TABLE: NonEmptyString,

EMAIL_MODE_SWITCH_LIMIT_DATE: UTCISODateFromString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. Is this variable required for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed with default value in ee889ae

GetProfile/__tests__/handler.test.ts Outdated Show resolved Hide resolved
AleDore and others added 3 commits July 2, 2021 15:26
Co-authored-by: Daniele Manni <BurnedMarshal@users.noreply.github.com>
utils/config.ts Outdated
// No need to re-evaluate this object for each call
const errorOrConfig: t.Validation<IConfig> = IConfig.decode({
...process.env,
EMAIL_MODE_SWITCH_LIMIT_DATE: fromNullableE(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value should be a string because here we apply the decoder IConfig and
UTCISODateFromString requires a string as input.

utils/config.ts Outdated
Comment on lines 101 to 109
EMAIL_MODE_SWITCH_LIMIT_DATE: fromNullableE(
DEFAULT_EMAIL_MODE_SWITCH_LIMIT_DATE
)(process.env.EMAIL_MODE_SWITCH_LIMIT_DATE)
.chain(_ =>
UTCISODateFromString.decode(_).mapLeft(
() => DEFAULT_EMAIL_MODE_SWITCH_LIMIT_DATE
)
)
.fold(_ => new Date(_), identity),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EMAIL_MODE_SWITCH_LIMIT_DATE: fromNullableE(
DEFAULT_EMAIL_MODE_SWITCH_LIMIT_DATE
)(process.env.EMAIL_MODE_SWITCH_LIMIT_DATE)
.chain(_ =>
UTCISODateFromString.decode(_).mapLeft(
() => DEFAULT_EMAIL_MODE_SWITCH_LIMIT_DATE
)
)
.fold(_ => new Date(_), identity),
EMAIL_MODE_SWITCH_LIMIT_DATE: fromNullable(process.env.EMAIL_MODE_SWITCH_LIMIT_DATE)
.getOrElse(DEFAULT_EMAIL_MODE_SWITCH_LIMIT_DATE),

Copy link
Contributor

@BurnedMarshal BurnedMarshal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AleDore AleDore merged commit f6c63d1 into master Jul 2, 2021
@AleDore AleDore deleted the IP-284_add_timestamp_check_on_profile_for_is_email_enabled branch July 2, 2021 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants