forked from vegeta999/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetUserActiveStatus.js
More file actions
66 lines (51 loc) · 1.69 KB
/
Copy pathsetUserActiveStatus.js
File metadata and controls
66 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Accounts } from 'meteor/accounts-base';
import * as Mailer from '../../app/mailer';
import { hasPermission } from '../../app/authorization';
import { Users, Subscriptions } from '../../app/models';
import { settings } from '../../app/settings';
Meteor.methods({
setUserActiveStatus(userId, active) {
check(userId, String);
check(active, Boolean);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'setUserActiveStatus',
});
}
if (hasPermission(Meteor.userId(), 'edit-other-user-active-status') !== true) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'setUserActiveStatus',
});
}
const user = Users.findOneById(userId);
if (!user) {
return false;
}
Users.setUserActive(userId, active);
if (user.username) {
Subscriptions.setArchivedByUsername(user.username, !active);
}
if (active === false) {
Users.unsetLoginTokens(userId);
} else {
Users.unsetReason(userId);
}
if (active && !settings.get('Accounts_Send_Email_When_Activating')) {
return true;
}
if (!active && !settings.get('Accounts_Send_Email_When_Deactivating')) {
return true;
}
const destinations = Array.isArray(user.emails) && user.emails.map((email) => `${ user.name || user.username }<${ email.address }>`);
const email = {
to: destinations,
from: settings.get('From_Email'),
subject: Accounts.emailTemplates.userActivated.subject({ active }),
html: Accounts.emailTemplates.userActivated.html({ active, name: user.name, username: user.username }),
};
Mailer.sendNoWrap(email);
return true;
},
});