Skip to content

Commit 3596043

Browse files
committed
Notify user always when removed, otherwise when indicated
1 parent 7ed48dd commit 3596043

File tree

5 files changed

+39
-29
lines changed

5 files changed

+39
-29
lines changed

apinf_packages/tenant/client/add/add.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ Template.tenantForm.events({
5252
};
5353
return usersRow;
5454
});
55-
// gather list of notified users email addresses
55+
// gather list of notified users' email addresses
5656
notifyUserList = tenantUsers.filter((userdata) => {
57-
// if (userdata.notification === 'checked') {
58-
return {
59-
username: userdata.name,
60-
email: userdata.email,
61-
}
62-
// }
63-
// return false;
57+
if (userdata.notification === 'checked') {
58+
return true;
59+
}
60+
return false;
6461
});
6562
}
6663

@@ -155,12 +152,6 @@ Template.tenantForm.events({
155152
description: $('#add-tenant-description').val(),
156153
};
157154

158-
// Get possible users in changed tenant
159-
if (Session.get('tenantUsers')) {
160-
// Read list of users of the tenant at hand
161-
modifiedTenant.users = Session.get('tenantUsers');
162-
}
163-
164155
// Any changes in name
165156
if (originalTenant.name !== modifiedTenant.name) {
166157
// Fill in tenant id
@@ -204,6 +195,12 @@ Template.tenantForm.events({
204195
-> all is done
205196
*/
206197

198+
// Get possible users in changed tenant
199+
if (Session.get('tenantUsers')) {
200+
// Read list of users of the tenant at hand
201+
modifiedTenant.users = Session.get('tenantUsers');
202+
}
203+
207204
const usersNeedChecking = [];
208205
const notifyChangedUsers = [];
209206
const notifyRemovedUsers = [];
@@ -233,10 +230,10 @@ Template.tenantForm.events({
233230
op: 'remove',
234231
path,
235232
};
236-
// Add user to remove list
233+
// Add remove operation for user to request list
237234
changeList.push(removedUser);
238235

239-
// Add user also to check list
236+
// Add user info also to check list
240237
const checkPath = path.concat('/name');
241238
const checkUser = {
242239
op: 'test',
@@ -246,7 +243,8 @@ Template.tenantForm.events({
246243
// Add user to to-be-checked list
247244
usersNeedChecking.push(checkUser);
248245

249-
// Add user to list for notification about removal
246+
console.log('orig usr to be removed=', origUser);
247+
// Always add user to list for notification about removal
250248
notifyRemovedUsers.push(origUser);
251249

252250
// If user data is modified, set user to be replaced
@@ -286,8 +284,11 @@ Template.tenantForm.events({
286284
// Add user to to-be-checked list
287285
usersNeedChecking.push(checkUser);
288286

289-
// Add user to notification about modification list
290-
notifyChangedUsers.push(sameUserInModified[0]);
287+
// If notification is indicated, add to notify list
288+
if (sameUserInModified[0].notification) {
289+
// Add user to notification about modification list
290+
notifyChangedUsers.push(sameUserInModified[0]);
291+
}
291292

292293
// User data is changed, remove from modified list
293294
modifiedTenant.users.splice(modifiedUserIndex, 1);
@@ -307,8 +308,10 @@ Template.tenantForm.events({
307308

308309
// If there are any modified users left, they are to be added into request
309310
const newUsers = modifiedTenant.users.map((user) => {
310-
// Add user to notification about modification list
311-
notifyChangedUsers.push(user);
311+
if (user.notification === 'checked') {
312+
// Add user to notification about modification list
313+
notifyChangedUsers.push(user);
314+
}
312315

313316
// collect roles
314317
const tenantRoles = [];

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Template.tenantUserForm.events({
3535
provider: false,
3636
consumer: false,
3737
email: thisUser[0].email,
38+
notification: "checked",
3839
};
3940

4041
let tenantUsers = [];

apinf_packages/tenant/client/add/userlist/userlist.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
</label>
2828

2929
<input type="checkbox"
30+
checked={{ notification }}
3031
id="notifyUser"
31-
name=notificationToUser
32+
name=notifyUser
3233
value="notify-user"
3334
class="notificationToUser">
3435
</div>

apinf_packages/tenant/client/add/userlist/userlist.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Template.tenantUsersList.events({
5050

5151
// Save to localStorage to be used while listing users of tenant
5252
Session.set('tenantUsers', tenantUsers);
53+
console.log('tenant users consumer change', tenantUsers);
5354
},
5455
'change .tenantUserRoleProvider': function (event) {
5556
let tenantUsers = [];
@@ -68,23 +69,25 @@ Template.tenantUsersList.events({
6869

6970
// Save to localStorage to be used while listing users of tenant
7071
Session.set('tenantUsers', tenantUsers);
72+
console.log('tenant users provider change', tenantUsers);
7173
},
7274
'change .notificationToUser': function (event) {
7375
let tenantUsers = [];
74-
// Get possible previous users of tenant
76+
// Get list of users of tenant
7577
if (Session.get('tenantUsers')) {
7678
tenantUsers = Session.get('tenantUsers');
7779
}
7880

79-
// update user's role, provider
81+
// update user's notification grant
8082
tenantUsers = tenantUsers.map(user => {
8183
if (user.id === this.id) {
8284
user.notification = event.currentTarget.checked ? 'checked' : false;
8385
}
8486
return user;
8587
});
8688

87-
// Save to localStorage to be used while listing users of tenant
89+
// Save to localStorage to be used while user roles change
8890
Session.set('tenantUsers', tenantUsers);
91+
console.log('tenant users notif change', tenantUsers);
8992
},
9093
});

apinf_packages/tenant/client/remove_tenant/remove_tenant.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ Template.ensureTenantRemovalForm.events({
3939
Meteor.call('deleteTenant', tenantToRemove, (error, result) => {
4040
if (result) {
4141
if (result.status === 204) {
42-
// Tenant successfully removed from manager side, empty local list
43-
const notifyUserList = Session.get('tenantUsers');
42+
// Always notify users when the tenant is removed
43+
const tenantUsers = Session.get('tenantUsers');
44+
4445
// Notification to users of tenant
45-
console.log('Perhaps following users need to be notified about removal=', notifyUserList);
46-
Meteor.call('informTenantUser', notifyUserList, 'userRemoval', tenantToRemove.name, (notifyError, notifyResult) => {
46+
console.log('Perhaps following users need to be notified about removal=', tenantUsers);
47+
Meteor.call('informTenantUser', tenantUsers, 'userRemoval', tenantToRemove.name, (notifyError, notifyResult) => {
4748
if (notifyError) {
4849
sAlert.error('Error in notifying users', { timeout: 'none' });
4950
}
5051
});
5152

53+
// Tenant successfully removed from manager side, empty local list
5254
tenantList = [];
5355
// Save to sessionStorage to be used while adding users to tenant
5456
Session.set('tenantList', tenantList);

0 commit comments

Comments
 (0)