@@ -113,7 +113,6 @@ Meteor.methods({
113
113
114
114
response . status = result . statusCode ;
115
115
} catch ( err ) {
116
-
117
116
// Return error object
118
117
let errorMessage = TAPi18n . __ ( 'tenantRequest_missingTenantList' ) ;
119
118
errorMessage = errorMessage . concat ( err ) ;
@@ -420,52 +419,64 @@ Meteor.methods({
420
419
return response ;
421
420
} ,
422
421
informTenantUser ( userlist , notificationType , tenantName ) {
423
- // Check the type of notification
422
+ check ( userlist , Array ) ;
423
+ check ( notificationType , String ) ;
424
+ check ( tenantName , String ) ;
425
+
424
426
let emailText ;
425
427
let emailSubject ;
428
+ // To convey variables to text strings
429
+ const params = { tenant : tenantName } ;
430
+
431
+ // Check the type of notification
426
432
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 ) ;
429
435
} 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 ) ;
432
438
} 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 ) ;
435
445
}
436
446
437
447
// Send notification for each user in list
438
448
if ( emailText ) {
439
449
// Get settings
440
450
const settings = Settings . findOne ( ) ;
441
451
442
- // Check if email settings are configured
452
+ // Email can be sent only when email settings are configured
443
453
if ( settings . mail && settings . mail . enabled ) {
454
+ // Send email for each changed user
444
455
userlist . forEach ( user => {
445
456
// Get the email address for user in question
446
457
const toUser = completeUserList . find ( userData => userData . id === user . id ) ;
447
458
448
- // fill notification
459
+ // Add user name to notification
449
460
let emailTextToSend = emailText . concat ( user . name ) ;
450
- console . log ( 'user=' , user ) ;
451
461
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' ) ;
455
467
if ( user . provider ) {
456
468
emailTextToSend = emailTextToSend . concat ( ', data-provider.' ) ;
457
469
}
458
470
}
459
471
472
+ // Fill data to be sent
460
473
const emailContent = {
461
474
to : toUser . email ,
462
475
from : settings . mail . fromEmail ,
463
476
subject : emailSubject ,
464
477
text : emailTextToSend ,
465
478
} ;
466
479
467
- console . log ( 'emali lähtee näinikkäästi=' , emailContent ) ;
468
-
469
480
// Send the e-mail
470
481
Email . send ( emailContent ) ;
471
482
} ) ;
0 commit comments