-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] Alert admins when user requires approval & alert users when the account is approved/activated/deactivated #7098
Changes from 24 commits
d4495b3
0255a9e
b90b3b7
7a93379
a877603
21dcb15
8701eb0
7f5e498
c92d2b0
eae8aa3
16a58b5
3925e89
f001a4c
21c6c73
fad9497
17ad773
db7d777
0f99622
e6fff42
12988c4
3cf721f
7538f00
e7cd5eb
777441e
c0edb09
c041848
206c868
72d8335
1482536
1ebd371
073dd0b
42201cf
4952eb1
b9f983a
dbcba56
b10b887
4248273
87b51d0
195d56b
24f0618
f9d7363
a54af9b
e04387a
920f928
6069e02
26c255e
23219cd
dfff89e
128116d
645943a
d5f141b
c639292
1b564f4
244cb4c
2a8d479
a9b004c
b2d99d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Meteor.methods({ | ||
unsetUserReason(userId) { | ||
Meteor.users.update(userId, { $unset: { 'reason' : 1 } }); | ||
return true; | ||
} | ||
}); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ class ModelUsers extends RocketChat.models._Base { | |
this.tryEnsureIndex({ 'active': 1 }, { sparse: 1 }); | ||
this.tryEnsureIndex({ 'statusConnection': 1 }, { sparse: 1 }); | ||
this.tryEnsureIndex({ 'type': 1 }); | ||
this.tryEnsureIndex({ 'reason': 1 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really need this index? I don't think we'll be doing any query/sorting using reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, just forgot it there. Removing |
||
|
||
this.cache.ensureIndex('username', 'unique'); | ||
} | ||
|
@@ -493,6 +494,26 @@ class ModelUsers extends RocketChat.models._Base { | |
return this.update({ _id }, update); | ||
} | ||
|
||
setReason(_id, reason) { | ||
const update = { | ||
$set: { | ||
reason | ||
} | ||
}; | ||
|
||
return this.update(_id, update); | ||
} | ||
|
||
unsetReason(_id) { | ||
const update = { | ||
$unset: { | ||
'reason' : true | ||
} | ||
}; | ||
|
||
return this.update(_id, update); | ||
} | ||
|
||
// INSERT | ||
create(data) { | ||
const user = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ Accounts.emailTemplates.siteName = RocketChat.settings.get('Site_Name'); | |
|
||
Accounts.emailTemplates.from = `${ RocketChat.settings.get('Site_Name') } <${ RocketChat.settings.get('From_Email') }>`; | ||
|
||
Accounts.emailTemplates.notifyAdmin = {}; | ||
|
||
const verifyEmailHtml = Accounts.emailTemplates.verifyEmail.text; | ||
|
||
Accounts.emailTemplates.verifyEmail.html = function(user, url) { | ||
|
@@ -56,6 +58,31 @@ Accounts.emailTemplates.enrollAccount.html = function(user = {}/*, url*/) { | |
return header + html + footer; | ||
}; | ||
|
||
Accounts.emailTemplates.notifyAdmin.subject = function() { | ||
const subject = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Subject_Default'); | ||
const siteName = RocketChat.settings.get('Site_Name'); | ||
|
||
return `[${ siteName }] ${ subject }`; | ||
}; | ||
|
||
Accounts.emailTemplates.notifyAdmin.html = function(options = {}) { | ||
|
||
let html; | ||
|
||
html = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Default'); | ||
|
||
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || ''); | ||
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || ''); | ||
|
||
html = RocketChat.placeholders.replace(html, { | ||
name: options.name, | ||
email: options.email, | ||
reason: options.reason | ||
}); | ||
|
||
return header + html + footer; | ||
}; | ||
|
||
Accounts.onCreateUser(function(options, user = {}) { | ||
RocketChat.callbacks.run('beforeCreateUser', options, user); | ||
|
||
|
@@ -91,6 +118,27 @@ Accounts.onCreateUser(function(options, user = {}) { | |
} | ||
} | ||
|
||
if (!user.active) { | ||
user.emails.some((email) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea, was just folowing an example from another file sending email. Fixing |
||
const destinations = []; | ||
|
||
RocketChat.models.Roles.findUsersInRole('admin').forEach(function(adminUser) { | ||
destinations.push(`${ adminUser.name }<${ adminUser.emails[0].address }>`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible that an adminUser doesn't have e-mail on |
||
}); | ||
|
||
email = { | ||
to: destinations, | ||
from: RocketChat.settings.get('From_Email'), | ||
subject: Accounts.emailTemplates.notifyAdmin.subject(), | ||
html: Accounts.emailTemplates.notifyAdmin.html(options) | ||
}; | ||
|
||
Meteor.defer(() => { | ||
Email.send(email); | ||
}); | ||
}); | ||
} | ||
|
||
return user; | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Meteor.methods({ | ||
unsetUserReason(userId) { | ||
check(userId, String); | ||
|
||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { | ||
method: 'unsetUserReason' | ||
}); | ||
} | ||
|
||
if (RocketChat.authz.hasPermission(Meteor.userId(), 'edit-other-user-active-status') !== true) { | ||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { | ||
method: 'unsetUserReason' | ||
}); | ||
} | ||
|
||
const user = RocketChat.models.Users.findOneById(userId); | ||
|
||
if (user) { | ||
RocketChat.models.Users.unsetReason(userId); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise on client side, this method should not exist and its content should be executed inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import loginPage from '../../pageobjects/login.page'; | |
import mainContent from '../../pageobjects/main-content.page'; | ||
|
||
//test data imports | ||
import {username, email, password} from '../../data/user.js'; | ||
import {username, email, password, reason} from '../../data/user.js'; | ||
|
||
|
||
|
||
|
@@ -22,7 +22,7 @@ describe('[User Creation]', function() { | |
it('it should create user', () => { | ||
loginPage.gotToRegister(); | ||
|
||
loginPage.registerNewUser({username, email, password}); | ||
loginPage.registerNewUser({username, email, password, reason}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the reason only shows up when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @MartinSchoeler. I was looking for this |
||
|
||
loginPage.inputUsername.waitForExist(5000); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method shouldn't exist. First, it is not checking for user permission to unset reason, and second you could unset reason in the same method
setUserActiveStatus
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed