diff --git a/client/modules/accounts/containers/dropdown/mainDropdownContainer.js b/client/modules/accounts/containers/dropdown/mainDropdownContainer.js index 53162617f58..b4a2df611da 100644 --- a/client/modules/accounts/containers/dropdown/mainDropdownContainer.js +++ b/client/modules/accounts/containers/dropdown/mainDropdownContainer.js @@ -67,18 +67,19 @@ class MainDropdownContainer extends Component { } function getCurrentUser() { - if (typeof Reaction === "object") { - const shopId = Reaction.getShopId(); - const user = Accounts.user(); - if (!shopId || typeof user !== "object") return null; - // shoppers should always be guests - const isGuest = Roles.userIsInRole(user, "guest", shopId); - // but if a user has never logged in then they are anonymous - const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId); - - return isGuest && !isAnonymous ? user : null; + const shopId = Reaction.getShopId(); + const user = Accounts.user(); + + if (!shopId || typeof user !== "object") { + return null; } - return null; + + // shoppers should always be guests + const isGuest = Roles.userIsInRole(user, "guest", shopId); + // but if a user has never logged in then they are anonymous + const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId); + + return isGuest && !isAnonymous ? user : null; } function getUserGravatar(currentUser, size) { @@ -88,7 +89,9 @@ function getUserGravatar(currentUser, size) { default: "identicon" }; const user = currentUser || Accounts.user(); - if (!user) return false; + if (!user) { + return false; + } const account = Collections.Accounts.findOne(user._id); // first we check picture exists. Picture has higher priority to display if (account && account.profile && account.profile.picture) { @@ -104,11 +107,14 @@ function displayName(displayUser) { i18nextDep.depend(); const user = displayUser || Accounts.user(); + if (user) { - if (user.profile && user.profile.name) { - return user.profile.name; + if (user.name) { + return user.name; } else if (user.username) { return user.username; + } else if (user.profile && user.profile.name) { + return user.profile.name; } // todo: previous check was user.services !== "anonymous", "resume". Is this diff --git a/client/modules/accounts/helpers/templates.js b/client/modules/accounts/helpers/templates.js index ca4edf48957..47cbb995484 100644 --- a/client/modules/accounts/helpers/templates.js +++ b/client/modules/accounts/helpers/templates.js @@ -28,10 +28,10 @@ Template.registerHelper("getGravatar", function (currentUser, size) { Template.registerHelper("displayName", function (displayUser) { i18nextDep.depend(); - const user = displayUser || Accounts.user(); + const user = displayUser || Collections.Accounts.findOne(Meteor.userId()); if (user) { - if (user.profile && user.profile.name) { - return user.profile.name; + if (user.name) { + return user.name; } else if (user.username) { return user.username; } diff --git a/client/modules/accounts/templates/dashboard/dashboard.js b/client/modules/accounts/templates/dashboard/dashboard.js index 3771052753b..d4dcb9f9fa0 100644 --- a/client/modules/accounts/templates/dashboard/dashboard.js +++ b/client/modules/accounts/templates/dashboard/dashboard.js @@ -2,6 +2,7 @@ import _ from "lodash"; import { Meteor } from "meteor/meteor"; import { Template } from "meteor/templating"; import { Reaction, i18next } from "/client/api"; +import * as Collections from "/lib/collections"; import { ServiceConfigHelper } from "../../helpers/util"; /** @@ -45,6 +46,12 @@ Template.accountsDashboard.helpers({ return shopUsers.map(user => { const member = {}; + // Querying the Accounts collection to retrieve user's name because + // Meteor filters out sensitive info from the Meteor.users schema + const userSub = Meteor.subscribe("UserAccount", user._id); + if (userSub.ready()) { + member.name = Collections.Accounts.findOne(user._id).name; + } member.userId = user._id; if (user.emails && user.emails.length) { diff --git a/lib/collections/schemas/accounts.js b/lib/collections/schemas/accounts.js index cbbd86a4b07..25288392b74 100644 --- a/lib/collections/schemas/accounts.js +++ b/lib/collections/schemas/accounts.js @@ -77,6 +77,10 @@ export const Accounts = new SimpleSchema({ regEx: SimpleSchema.RegEx.Id, index: 1 }, + name: { + type: String, + optional: true + }, emails: { type: [Email], optional: true diff --git a/server/api/core/core.js b/server/api/core/core.js index b2bf80c715e..02e5e845e13 100644 --- a/server/api/core/core.js +++ b/server/api/core/core.js @@ -281,7 +281,8 @@ export default { // defaults use either env or generated options.email = env.REACTION_EMAIL || Random.id(8).toLowerCase() + "@" + domain; - options.username = env.REACTION_USER || "Admin"; // username + options.username = env.REACTION_USER || "admin"; // username + options.name = env.REACTION_USER_NAME || "Admin"; // set admin name options.password = env.REACTION_AUTH || Random.secret(8); // but we can override with provided `meteor --settings` @@ -317,6 +318,14 @@ export default { accountId = Meteor.users.findOne({ "emails.address": options.email })._id; } + if (options.name) { + Meteor.users.update(accountId, { + $set: { + name: options.name + } + }); + } + // // send verification email // diff --git a/server/methods/accounts/accounts.js b/server/methods/accounts/accounts.js index 905b06bbb04..deabdd63f61 100644 --- a/server/methods/accounts/accounts.js +++ b/server/methods/accounts/accounts.js @@ -487,7 +487,7 @@ export function inviteShopMember(shopId, email, name) { if (!user) { const userId = MeteorAccounts.createUser({ email: email, - username: name, + name: name, profile: { invited: true } @@ -503,7 +503,8 @@ export function inviteShopMember(shopId, email, name) { Meteor.users.update(userId, { $set: { - "services.password.reset": { token, email, when: new Date() } + "services.password.reset": { token, email, when: new Date() }, + "name": name } }); diff --git a/server/publications/collections/accounts.js b/server/publications/collections/accounts.js index 4eedc96567c..5e7695f1bc4 100644 --- a/server/publications/collections/accounts.js +++ b/server/publications/collections/accounts.js @@ -84,6 +84,7 @@ Meteor.publish("UserProfile", function (profileUserId) { // no need to normal user so see his password hash const fields = { "emails": 1, + "name": 1, "profile.lang": 1, "profile.firstName": 1, "profile.lastName": 1, diff --git a/server/startup/accounts.js b/server/startup/accounts.js index 7979f86b4c1..3dfbfb7322e 100644 --- a/server/startup/accounts.js +++ b/server/startup/accounts.js @@ -84,6 +84,7 @@ export default function () { const defaultRoles = ["guest", "account/profile", "product", "tag", "index", "cart/checkout", "cart/completed"]; const roles = {}; const additionals = { + name: options && options.name, profile: Object.assign({}, options && options.profile) }; if (!user.emails) user.emails = [];