Skip to content

Commit

Permalink
Merge pull request #307 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Added notification for changes in global roles
  • Loading branch information
valentinyanakiev authored May 15, 2024
2 parents e206cb0 + dad60f5 commit cdaf2f9
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 45 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.7.1",
"version": "0.8.2",
"description": "Library for interacting with Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/common/enums/role.change.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// todo: remove once notifications can use the types directly from
export enum RoleChangeType {
ADDED = 'added',
REMOVED = 'removed',
}
1 change: 1 addition & 0 deletions lib/src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './collaboration.post.created.event.payload';
export * from './collaboration.post.comment.event.payload';
export * from './collaboration.callout.published.event.payload';
export * from './collaboration.discussion.comment.event.payload';
export * from './platform.global.role.change.event.payload';
export * from './platform.user.registration.event.payload';
export * from './platform.user.removed.event.payload';
export * from './platform.forum.discussion.comment.event.payload';
Expand Down
11 changes: 11 additions & 0 deletions lib/src/dto/platform.global.role.change.event.payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RoleChangeType } from "@src/common/enums/role.change.type";
import { BaseEventPayload } from "./base.event.payload";
import { ContributorPayload } from "./contributor.payload";

export interface PlatformGlobalRoleChangeEventPayload
extends BaseEventPayload {
type: RoleChangeType;
user: ContributorPayload
role: string;
actor: ContributorPayload;
};
1 change: 1 addition & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './notification.event.type';
export * from './dto';
export * from './common/enums/space.type';
export * from './common/enums/role.change.type';
1 change: 1 addition & 0 deletions lib/src/notification.event.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum NotificationEventType {
COLLABORATION_CALLOUT_PUBLISHED = 'collaborationCalloutPublished',
PLATFORM_USER_REGISTERED = 'platformUserRegistered',
PLATFORM_USER_REMOVED = 'platformUserRemoved',
PLATFORM_GLOBAL_ROLE_CHANGE = 'platformGlobalRoleChange',
PLATFORM_FORUM_DISCUSSION_COMMENT = 'platformForumDiscussionComment',
PLATFORM_FORUM_DISCUSSION_CREATED = 'platformForumDiscussionCreated',
COMMENT_REPLY = 'commentReply',
Expand Down
45 changes: 22 additions & 23 deletions service/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ recipients:
- rule:
type: SPACE_ADMIN
resource_id: <spaceID>
# We don't have SUBSPACE_ADMIN any more. We have SPACE_SUBSPACE_ADMIN, but it's different payload that needs to be provided for this to work (the resource_id should be the parent of the entity).
# toDo - clarify this rule
# - rule:
# type: SUBSPACE_ADMIN
# resource_id: <spaceID>
- rule:
type: SUBSPACE_ADMIN
resource_id: <spaceID>
- rule:
type: GLOBAL_ADMIN_COMMUNITY
type: GLOBAL_COMMUNITY_READ
resource_id:
- rule:
type: GLOBAL_ADMIN
Expand All @@ -112,9 +114,9 @@ recipients:
- rule:
type: SPACE_ADMIN
resource_id: <spaceID>
- rule:
type: SUBSPACE_ADMIN
resource_id: <spaceID>
# - rule:
# type: SUBSPACE_ADMIN
# resource_id: <spaceID>
- name: member
rules:
- rule:
Expand All @@ -140,9 +142,6 @@ recipients:
communication_update_sent:
- name: admin
rules:
- rule:
type: GLOBAL_ADMIN_COMMUNITY
resource_id:
- rule:
type: GLOBAL_ADMIN
resource_id:
Expand Down Expand Up @@ -208,9 +207,9 @@ recipients:
- rule:
type: SPACE_ADMIN
resource_id: <spaceID>
- rule:
type: SUBSPACE_ADMIN
resource_id: <spaceID>
# - rule:
# type: SUBSPACE_ADMIN
# resource_id: <spaceID>
- name: user
rules:
- rule:
Expand All @@ -225,9 +224,9 @@ recipients:
- rule:
type: SPACE_ADMIN
resource_id: <spaceID>
- rule:
type: SUBSPACE_ADMIN
resource_id: <spaceID>
# - rule:
# type: SUBSPACE_ADMIN
# resource_id: <spaceID>
- name: user
rules:
- rule:
Expand Down Expand Up @@ -263,31 +262,31 @@ recipients:
platform_user_registered:
- name: admin
rules:
- rule:
type: GLOBAL_ADMIN_COMMUNITY
resource_id:
- rule:
type: GLOBAL_ADMIN
resource_id:
- rule:
type: GLOBAL_ADMIN_SPACES
type: GLOBAL_SUPPORT
resource_id:
- name: registrant
rules:
- rule:
type: USER_SELF_MANAGEMENT
resource_id: <registrantID>
platform_user_removed:
platform_global_role_change:
- name: admin
rules:
- rule:
type: GLOBAL_ADMIN_COMMUNITY
type: GLOBAL_ADMIN
resource_id:
platform_user_removed:
- name: admin
rules:
- rule:
type: GLOBAL_ADMIN
resource_id:
- rule:
type: GLOBAL_ADMIN_SPACES
type: GLOBAL_SUPPORT
resource_id:
platform_forum_discussion_comment:
- name: discussionCreator
Expand Down
32 changes: 16 additions & 16 deletions service/package-lock.json

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

6 changes: 3 additions & 3 deletions service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-notifications",
"version": "0.16.0",
"version": "0.17.0",
"description": "Alkemio notifications service",
"author": "Alkemio Foundation",
"private": false,
Expand Down Expand Up @@ -35,8 +35,8 @@
"validate-connection": "ts-node src/utils/validate-connection.ts"
},
"dependencies": {
"@alkemio/client-lib": "^0.28.0",
"@alkemio/notifications-lib": "^0.7.1",
"@alkemio/client-lib": "^0.29.4",
"@alkemio/notifications-lib": "^0.8.2",
"@nestjs/common": "^8.0.5",
"@nestjs/config": "^1.0.1",
"@nestjs/core": "^8.0.5",
Expand Down
15 changes: 15 additions & 0 deletions service/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
CommunicationOrganizationMentionEventPayload,
CommunicationUpdateEventPayload,
CommunityNewMemberPayload,
PlatformGlobalRoleChangeEventPayload,
PlatformUserRegistrationEventPayload,
CollaborationCalloutPublishedEventPayload,
BaseEventPayload,
Expand Down Expand Up @@ -109,6 +110,20 @@ export class AppController {
);
}

@EventPattern(NotificationEventType.PLATFORM_GLOBAL_ROLE_CHANGE)
async sendGlobalRoleChangeNotification(
// todo is auto validation possible
@Payload() eventPayload: PlatformGlobalRoleChangeEventPayload,
@Ctx() context: RmqContext
) {
this.sendNotifications(
eventPayload,
context,
this.notificationService.sendGlobalRoleChangeNotification(eventPayload),
NotificationEventType.PLATFORM_GLOBAL_ROLE_CHANGE
);
}

@EventPattern(NotificationEventType.PLATFORM_USER_REGISTERED)
async sendUserRegisteredNotification(
// 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 { CommunityInvitationCreatedNotificationBuilder } from './services/domain
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';
import { AlkemioUrlGeneratorModule } from './services/application/alkemio-url-generator/alkemio.url.generator.module';
import { PlatformGlobalRoleChangeNotificationBuilder } from './services/domain/builders/platform-global-role-change/platform.global.role.change.notification.builder';

@Module({
imports: [
Expand Down Expand Up @@ -66,6 +67,7 @@ import { AlkemioUrlGeneratorModule } from './services/application/alkemio-url-ge
CommunityApplicationCreatedNotificationBuilder,
CommunityInvitationCreatedNotificationBuilder,
CommunityExternalInvitationCreatedNotificationBuilder,
PlatformGlobalRoleChangeNotificationBuilder,
PlatformUserRegisteredNotificationBuilder,
PlatformUserRemovedNotificationBuilder,
PlatformForumDiscussionCommentNotificationBuilder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RoleChangeType } from '@alkemio/notifications-lib';
import { BaseEmailPayload } from './base.email.payload';

export interface PlatformGlobalRoleChangeEmailPayload extends BaseEmailPayload {
user: {
displayName: string;
firstName: string;
email: string;
profile: string;
};
actor: {
displayName: string;
url: string;
};
type: RoleChangeType;
role: string;
triggeredBy: string;
}
1 change: 1 addition & 0 deletions service/src/common/enums/email.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum EmailTemplate {
COLLABORATION_WHITEBOARD_CREATED_MEMBER = 'collaboration.whiteboard.created.member',
COLLABORATION_CALLOUT_PUBLISHED_MEMBER = 'collaboration.callout.published.member',
COLLABORATION_DISCUSSION_COMMENT_MEMBER = 'collaboration.discussion.comment.member',
PLATFORM_GLOBAL_ROLE_CHANGE_ADMIN = 'platform.global.role.change.admin',
PLATFORM_USER_REGISTRATION_REGISTRANT = 'platform.user.registration.registrant',
PLATFORM_USER_REGISTRATION_ADMIN = 'platform.user.registration.admin',
PLATFORM_USER_REMOVED_ADMIN = 'platform.user.removed.admin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type TemplateConfig = {
collaboration_review_submitted?: TemplateRuleSet[];
collaboration_interest?: TemplateRuleSet[];
collaboration_callout_published?: TemplateRuleSet[];
platform_global_role_change?: TemplateRuleSet[];
platform_user_registered?: TemplateRuleSet[];
platform_user_removed?: TemplateRuleSet[];
platform_forum_discussion_comment?: TemplateRuleSet[];
Expand Down
Loading

0 comments on commit cdaf2f9

Please sign in to comment.