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

Release 2.3.0 #107

Merged
merged 26 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
d33adbb
add release version
RamRamez Jul 21, 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.

3 changes: 3 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ GIVETH_IO_THIRD_PARTY_MICRO_SERVICE=givethio
GIV_ECONOMY_THIRD_PARTY_SECRET=secret
GIV_ECONOMY_THIRD_PARTY_MICRO_SERVICE=giveconomy-notification-service

NOTIFY_REWARD_THIRD_PARTY_SECRET=secret
NOTIFY_REWARD_THIRD_PARTY_MICRO_SERVICE=notifyreward

# OPTIONAL - force logging to stdout when the value is true
LOG_STDOUT=false

Expand Down
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.GENERAL,
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';`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { MICRO_SERVICES } from '../src/utils/utils';
import { NOTIFICATION_CATEGORY } from '../src/types/general';

export class changeMicroserviceAndCategoryOfNotifyRewardNotificationType1720553769343 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE notification_type
SET "microService" = '${MICRO_SERVICES.notifyReward}',
category = '${NOTIFICATION_CATEGORY.ORTTO}'
WHERE name = 'Notify reward amount';
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE notification_type
SET "microService" = '${MICRO_SERVICES.givethio}',
categoty = '${NOTIFICATION_CATEGORY.GENERAL}'
WHERE name = 'Notify reward amount';
`);
}
}
27 changes: 27 additions & 0 deletions migrations/1720828190666-seedThirdPartyForNotifyReward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class seedThirdPartyForNotifyReward1720828190666 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
) {
// Create third part record for notifyreward in development and test ENVs
await queryRunner.query(`
INSERT INTO third_party(
"microService", secret, "isActive")
VALUES
('notifyreward', 'secret', true)
;
`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DELETE FROM third_party
WHERE "microService" = 'notifyreward';
`);
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification-venter",
"version": "2.2.0",
"version": "2.3.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
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
72 changes: 72 additions & 0 deletions src/routes/v1/notificationRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAccessTokenForMockAuthMicroService,
getGivEconomyBasicAuth,
getGivethIoBasicAuth,
getNotifyRewardBasicAuth,
serverUrl,
sleep,
} from '../../../test/testUtils';
Expand Down Expand Up @@ -2092,6 +2093,77 @@ function sendNotificationTestCases() {
const createdNotification = await findNotificationByTrackId(trackId);
assert.equal(createdNotification?.createdAt.getTime(), creationTime);
});

it('should create *Notify reward amount* notification, success', async () => {
const data = {
eventName: "Notify reward amount",
sendEmail: true,
sendSegment: true,
creationTime: 1667992708000,
email: "[email protected]",
segment: {
payload: {
round: 10,
date: "1667992708000",
amount: "12134",
contractAddress: "0xsfglsjfdflk",
farm: "test farm",
message: "test message",
network: "ethereum",
script: "test script",
transactionHash: "test txhash"
}
}
};

const result = await axios.post(sendNotificationUrl, data, {
headers: {
authorization: getNotifyRewardBasicAuth(),
},
});

assert.equal(result.status, 200);
assert.isOk(result.data);
assert.isTrue(result.data.success);
});
it('should create *Notify reward amount* notification, failed invalid payload', async () => {
try {
const data = {
eventName: "Notify reward amount",
sendEmail: true,
sendSegment: true,
creationTime: 1667992708000,
email: "[email protected]",
segment: {
payload: {
round: 10,
date: "1667992708000",
amount: "12134",
contractAddress: "0xsfglsjfdflk",
farm: "test farm",
message: "test message",
network: "ethereum",
script: "test script",
transactionHash: "test txhash",
invalidField: "invalid data"
}
}
};
await axios.post(sendNotificationUrl, data, {
headers: {
authorization: getNotifyRewardBasicAuth(),
},
});
// If request doesn't fail, it means this test failed
assert.isTrue(false);
} catch (e: any) {
assert.equal(
e.response.data.message,
errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message,
);
assert.equal(e.response.data.description, '"segment.payload.invalidField" is not allowed');
}
});
}

function sendBulkNotificationsTestCases() {
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
Loading
Loading