Skip to content

Commit 2e8719c

Browse files
committed
Localized notification message
1 parent 2e4ea68 commit 2e8719c

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

apinf_packages/core/lib/i18n/en.i18n.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@
541541
"importOpenApiSpecification_optionText_url": "URL",
542542
"importOpenApiSpecification_optionText_firstOption": "Select lifecycle status",
543543
"importOpenApiSpecificationUploadButton_buttonText_file": "Choose file",
544+
"informTenantUser_emailSubject_tenantAddition": "New tenant added: __tenant__",
545+
"informTenantUser_emailSubject_tenantRemoval": "Tenant __tenant__ removed",
546+
"informTenantUser_emailSubject_userRemoval": "User removed from tenant __tenant__",
547+
"informTenantUser_emailSubject_userRoleChange": "Changes in user roles in tenant __tenant__",
548+
"informTenantUser_emailText_roleInfo": "Current roles: ",
549+
"informTenantUser_emailText_tenantRemoval": "Tenant __tenant__ is removed. One of the users was: ",
550+
"informTenantUser_emailText_userRemoval": "Changes in tenant __tenant__. Removed following user: ",
551+
"informTenantUser_emailText_userRoleChange": "In the tenant __tenant__, there are changes in roles of following user: ",
544552
"invalidApiBasePathMessage": "Must begin and end with /. Allowed alphanumeric characters and -.?$*+'()/:#@!&,;=",
545553
"invalidApiMonitoringEndpointMessage": "Must begin with /. Allowed alphanumeric characters and -.?$*+'()/:#@!&,;=",
546554
"invalidApiRequiredMessage": "Invalid input not allowed",

apinf_packages/tenant/client/add/add.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Template.tenantForm.events({
9393

9494
// Notification to users of tenant
9595
// eslint-disable-next-line max-len
96-
Meteor.call('informTenantUser', notifyUserList, 'userRoleChange', tenant.name, (nofityChangeError) => {
96+
Meteor.call('informTenantUser', notifyUserList, 'tenantAddition', tenant.name, (nofityChangeError) => {
9797
if (nofityChangeError) {
9898
sAlert.error('Error in notifying users', { timeout: 'none' });
9999
}
@@ -105,7 +105,6 @@ Template.tenantForm.events({
105105

106106
// Inform user about success
107107
sAlert.success(message);
108-
109108
} else {
110109
// Operation finished, inform spinner
111110
Session.set('tenantUpdateOngoing', false);

apinf_packages/tenant/client/add/form/form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Template.tenantUserForm.events({
2424
if (userdata.id === userId) {
2525
return {
2626
userdata,
27-
}
27+
};
2828
}
2929
return false;
3030
});
@@ -35,7 +35,7 @@ Template.tenantUserForm.events({
3535
provider: false,
3636
consumer: false,
3737
email: thisUser[0].email,
38-
notification: "checked",
38+
notification: 'checked',
3939
};
4040

4141
let tenantUsers = [];

apinf_packages/tenant/client/remove_tenant/remove_tenant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Template.ensureTenantRemovalForm.events({
4343
const tenantUsers = Session.get('tenantUsers');
4444

4545
// Notification to users of tenant
46-
Meteor.call('informTenantUser', tenantUsers, 'tenantRemoval', tenantToRemove.name, (notifyError, notifyResult) => {
46+
// eslint-disable-next-line max-len
47+
Meteor.call('informTenantUser', tenantUsers, 'tenantRemoval', tenantToRemove.name, (notifyError) => {
4748
if (notifyError) {
4849
sAlert.error('Error in notifying users', { timeout: 'none' });
4950
}

apinf_packages/tenant/server/methods.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ Meteor.methods({
113113

114114
response.status = result.statusCode;
115115
} catch (err) {
116-
117116
// Return error object
118117
let errorMessage = TAPi18n.__('tenantRequest_missingTenantList');
119118
errorMessage = errorMessage.concat(err);
@@ -420,52 +419,64 @@ Meteor.methods({
420419
return response;
421420
},
422421
informTenantUser (userlist, notificationType, tenantName) {
423-
// Check the type of notification
422+
check(userlist, Array);
423+
check(notificationType, String);
424+
check(tenantName, String);
425+
424426
let emailText;
425427
let emailSubject;
428+
// To convey variables to text strings
429+
const params = { tenant: tenantName };
430+
431+
// Check the type of notification
426432
if (notificationType === 'userRoleChange') {
427-
emailSubject = `Changes in user roles in tenant ${tenantName}`;
428-
emailText = `In the tenant ${tenantName} there are changes in roles of following user: `;
433+
emailSubject = TAPi18n.__('informTenantUser_emailSubject_userRoleChange', params);
434+
emailText = TAPi18n.__('informTenantUser_emailText_userRoleChange', params);
429435
} else if (notificationType === 'userRemoval') {
430-
emailSubject = `User removed from tenant ${tenantName}`;
431-
emailText = `Changes in tenant ${tenantName}. Removed following user: `;
436+
emailSubject = TAPi18n.__('informTenantUser_emailSubject_userRemoval', params);
437+
emailText = TAPi18n.__('informTenantUser_emailText_userRemoval', params);
432438
} else if (notificationType === 'tenantRemoval') {
433-
emailSubject = `Tenant ${tenantName} removed`;
434-
emailText = `Tenant ${tenantName} is removed. One of the users was: `;
439+
emailSubject = TAPi18n.__('informTenantUser_emailSubject_tenantRemoval', params);
440+
emailText = TAPi18n.__('informTenantUser_emailText_tenantRemoval', params);
441+
} else if (notificationType === 'tenantAddition') {
442+
emailSubject = TAPi18n.__('informTenantUser_emailSubject_tenantAddition', params);
443+
// Note! Same text as in user role change
444+
emailText = TAPi18n.__('informTenantUser_emailText_userRoleChange', params);
435445
}
436446

437447
// Send notification for each user in list
438448
if (emailText) {
439449
// Get settings
440450
const settings = Settings.findOne();
441451

442-
// Check if email settings are configured
452+
// Email can be sent only when email settings are configured
443453
if (settings.mail && settings.mail.enabled) {
454+
// Send email for each changed user
444455
userlist.forEach(user => {
445456
// Get the email address for user in question
446457
const toUser = completeUserList.find(userData => userData.id === user.id);
447458

448-
// fill notification
459+
// Add user name to notification
449460
let emailTextToSend = emailText.concat(user.name);
450-
console.log('user=', user);
451461

452-
// In case roles were changed, anticipate new roles
453-
if (notificationType === 'userRoleChange') {
454-
emailTextToSend = emailTextToSend.concat('. Current roles: data-consumer');
462+
// In case roles were changed, anticipate new roles. Consumer as default, provider, if indicated.
463+
if (notificationType === 'userRoleChange' || notificationType === 'tenantAddition') {
464+
emailTextToSend = emailTextToSend.concat('. ');
465+
emailTextToSend = emailTextToSend.concat(TAPi18n.__('informTenantUser_emailText_roleInfo'));
466+
emailTextToSend = emailTextToSend.concat(' data-consumer');
455467
if (user.provider) {
456468
emailTextToSend = emailTextToSend.concat(', data-provider.');
457469
}
458470
}
459471

472+
// Fill data to be sent
460473
const emailContent = {
461474
to: toUser.email,
462475
from: settings.mail.fromEmail,
463476
subject: emailSubject,
464477
text: emailTextToSend,
465478
};
466479

467-
console.log('emali lähtee näinikkäästi=', emailContent);
468-
469480
// Send the e-mail
470481
Email.send(emailContent);
471482
});

0 commit comments

Comments
 (0)