Skip to content

Commit

Permalink
Merge pull request #75 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release: Updated Alkemio Template
  • Loading branch information
techsmyth authored Dec 16, 2021
2 parents 79c3b5f + c2a302d commit b88b788
Show file tree
Hide file tree
Showing 20 changed files with 268 additions and 73 deletions.
18 changes: 9 additions & 9 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.4.3",
"version": "0.4.4",
"description": "Alkemio notifications service",
"author": "Cherrytwist 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.10.2",
"@alkemio/client-lib": "^0.10.4",
"@nestjs/axios": "^0.0.1",
"@nestjs/common": "^8.0.5",
"@nestjs/config": "^1.0.1",
Expand Down
3 changes: 2 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export class AppController {
this.logger.verbose?.('All messages failed to be sent!');
// if all messages failed to be sent, we reject the message but we make sure the message is
// not discarded so we provide 'true' to requeue parameter
channel.reject(originalMsg, true);
channel.nack(originalMsg, false, false);
// channel.reject(originalMsg, true);
} else {
this.logger.verbose?.(
`${nacked.length} messages out of total ${x.length} messages failed to be sent!`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,24 @@ export class AlkemioClientAdapter implements IFeatureFlagProvider {
uniqueUser => uniqueUser.id === user.id
);
if (!alreadyFound) {
uniqueUsers.push(user);
if (this.isEmailFormat(user.email)) uniqueUsers.push(user);
else {
this.logger.error(
`Unable to obtain a valid email address for "${user.displayName}": "${user.email}" is not a valid email address!
Please check the service account running the notifications service, it must have sufficient permissions to see the user email.`,
LogContext.NOTIFICATIONS
);
}
}
}
return uniqueUsers;
}

private isEmailFormat(value: string): boolean {
const emailRegex = /^\S+@\S+$/;
return emailRegex.test(value);
}

private async tryGetUser(
userID: string,
retry: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ export class AlkemioUrlGenerator {
)?.webclient_endpoint;
}

createHubURL(): string {
return this.webclientEndpoint;
}

createCommunityURL(
hubNameID: string,
challengeNameID?: string,
opportunityNameID?: string
): string {
const baseURL = `${this.webclientEndpoint}/${hubNameID}`;
if (opportunityNameID) {
return `${baseURL}/${challengeNameID}/${opportunityNameID}`;
return `${baseURL}/challenges/${challengeNameID}/opportunities/${opportunityNameID}`;
}
if (challengeNameID) {
return `${baseURL}/${challengeNameID}`;
return `${baseURL}/challenges/${challengeNameID}`;
}
return baseURL;
}
Expand All @@ -38,4 +42,8 @@ export class AlkemioUrlGenerator {
createOrganizationURL(orgNameID: string): string {
return `${this.webclientEndpoint}/organization/${orgNameID}`;
}

createUserNotificationPreferencesURL(userNameID: string): string {
return `${this.webclientEndpoint}/user/${userNameID}/settings/notifications`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export class ApplicationCreatedNotificationBuilder {
eventPayload.hub.challenge?.nameID,
eventPayload.hub.challenge?.opportunity?.nameID
);
const notificationPreferenceURL =
this.alkemioUrlGenerator.createUserNotificationPreferencesURL(
recipient.nameID
);
const hubURL = this.alkemioUrlGenerator.createHubURL();
return {
emailFrom: '[email protected]',
applicant: {
Expand All @@ -173,12 +178,16 @@ export class ApplicationCreatedNotificationBuilder {
recipient: {
name: recipient.displayName,
email: recipient.email,
notificationPreferences: notificationPreferenceURL,
},
community: {
name: eventPayload.community.name,
type: eventPayload.community.type,
url: communityURL,
},
hub: {
url: hubURL,
},
event: eventPayload,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export class CommunicationDiscussionCreatedNotificationBuilder {
eventPayload,
'admin',
EmailTemplate.COMMUNICATION_DISCUSSION_CREATED_ADMIN,
sender
sender,
UserPreferenceType.NotificationCommunicationDiscussionCreatedAdmin
);

const memberNotificationPromises = await this.buildNotificationsForRole(
Expand Down Expand Up @@ -178,6 +179,11 @@ export class CommunicationDiscussionCreatedNotificationBuilder {
eventPayload.hub.challenge?.opportunity?.nameID
);
const senderProfile = this.alkemioUrlGenerator.createUserURL(sender.nameID);
const notificationPreferenceURL =
this.alkemioUrlGenerator.createUserNotificationPreferencesURL(
recipient.nameID
);
const hubURL = this.alkemioUrlGenerator.createHubURL();
return {
emailFrom: '[email protected]',
createdBy: {
Expand All @@ -195,12 +201,16 @@ export class CommunicationDiscussionCreatedNotificationBuilder {
name: recipient.displayName,
firstname: recipient.firstName,
email: recipient.email,
notificationPreferences: notificationPreferenceURL,
},
community: {
name: eventPayload.community.name,
type: eventPayload.community.type,
url: communityURL,
},
hub: {
url: hubURL,
},
event: eventPayload,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export class CommunicationUpdateNotificationBuilder {
eventPayload,
'admin',
EmailTemplate.COMMUNICATION_UPDATE_ADMIN,
sender
sender,
UserPreferenceType.NotificationCommunicationUpdateSentAdmin
);

const memberNotificationPromises = await this.buildNotificationsForRole(
Expand Down Expand Up @@ -176,6 +177,11 @@ export class CommunicationUpdateNotificationBuilder {
eventPayload.hub.challenge?.opportunity?.nameID
);
const senderProfile = this.alkemioUrlGenerator.createUserURL(sender.nameID);
const notificationPreferenceURL =
this.alkemioUrlGenerator.createUserNotificationPreferencesURL(
recipient.nameID
);
const hubURL = this.alkemioUrlGenerator.createHubURL();
return {
emailFrom: '[email protected]',
sender: {
Expand All @@ -191,12 +197,16 @@ export class CommunicationUpdateNotificationBuilder {
name: recipient.displayName,
firstname: recipient.firstName,
email: recipient.email,
notificationPreferences: notificationPreferenceURL,
},
community: {
name: eventPayload.community.name,
type: eventPayload.community.type,
url: communityURL,
},
hub: {
url: hubURL,
},
event: eventPayload,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export class UserRegisteredNotificationBuilder {
const registrantProfileURL = this.alkemioUrlGenerator.createUserURL(
registrant.nameID
);
const notificationPreferenceURL =
this.alkemioUrlGenerator.createUserNotificationPreferencesURL(
recipient.nameID
);
const hubURL = this.alkemioUrlGenerator.createHubURL();
return {
emailFrom: '[email protected]',
registrant: {
Expand All @@ -165,6 +170,10 @@ export class UserRegisteredNotificationBuilder {
name: recipient.displayName,
firstname: recipient.firstName,
email: recipient.email,
notificationPreferences: notificationPreferenceURL,
},
hub: {
url: hubURL,
},
event: eventPayload,
};
Expand Down
Loading

0 comments on commit b88b788

Please sign in to comment.