Skip to content

Commit

Permalink
Merge pull request #232 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: External invitations notification
  • Loading branch information
valentinyanakiev authored Jul 10, 2023
2 parents c0ba22e + 0f2203f commit 4e97587
Show file tree
Hide file tree
Showing 49 changed files with 431 additions and 153 deletions.
4 changes: 2 additions & 2 deletions lib/package-lock.json

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

2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/notifications-lib",
"version": "0.5.3",
"version": "0.6.0",
"description": "Library for interacting with Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { JourneyBaseEventPayload } from './journey.base.event.payload';
export interface CommunityExternalInvitationCreatedEventPayload
extends JourneyBaseEventPayload {
invitees: {
email: string;
}[];
welcomeMessage?: string;
}
1 change: 1 addition & 0 deletions lib/src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './communication.organization.mention.event.payload';
export * from './community.application.created.event.payload';
export * from './community.new.member.payload';
export * from './community.invitation.created.event.payload';
export * from './community.external.invitation.created.event.payload';
export * from './collaboration.interest.payload';
export * from './collaboration.whiteboard.created.event.payload';
export * from './collaboration.post.created.event.payload';
Expand Down
1 change: 1 addition & 0 deletions lib/src/notification.event.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum NotificationEventType {
COMMUNITY_APPLICATION_CREATED = 'communityApplicationCreated',
COMMUNITY_NEW_MEMBER = 'communityNewMember',
COMMUNITY_INVITATION_CREATED = 'communityInvitationCreated',
COMMUNITY_EXTERNAL_INVITATION_CREATED = 'communityExternalInvitationCreated',
COMMUNICATION_COMMENT_SENT = 'communicationCommentSent',
COMMUNICATION_UPDATE_SENT = 'communicationUpdateSent',
COMMUNICATION_USER_MESSAGE = 'communicationUserMessage',
Expand Down
13 changes: 12 additions & 1 deletion service/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ alkemio:
password: ${SERVICE_ACCOUNT_PASSWORD}:change-me-now

kratos:
public_endpoint: ${KRATOS_API_PUBLIC_ENDPOINT}:http://localhost:3000/identity/ory/kratos/public
public_endpoint: ${KRATOS_API_PUBLIC_ENDPOINT}:http://localhost:3000/ory/kratos/public

recipients:
community_application_created:
Expand Down Expand Up @@ -132,6 +132,17 @@ recipients:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <inviteeID>
community_external_invitation_created:
- name: inviter
rules:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <inviterID>
- name: invitee
rules:
- rule:
type: EXTERNAL_USER
resource_id:
communication_update_sent:
- name: admin
rules:
Expand Down
18 changes: 9 additions & 9 deletions service/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 service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-notifications",
"version": "0.12.0",
"version": "0.13.0",
"description": "Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@alkemio/client-lib": "^0.21.0",
"@alkemio/notifications-lib": "^0.5.3",
"@alkemio/notifications-lib": "^0.6.0",
"@nestjs/common": "^8.0.5",
"@nestjs/config": "^1.0.1",
"@nestjs/core": "^8.0.5",
Expand Down
17 changes: 17 additions & 0 deletions service/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from '@alkemio/notifications-lib';
import { NotificationService } from './services/domain/notification/notification.service';
import { ALKEMIO_CLIENT_ADAPTER, LogContext } from './common/enums';
import { CommunityExternalInvitationCreatedEventPayload } from '@alkemio/notifications-lib';

@Controller()
export class AppController {
Expand Down Expand Up @@ -78,6 +79,22 @@ export class AppController {
);
}

@EventPattern(NotificationEventType.COMMUNITY_EXTERNAL_INVITATION_CREATED)
async sendExternalInvitationNotification(
// todo is auto validation possible
@Payload() eventPayload: CommunityExternalInvitationCreatedEventPayload,
@Ctx() context: RmqContext
) {
this.sendNotifications(
eventPayload,
context,
this.notificationService.sendExternalInvitationCreatedNotifications(
eventPayload
),
NotificationEventType.COMMUNITY_EXTERNAL_INVITATION_CREATED
);
}

@EventPattern(NotificationEventType.COMMUNITY_NEW_MEMBER)
async sendCommunityNewMemberNotification(
// todo is auto validation possible
Expand Down
2 changes: 2 additions & 0 deletions service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { CollaborationWhiteboardCreatedNotificationBuilder } from './services/do
import { CollaborationDiscussionCommentNotificationBuilder } from './services/domain/builders/collaboration-discussion-comment/collaboration.discussion.comment.notification.builder';
import { CommunityInvitationCreatedNotificationBuilder } from './services/domain/builders/community-invitation-created/community.invitation.created.notification.builder';
import { CommentReplyNotificationBuilder } from './services/domain/builders/comment-reply/comment.reply.notification.builder';
import { CommunityExternalInvitationCreatedNotificationBuilder } from './services/domain/builders/community-external-invitation-created/community.external.invitation.created.notification.builder';

@Module({
imports: [
Expand All @@ -64,6 +65,7 @@ import { CommentReplyNotificationBuilder } from './services/domain/builders/comm
NotificationBuilder,
CommunityApplicationCreatedNotificationBuilder,
CommunityInvitationCreatedNotificationBuilder,
CommunityExternalInvitationCreatedNotificationBuilder,
PlatformUserRegisteredNotificationBuilder,
PlatformUserRemovedNotificationBuilder,
PlatformForumDiscussionCommentNotificationBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ export interface CommunicationUserMentionEmailPayload extends BaseEmailPayload {
firstName: string;
};
comment: string;
mentionedUser: {
displayName: string;
firstName: string;
};
commentOrigin: {
url: string;
displayName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BaseJourneyEmailPayload } from './base.journey.email.payload';

export interface CommunityExternalInvitationCreatedEmailPayload
extends BaseJourneyEmailPayload {
inviter: {
name: string;
firstName: string;
email: string;
profile: string;
};
welcomeMessage?: string;
emails?: string;
journeyAdminURL: string;
}
1 change: 1 addition & 0 deletions service/src/common/email-template-payload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './base.email.payload';
export * from './base.journey.email.payload';
export * from './community.application.created.email.payload';
export * from './community.invitation.created.email.payload';
export * from './community.external.invitation.created.email.payload';
export * from './community.new.member.email.payload';
export * from './collaboration.whiteboard.created.email.payload';
export * from './collaboration.post.comment.email.payload';
Expand Down
2 changes: 2 additions & 0 deletions service/src/common/enums/email.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export enum EmailTemplate {
COMMUNITY_INVITATION_ADMIN = 'community.invitation.created.admin',
COMMUNITY_INVITATION_INVITEE = 'community.invitation.created.invitee',
COMMUNITY_INVITATION_INVITER = 'community.invitation.created.inviter',
COMMUNITY_EXTERNAL_INVITATION_INVITEE = 'community.external.invitation.created.invitee',
COMMUNITY_EXTERNAL_INVITATION_INVITER = 'community.external.invitation.created.inviter',
COMMUNICATION_UPDATE_ADMIN = 'communication.update.admin',
COMMUNICATION_UPDATE_MEMBER = 'communication.update.member',
COMMUNICATION_USER_MESSAGE_SENDER = 'communication.user.message.sender',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type TemplateRuleSet = {
export type TemplateConfig = {
community_application_created?: TemplateRuleSet[];
community_invitation_created?: TemplateRuleSet[];
community_external_invitation_created?: TemplateRuleSet[];
community_new_member?: TemplateRuleSet[];
communication_update_sent?: TemplateRuleSet[];
platform_forum_discussion_created?: TemplateRuleSet[];
Expand Down
2 changes: 2 additions & 0 deletions service/src/core/models/credential.criterion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AuthorizationCredential } from '@alkemio/client-lib';

export const ROLE_EXTERNAL_USER = 'EXTERNAL_USER';

export type CredentialCriterion = {
type: AuthorizationCredential;
resourceID?: string;
Expand Down
23 changes: 23 additions & 0 deletions service/src/core/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ export type User = {
};
};

export type InternalUser = {
id: string;
nameID: string;
firstName: string;
lastName: string;
email: string;
preferences?: UserPreference[];
profile: {
id: string;
displayName: string;
};
};

export type ExternalUser = {
firstName: string;
lastName: string;
email: string;
};

export const isUser = (user: User | ExternalUser): user is User => {
return (user as User).nameID !== undefined;
};

export type UserPreference = {
definition: UserPreferenceDefinition;
value: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createOrganizationURL as libCreateOrganizationURL,
createUserNotificationPreferencesURL as libCreateUserNotificationPreferencesURL,
} from '@alkemio/notifications-lib';
import { ExternalUser, User, isUser } from '@src/core/models';

@Injectable()
export class AlkemioUrlGenerator {
Expand Down Expand Up @@ -67,10 +68,12 @@ export class AlkemioUrlGenerator {
return libCreateOrganizationURL(this.webclientEndpoint, orgNameID);
}

createUserNotificationPreferencesURL(userNameID: string): string {
return libCreateUserNotificationPreferencesURL(
this.webclientEndpoint,
userNameID
);
createUserNotificationPreferencesURL(user: User | ExternalUser): string {
return isUser(user)
? libCreateUserNotificationPreferencesURL(
this.webclientEndpoint,
user.nameID
)
: '';
}
}
Loading

0 comments on commit 4e97587

Please sign in to comment.