Skip to content

Commit

Permalink
Merge pull request #110 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Two new notifications
  • Loading branch information
hero101 authored Apr 21, 2022
2 parents be0df34 + d5c3c5e commit 288a714
Show file tree
Hide file tree
Showing 24 changed files with 257 additions and 38 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-deploy-k8s-dev-aws.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Build & Deploy to Dev on AWS

on:
push:
branches: [develop]
workflow_dispatch:

env:
ECR_REGISTRY: ${{ secrets.ECR_DEV_TEST_REGISTRY }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/build-deploy-k8s-dev-azure.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Build & Deploy to Dev

on:
workflow_dispatch:
push:
branches: [develop]

jobs:
build-and-deploy:
Expand All @@ -14,7 +15,7 @@ jobs:
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
creds: ${{ secrets.AZURE_CRED_K8S_NEW }}

- name: 'Build and push image'
uses: azure/docker-login@v1
Expand All @@ -28,7 +29,7 @@ jobs:
- uses: Azure/aks-set-context@v1
with:
creds: ${{ secrets.AZURE_CRED_K8S }}
creds: ${{ secrets.AZURE_CRED_K8S_NEW }}
cluster-name: ${{ secrets.CLUSTER_NAME }}
resource-group: ${{ secrets.RESOURCE_GROUP_K8S }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-deploy-k8s-test-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
creds: ${{ secrets.AZURE_CRED_K8S_NEW }}

- name: 'Build and push image'
uses: azure/docker-login@v1
Expand All @@ -27,7 +27,7 @@ jobs:
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/alkemio-notifications:${{ github.sha }}
- uses: Azure/aks-set-context@v1
with:
creds: ${{ secrets.AZURE_CRED_K8S }}
creds: ${{ secrets.AZURE_CRED_K8S_NEW }}
cluster-name: k8s-test
resource-group: res-grp-k8s-test

Expand Down
2 changes: 1 addition & 1 deletion manifests/25-notifications-deployment-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: alkemio-notifications
image: ctdev.azurecr.io/alkemio-notifications:latest
image: alkemio.azurecr.io/alkemio-notifications:latest
env:
- name: RABBITMQ_HOST
valueFrom:
Expand Down
17 changes: 17 additions & 0 deletions notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,20 @@ recipients:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <reviewerID>
community_new_member:
- name: admin
rules:
- rule:
type: HUB_ADMIN
resource_id: <hubID>
- rule:
type: CHALLENGE_ADMIN
resource_id: <challengeID>
- rule:
type: OPPORTUNITY_ADMIN
resource_id: <opportunityID>
- name: member
rules:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <memberID>
37 changes: 16 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-notifications",
"version": "0.5.3",
"version": "0.5.4",
"description": "Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down Expand Up @@ -34,7 +34,7 @@
"validate-connection": "ts-node src/utils/validate-connection.ts"
},
"dependencies": {
"@alkemio/client-lib": "^0.13.1",
"@alkemio/client-lib": "^0.13.2",
"@nestjs/axios": "^0.0.1",
"@nestjs/common": "^8.0.5",
"@nestjs/config": "^1.0.1",
Expand Down
19 changes: 19 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
COMMUNICATION_UPDATE_SENT,
COMMUNITY_APPLICATION_CREATED,
COMMUNITY_CONTEXT_REVIEW_SUBMITTED,
COMMUNITY_NEW_MEMBER,
LogContext,
USER_REGISTERED,
} from './common';
Expand All @@ -19,6 +20,7 @@ import {
CommunicationDiscussionCreatedEventPayload,
CommunityContextReviewSubmittedPayload,
UserRegistrationEventPayload,
CommunityNewMemberPayload,
} from '@common/dto';
import { NotificationService } from './services/domain/notification/notification.service';

Expand Down Expand Up @@ -47,6 +49,23 @@ export class AppController {
COMMUNITY_APPLICATION_CREATED
);
}

@EventPattern(COMMUNITY_NEW_MEMBER)
async sendCommunityNewMemberNotification(
// todo is auto validation possible
@Payload() eventPayload: CommunityNewMemberPayload,
@Ctx() context: RmqContext
) {
this.sendNotifications(
eventPayload,
context,
this.notificationService.sendCommunityNewMemberNotifications(
eventPayload
),
COMMUNITY_NEW_MEMBER
);
}

@EventPattern(USER_REGISTERED)
async sendUserRegisteredNotification(
// todo is auto validation possible
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CommunicationUpdateNotificationBuilder,
CommunityContextReviewSubmittedNotificationBuilder,
UserRegisteredNotificationBuilder,
CommunityNewMemberNotificationBuilder,
} from './services/domain/builders';
import { AlkemioUrlGeneratorModule } from './services/application/alkemio-url-generator';
import { NotificationService } from './services/domain/notification/notification.service';
Expand Down Expand Up @@ -49,6 +50,7 @@ import { NotificationBuilderFactoryProvider } from './services/application/notif
CommunicationUpdateNotificationBuilder,
CommunicationDiscussionCreatedNotificationBuilder,
CommunityContextReviewSubmittedNotificationBuilder,
CommunityNewMemberNotificationBuilder,
NotificationService,
],
controllers: [AppController],
Expand Down
1 change: 1 addition & 0 deletions src/common/constants/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const COMMUNITY_APPLICATION_CREATED = 'communityApplicationCreated';
export const COMMUNITY_NEW_MEMBER = 'communityNewMember';
export const USER_REGISTERED = 'userRegistered';
export const COMMUNICATION_UPDATE_SENT = 'communicationUpdateSent';
export const COMMUNICATION_DISCUSSION_CREATED =
Expand Down
11 changes: 11 additions & 0 deletions src/common/dto/community.new.member.payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HubPayload } from './hub.payload';
import { CommunityType } from './application.created.event.payload';

export type CommunityNewMemberPayload = {
userID: string;
community: {
name: string;
type: CommunityType;
};
hub: HubPayload;
};
1 change: 1 addition & 0 deletions src/common/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './application.created.event.payload';
export * from './communication.discussion.created.event.payload';
export * from './communication.update.event.payload';
export * from './community.context.review.submitted.payload';
export * from './community.new.member.payload';
export * from './user.registration.event.payload';
export * from './hub.payload';
1 change: 1 addition & 0 deletions src/common/enums/alkemio.error.status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export enum AlkemioErrorStatus {
TEMPLATE_BUILDER_NOT_PROVIDED = 'TEMPLATE_BUILDER_NOT_PROVIDED',
ROLES_NOT_PROVIDED = 'ROLES_NOT_PROVIDED',
RULES_SET_NOT_FOUND = 'RULE_SET_NOT_FOUND',
NOTIFICATION_NO_CHANNELS = 'NOTIFICATION_NO_CHANNELS',
}
2 changes: 2 additions & 0 deletions src/common/enums/email.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export enum EmailTemplate {
COMMUNICATION_UPDATE_MEMBER = 'communication.update.member',
COMMUNITY_REVIEW_SUBMITTED_ADMIN = 'community.review.submitted.admin',
COMMUNITY_REVIEW_SUBMITTED_REVIEWER = 'community.review.submitted.reviewer',
COMMUNITY_NEW_MEMBER_ADMIN = 'community.new.member.admin',
COMMUNITY_NEW_MEMBER_MEMBER = 'community.new.member.member',
}
1 change: 1 addition & 0 deletions src/common/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './not.supported.exception';
export * from './base.exception';
export * from './notification-builder';
export * from './notification.no.channels.exception';
8 changes: 8 additions & 0 deletions src/common/exceptions/notification.no.channels.exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LogContext, AlkemioErrorStatus } from '@common/enums';
import { BaseException } from './base.exception';

export class NotificationNoChannelsException extends BaseException {
constructor(error: string, context = LogContext.NOTIFICATIONS) {
super(error, context, AlkemioErrorStatus.NOTIFICATION_NO_CHANNELS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type TemplateConfig = {
communication_update_sent?: TemplateRuleSet[];
communication_discussion_created?: TemplateRuleSet[];
community_review_submitted?: TemplateRuleSet[];
community_new_member?: TemplateRuleSet[];
};

export interface INotificationRecipientTemplateProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class NotificationBuilder<TPayload = Record<string, unknown>> {

if (!recipients.length) {
const criteriaText = credentialCriteria
.map(x => `<${x.type},${x.resourceID}`)
.map(x => `<${x.type},${x.resourceID}>`)
.join(' OR ');
this.logger.verbose?.(
`Unable to find recipients matching ${criteriaText}`,
Expand All @@ -205,6 +205,11 @@ export class NotificationBuilder<TPayload = Record<string, unknown>> {
return [];
}

this.logger.verbose?.(
`Identified ${recipients.length} recipients to be filtered by preferences`,
LogContext.NOTIFICATIONS
);

const filteredRecipients: User[] = [];

if (!extra?.rolePreferenceType) {
Expand All @@ -220,6 +225,11 @@ export class NotificationBuilder<TPayload = Record<string, unknown>> {
)
) {
filteredRecipients.push(recipient);
} else {
this.logger.verbose?.(
`User ${recipient.displayName} filtered out because of ${extra?.rolePreferenceType}`,
LogContext.NOTIFICATIONS
);
}
}
}
Expand Down
Loading

0 comments on commit 288a714

Please sign in to comment.