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

[FIX] Check settings for name requirement before validating #14021

Merged
merged 6 commits into from
Apr 6, 2019
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
11 changes: 7 additions & 4 deletions app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function validateUserData(userId, userData) {
});
}

if (!userData._id && !s.trim(userData.name)) {
if (settings.get('Accounts_RequireNameForSignUp') && !userData._id && !s.trim(userData.name)) {
throw new Meteor.Error('error-the-field-is-required', 'The field Name is required', {
method: 'insertOrUpdateUser',
field: 'Name',
Expand Down Expand Up @@ -171,6 +171,11 @@ export const saveUser = function(userId, userData) {

const _id = Accounts.createUser(createUser);

// set userData.name to empty string to guarantee it's not undefined
if (!userData.name) {
userData.name = '';
Copy link
Member

Choose a reason for hiding this comment

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

Why not? That way if I as admin edit a user that doesn't have a name name === undefined I'll update it to name === '' and all of his subscriptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

and how would you clear the username after it's been set to something?

}

const updateUser = {
$set: {
name: userData.name,
Expand Down Expand Up @@ -236,9 +241,7 @@ export const saveUser = function(userId, userData) {
setUsername(userData._id, userData.username);
}

if (userData.name) {
setRealName(userData._id, userData.name);
}
setRealName(userData._id, userData.name);

if (userData.email) {
const shouldSendVerificationEmailToUser = userData.verified !== true;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/setRealName.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import s from 'underscore.string';

export const _setRealName = function(userId, name) {
name = s.trim(name);
if (!userId || !name) {
if (!userId || (settings.get('Accounts_RequireNameForSignUp') && !name)) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion app/ui-flextab/client/tabs/userEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TAPi18n } from 'meteor/tap:i18n';
import { t, handleError } from '../../../utils';
import { Roles } from '../../../models';
import { hasAtLeastOnePermission } from '../../../authorization';
import { settings } from '../../../settings';
import toastr from 'toastr';
import s from 'underscore.string';

Expand Down Expand Up @@ -136,7 +137,7 @@ Template.userEdit.onCreated(function() {
const userData = this.getUserData();

const errors = [];
if (!userData.name) {
if (settings.get('Accounts_RequireNameForSignUp') && !userData.name) {
errors.push('Name');
}
if (!userData.username) {
Expand Down
Loading