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

Next release July 2024 #104

Merged
merged 25 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0ddec5c
Create funding.json
divine-comedian Jun 5, 2024
f4beafa
Update LICENSE
divine-comedian Jun 5, 2024
6c5b80a
Add error logs in routers
ae2079 Jun 11, 2024
870e498
Merge pull request #98 from Giveth/1375_improve_log_messages
mohammadranjbarz Jun 12, 2024
200c4f9
Add notify reward amount to notification types
ae2079 Jun 18, 2024
ad698ca
Add notify reward amount notification fields
ae2079 Jun 18, 2024
2596137
Add new migration for notify reward amount notification type
ae2079 Jun 20, 2024
58b204b
do email verification on project verification form through Ortto
RamRamez Jun 24, 2024
3b096fd
User Story - Rejected project owner reason
RamRamez Jun 25, 2024
92571c9
Replace ortto External Embedded Webform for Onboarding guide
RamRamez Jun 26, 2024
cfec49d
Merge pull request #101 from Giveth/do-email-verification-on-project-…
RamRamez Jun 30, 2024
1fda316
Merge branch 'refs/heads/staging' into User-Story---Rejected-project-…
RamRamez Jul 1, 2024
06353a9
Merge pull request #102 from Giveth/User-Story---Rejected-project-own…
RamRamez Jul 1, 2024
9cae75a
Merge pull request #103 from Giveth/Replace-ortto-External-Embedded-W…
RamRamez Jul 1, 2024
347a072
Add notifyRewardAmount validator to SEGMENT_METADATA_SCHEMA_VALIDATOR
ae2079 Jul 1, 2024
834cdf3
Pull staging and resolve conflicts
ae2079 Jul 1, 2024
8087902
Merge pull request #99 from Giveth/4194-sending-email-for-givpower
mohammadranjbarz Jul 2, 2024
1e979b9
add SUBSCRIBE_ONBOARDING
RamRamez Jul 4, 2024
03bb403
Add a unit test for activity creator for notify reward amount notific…
ae2079 Jul 9, 2024
8cdaf7f
Add a migration for change microService name of notify reward amount …
ae2079 Jul 12, 2024
78f0d14
Add missing fields to schema validator
ae2079 Jul 12, 2024
c918439
change notification category to orrto
ae2079 Jul 12, 2024
f3ff7ac
Add migration for adding new third party for notify reward
ae2079 Jul 12, 2024
c3f34ed
Add test cases for notify reward amount notification type to the noti…
ae2079 Jul 13, 2024
259147f
Merge pull request #106 from Giveth/4194-add-unit-test-and-debug
ae2079 Jul 14, 2024
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
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions funding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"opRetro": {
"projectId": "0xe434930e189c807b137ff0d8e2fa6a95eaa57dde574143a02ca0d7fb31a40bea"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';

const NotifyRewardAmountNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
description: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.NOTIFY_REWARD_AMOUNT,
schemaValidator: SCHEMA_VALIDATORS_NAMES.NOTIFY_REWARD_AMOUNT,
title: "Notify reward report",
}
]

export class seedNotificationTypeForNotifyRewardAmount1718888344202 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(NotificationType, NotifyRewardAmountNotificationType);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT};`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NOTIFICATION_CATEGORY } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATIONS_EVENT_NAMES } from '../src/types/notifications';

const EmailConfirmationNotificationType = [
{
name: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
description: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION,
}
]

export class seedNotificationTypeForSendEmailConfirmation1719224595366 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(NotificationType, EmailConfirmationNotificationType);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Send email confirmation';`,
);
}
}
26 changes: 26 additions & 0 deletions migrations/1719410008992-seedNotificationTypeForOnboardingGuide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';

const OnboardingNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
description: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUBSCRIBE_ONBOARDING,
}
]

export class seedNotificationTypeForOnboardingGuide1719410008992 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(NotificationType, OnboardingNotificationType);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Subscribe onboarding';`,
);
}
}
8 changes: 4 additions & 4 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import {
CreateDateColumn,
Entity,
Index,
JoinTable,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
RelationId,
UpdateDateColumn,
} from 'typeorm';
import { NOTIFICATION_CATEGORY } from '../types/general';
import { NotificationSetting } from './notificationSetting';

// Export Object with Schemas to N1 lookup
export const SCHEMA_VALIDATORS_NAMES = {
SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation',
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
SUPERFLUID: 'userSuperTokensCritical',
ADMIN_MESSAGE: 'adminMessage',
RAW_HTML_BROADCAST: 'rawHtmlBroadcast',
Expand Down Expand Up @@ -68,6 +66,8 @@ export const SCHEMA_VALIDATORS_NAMES = {
PROJECT_HAS_A_NEW_RANK: 'projectHasANewRank',
PROJECT_HAS_RISEN_IN_THE_RANK: 'projectHasRisenInTheRank',
YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank',

NOTIFY_REWARD_AMOUNT: 'notifyRewardAmount',
};
export type HtmlTemplate = { type: string; content: string; href?: string }[];

Expand Down
7 changes: 7 additions & 0 deletions src/routes/v1/notificationRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '../../middlewares/authentication';
import { NotificationsController } from '../../controllers/v1/notificationsController';
import { sendStandardResponse } from '../../utils/responseUtils';
import { logger } from '../../utils/logger';
import { createNewUserAddressIfNotExists } from '../../repositories/userAddressRepository';

export const notificationRouter = express.Router();
Expand All @@ -22,6 +23,7 @@ notificationRouter.post(
});
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/thirdParty/notifications error', e);
next(e);
}
},
Expand All @@ -41,6 +43,7 @@ notificationRouter.post(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/thirdParty/notificationsBulk error', e);
next(e);
}
},
Expand All @@ -65,6 +68,7 @@ notificationRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications error', e);
next(e);
}
},
Expand All @@ -85,6 +89,7 @@ notificationRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/read/:notificationId error', e);
next(e);
}
},
Expand All @@ -100,6 +105,7 @@ notificationRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/countUnread/:walletAddress error', e);
next(e);
}
},
Expand All @@ -120,6 +126,7 @@ notificationRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notifications/readAll error', e);
next(e);
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/routes/v1/notificationSettingsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Request, Response } from 'express';
import { validateAuthMicroserviceJwt } from '../../middlewares/authentication';
import { NotificationSettingsController } from '../../controllers/v1/notificationSettingsController';
import { sendStandardResponse } from '../../utils/responseUtils';
import { logger } from '../../utils/logger';

export const notificationSettingsRouter = express.Router();

Expand All @@ -25,6 +26,7 @@ notificationSettingsRouter.get(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('get /notification_settings error', e);
next(e);
}
},
Expand All @@ -47,6 +49,7 @@ notificationSettingsRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('/notification_settings/:id error', e);
next(e);
}
},
Expand All @@ -68,6 +71,7 @@ notificationSettingsRouter.put(
);
return sendStandardResponse({ res, result });
} catch (e) {
logger.error('put /notification_settings error', e);
next(e);
}
},
Expand Down
42 changes: 31 additions & 11 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { getEmailAdapter } from '../adapters/adapterFactory';
import { NOTIFICATION_CATEGORY } from '../types/general';

const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES) : any=> {
const fields = {
"str::email": payload.email,
}
if (process.env.ENVIRONMENT === 'production') {
fields['str:cm:user-id'] = payload.userId?.toString()
}
let attributes;
switch (orttoEventName) {
case NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION:
attributes = {
"str:cm:email": payload.email,
"str:cm:verificationlink": payload.verificationLink,
}
break;
case NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE:
attributes = {
"str:cm:email": payload.email,
Expand Down Expand Up @@ -126,6 +126,7 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'rejected',
"txt:cm:reason": payload.verificationRejectedReason,
"str:cm:userid": payload.userId?.toString(),
};
break
Expand Down Expand Up @@ -163,6 +164,19 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
"str:cm:userid": payload.userId?.toString(),
}
break
case NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT:
attributes = {
"int:cm:round": payload.round,
"str:cm:date": payload.date,
"str:cm:amount": payload.amount,
"str:cm:contractaddress": payload.contractAddress,
"str:cm:farm": payload.farm,
"str:cm:message": payload.message,
"str:cm:network": payload.network,
"str:cm:script": payload.script,
"str:cm:transactionhash": payload.transactionHash,
}
break
default:
logger.debug('activityCreator() invalid event name', orttoEventName)
return;
Expand All @@ -171,8 +185,12 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
logger.debug('activityCreator() invalid ORTTO_EVENT_NAMES', orttoEventName)
return;
}
const fields = {
"str::email": payload.email,
}
const merge_by = [];
if (process.env.ENVIRONMENT === 'production') {
if (process.env.ENVIRONMENT === 'production' && orttoEventName !== NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION) {
fields['str:cm:user-id'] = payload.userId?.toString()
merge_by.push("str:cm:user-id")
} else {
merge_by.push("str::email")
Expand Down Expand Up @@ -204,9 +222,7 @@ export const sendNotification = async (
message: errorMessages.DUPLICATED_TRACK_ID,
};
}
const userAddress = await createNewUserAddressIfNotExists(
userWalletAddress as string,
);

const notificationType = await getNotificationTypeByEventNameAndMicroservice({
eventName: body.eventName,
microService,
Expand All @@ -221,10 +237,14 @@ export const sendNotification = async (

const isOrttoSpecific = notificationType.category === NOTIFICATION_CATEGORY.ORTTO

const userAddress = isOrttoSpecific ? undefined : await createNewUserAddressIfNotExists(
userWalletAddress as string,
);

const notificationSetting = isOrttoSpecific ? null :
await findNotificationSettingByNotificationTypeAndUserAddress({
notificationTypeId: notificationType.id,
userAddressId: userAddress.id,
userAddressId: userAddress?.id as number
});

const shouldSendEmail =
Expand Down
6 changes: 5 additions & 1 deletion src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export enum NOTIFICATION_CATEGORY {
GIV_ECONOMY = 'givEconomy',
SUPPORTED_PROJECTS = 'supportedProjects',
GIV_POWER = 'givPower',
ORTTO = 'ortto'
ORTTO = 'ortto',
NOTIFY_REWARD_AMOUNT = 'notifyRewardAmount',
}

export enum NOTIFICATION_TYPE_NAMES {
Expand Down Expand Up @@ -51,5 +52,8 @@ export enum NOTIFICATION_TYPE_NAMES {
PROJECT_HAS_A_NEW_RANK = 'Your project has a new rank',
PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank',
YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank',
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',

NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
}
7 changes: 6 additions & 1 deletion src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export enum NOTIFICATIONS_EVENT_NAMES {
SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance',
SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',
SEND_EMAIL_CONFIRMATION = 'Send email confirmation',

NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
}

export const ORTTO_EVENT_NAMES = {
Expand All @@ -66,5 +69,7 @@ export const ORTTO_EVENT_NAMES = {
[NOTIFICATIONS_EVENT_NAMES.VERIFICATION_FORM_REJECTED]: 'project-verification',
[NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING]: 'first-update-warning',
[NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning',
[NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile'
[NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile',
[NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION]: 'verification-form-email-verification',
[NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount'
}
Loading
Loading