summaryrefslogtreecommitdiffstats
path: root/models/users.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2016-07-18 15:40:41 +0200
committerMaxime Quandalle <maxime@quandalle.com>2016-07-18 15:40:41 +0200
commit4f5cecf738b2bbb9612338737de6172de8874669 (patch)
treec34087b23fe4fcc4d555d0d00775314f18955fb4 /models/users.js
parent855f56c61a39b03442c4962e3afabd80f7fcd721 (diff)
parente521fe617ee923f72d5d6ca27cc03147d353eec4 (diff)
downloadwekan-4f5cecf738b2bbb9612338737de6172de8874669.tar.gz
wekan-4f5cecf738b2bbb9612338737de6172de8874669.tar.bz2
wekan-4f5cecf738b2bbb9612338737de6172de8874669.zip
Merge #616 into devel
Diffstat (limited to 'models/users.js')
-rw-r--r--models/users.js139
1 files changed, 109 insertions, 30 deletions
diff --git a/models/users.js b/models/users.js
index b45dedd2..790ee0a1 100644
--- a/models/users.js
+++ b/models/users.js
@@ -1,5 +1,95 @@
Users = Meteor.users;
+Users.attachSchema(new SimpleSchema({
+ username: {
+ type: String,
+ optional: true,
+ autoValue() { // eslint-disable-line consistent-return
+ if (this.isInsert && !this.isSet) {
+ const name = this.field('profile.fullname');
+ if (name.isSet) {
+ return name.value.toLowerCase().replace(/\s/g, '');
+ }
+ }
+ },
+ },
+ emails: {
+ type: [Object],
+ optional: true,
+ },
+ 'emails.$.address': {
+ type: String,
+ regEx: SimpleSchema.RegEx.Email,
+ },
+ 'emails.$.verified': {
+ type: Boolean,
+ },
+ createdAt: {
+ type: Date,
+ autoValue() { // eslint-disable-line consistent-return
+ if (this.isInsert) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ profile: {
+ type: Object,
+ optional: true,
+ autoValue() { // eslint-disable-line consistent-return
+ if (this.isInsert && !this.isSet) {
+ return {};
+ }
+ },
+ },
+ 'profile.avatarUrl': {
+ type: String,
+ optional: true,
+ },
+ 'profile.emailBuffer': {
+ type: [String],
+ optional: true,
+ },
+ 'profile.fullname': {
+ type: String,
+ optional: true,
+ },
+ 'profile.initials': {
+ type: String,
+ optional: true,
+ },
+ 'profile.invitedBoards': {
+ type: [String],
+ optional: true,
+ },
+ 'profile.language': {
+ type: String,
+ optional: true,
+ },
+ 'profile.notifications': {
+ type: [String],
+ optional: true,
+ },
+ 'profile.starredBoards': {
+ type: [String],
+ optional: true,
+ },
+ 'profile.tags': {
+ type: [String],
+ optional: true,
+ },
+ services: {
+ type: Object,
+ optional: true,
+ blackbox: true,
+ },
+ heartbeat: {
+ type: Date,
+ optional: true,
+ },
+}));
+
// Search a user in the complete server database by its name or username. This
// is used for instance to add a new user to a board.
const searchInFields = ['username', 'profile.fullname'];
@@ -259,14 +349,6 @@ if (Meteor.isServer) {
});
}
-Users.before.insert((userId, doc) => {
- doc.profile = doc.profile || {};
-
- if (!doc.username && doc.profile.fullname) {
- doc.username = doc.profile.fullname.toLowerCase().replace(/\s/g, '');
- }
-});
-
if (Meteor.isServer) {
// Let mongoDB ensure username unicity
Meteor.startup(() => {
@@ -306,32 +388,29 @@ if (Meteor.isServer) {
incrementBoards(_.difference(newIds, oldIds), +1);
});
- // XXX i18n
+ const fakeUserId = new Meteor.EnvironmentVariable();
+ const getUserId = CollectionHooks.getUserId;
+ CollectionHooks.getUserId = () => {
+ return fakeUserId.get() || getUserId();
+ };
+
Users.after.insert((userId, doc) => {
- const ExampleBoard = {
- title: 'Welcome Board',
- userId: doc._id,
- permission: 'private',
+ const fakeUser = {
+ extendAutoValueContext: {
+ userId: doc._id,
+ },
};
- // Insert the Welcome Board
- Boards.insert(ExampleBoard, (err, boardId) => {
-
- ['Basics', 'Advanced'].forEach((title) => {
- const list = {
- title,
- boardId,
- userId: ExampleBoard.userId,
-
- // XXX Not certain this is a bug, but we except these fields get
- // inserted by the Lists.before.insert collection-hook. Since this
- // hook is not called in this case, we have to dublicate the logic and
- // set them here.
- archived: false,
- createdAt: new Date(),
- };
+ fakeUserId.withValue(doc._id, () => {
+ // Insert the Welcome Board
+ Boards.insert({
+ title: TAPi18n.__('welcome-board'),
+ permission: 'private',
+ }, fakeUser, (err, boardId) => {
- Lists.insert(list);
+ ['welcome-list1', 'welcome-list2'].forEach((title) => {
+ Lists.insert({ title: TAPi18n.__(title), boardId }, fakeUser);
+ });
});
});
});