Skip to content
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] Search users by fields defined by admin #7612

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"Accounts_RegistrationForm_SecretURL_Description": "You must provide a random string that will be added to your registration URL. Example: https://demo.rocket.chat/register/[secret_hash]",
"Accounts_RequireNameForSignUp": "Require Name For Signup",
"Accounts_RequirePasswordConfirmation": "Require Password Confirmation",
"Accounts_SearchFields": "Fields to consider in search",
"Accounts_SetDefaultAvatar": "Set Default Avatar",
"Accounts_SetDefaultAvatar_Description": "Tries to determine default avatar based on OAuth Account or Gravatar",
"Accounts_ShowFormLogin": "Show form-based Login",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"Accounts_RegistrationForm_SecretURL_Description": "Você deve fornecer uma seqüência aleatória que será adicionada à sua URL de registro. Exemplo: https://demo.rocket.chat/register/[secret_hash]",
"Accounts_RequireNameForSignUp": "Nome é obrigatório para cadastro",
"Accounts_RequirePasswordConfirmation": "Requer Confirmação de Senha",
"Accounts_SearchFields": "Campos a considerar na busca",
"Accounts_ShowFormLogin": "Mostrar formulário de login",
"Accounts_UseDefaultBlockedDomainsList": "Use Lista Padrão de Domínios Bloqueados",
"Accounts_UseDNSDomainCheck": "Use verificação de Domínio DNS",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"Accounts_RegistrationForm_SecretURL_Description": "Você deve fornecer uma seqüência aleatória que será adicionada à sua URL de registro. Exemplo: https://demo.rocket.chat/register/[secret_hash]",
"Accounts_RequireNameForSignUp": "Nome é obrigatório para cadastro",
"Accounts_RequirePasswordConfirmation": "Requer Confirmação de Senha",
"Accounts_SearchFields": "Campos a considerar na busca",
"Accounts_ShowFormLogin": "Mostrar formulário de login",
"Accounts_UseDefaultBlockedDomainsList": "Use Lista Padrão de Domínios Bloqueados",
"Accounts_UseDNSDomainCheck": "Use verificação de Domínio DNS",
Expand Down
15 changes: 4 additions & 11 deletions packages/rocketchat-lib/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,14 @@ class ModelUsers extends RocketChat.models._Base {
}

const termRegex = new RegExp(s.escapeRegExp(searchTerm), 'i');
const orStmt = _.reduce(_.keys(options.fields), function(acc, el) {
acc.push({ [el]: termRegex }); return acc;
}, []);
const query = {
$and: [
{
active: true,
$or: [
{
username: termRegex
},
{
name: termRegex
},
{
'emails.address': termRegex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened with this field on search?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be added as default in the settings.js. Will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigok I've made a new commit which I think has a better implementation and fix the issue you commented above.

}
]
$or: orStmt
},
{
username: { $exists: true, $nin: exceptions }
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ RocketChat.settings.addGroup('Accounts', function() {
type: 'boolean',
'public': true
});
this.add('Accounts_SearchFields', 'username, name, status', {
type: 'string',
public: true
});

this.section('Registration', function() {
this.add('Accounts_DefaultUsernamePrefixSuggestion', 'user', {
Expand Down
10 changes: 5 additions & 5 deletions server/publications/spotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Meteor.methods({
if (type.users === true && RocketChat.authz.hasPermission(this.userId, 'view-d-room')) {
const userOptions = {
limit: 5,
fields: {
username: 1,
name: 1,
status: 1
},
fields: {},
sort: {}
};

_.map(RocketChat.settings.get('Accounts_SearchFields').trim().split(','), function(field) {
userOptions.fields[field.trim()] = 1;
});

if (RocketChat.settings.get('UI_Use_Real_Name')) {
userOptions.sort.name = 1;
} else {
Expand Down