2016-12-21 12:04:43 +01:00
|
|
|
import Users from './collection.js';
|
|
|
|
|
2016-06-23 15:00:58 +09:00
|
|
|
const adminGroup = {
|
|
|
|
name: "admin",
|
|
|
|
order: 10
|
|
|
|
};
|
|
|
|
|
2017-01-16 12:32:28 +09:00
|
|
|
const ownsOrIsAdmin = (user, document) => {
|
|
|
|
return Users.owns(user, document) || Users.isAdmin(user);
|
|
|
|
};
|
|
|
|
|
2016-06-23 15:00:58 +09:00
|
|
|
/**
|
2016-11-08 18:22:17 +01:00
|
|
|
* @summary Users schema
|
2016-11-22 18:14:51 -05:00
|
|
|
* @type {Object}
|
2016-06-23 15:00:58 +09:00
|
|
|
*/
|
2016-12-08 23:48:16 +01:00
|
|
|
const schema = {
|
2016-11-08 18:22:17 +01:00
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
publish: true,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-30 10:21:25 +09:00
|
|
|
preload: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
2016-11-08 18:22:17 +01:00
|
|
|
username: {
|
|
|
|
type: String,
|
|
|
|
// regEx: /^[a-z0-9A-Z_]{3,15}$/,
|
|
|
|
publish: true,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-30 10:21:25 +09:00
|
|
|
preload: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
|
|
|
emails: {
|
2017-01-11 18:02:12 +01:00
|
|
|
type: [Object],
|
2016-11-30 10:21:25 +09:00
|
|
|
optional: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
2016-11-08 18:22:17 +01:00
|
|
|
"emails.$.address": {
|
|
|
|
type: String,
|
|
|
|
regEx: SimpleSchema.RegEx.Email,
|
2016-11-30 10:21:25 +09:00
|
|
|
optional: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
|
|
|
"emails.$.verified": {
|
|
|
|
type: Boolean,
|
2016-11-30 10:21:25 +09:00
|
|
|
optional: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
publish: true,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-30 10:21:25 +09:00
|
|
|
preload: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
|
|
|
isAdmin: {
|
|
|
|
type: Boolean,
|
|
|
|
label: "Admin",
|
|
|
|
control: "checkbox",
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['admins'],
|
|
|
|
editableBy: ['admins'],
|
|
|
|
viewableBy: ['guests'],
|
2016-11-29 18:54:12 +09:00
|
|
|
group: adminGroup,
|
|
|
|
preload: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
|
|
|
profile: {
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
blackbox: true
|
|
|
|
},
|
2016-11-10 16:00:17 +01:00
|
|
|
// telescope-specific data, kept for backward compatibility and migration purposes
|
2016-12-08 23:48:16 +01:00
|
|
|
telescope: {
|
2016-11-30 10:31:19 +01:00
|
|
|
type: Object,
|
|
|
|
blackbox: true,
|
2016-11-10 16:00:17 +01:00
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-10 16:00:17 +01:00
|
|
|
},
|
2016-11-08 18:22:17 +01:00
|
|
|
services: {
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
2016-11-30 10:21:25 +09:00
|
|
|
blackbox: true,
|
2016-11-08 18:22:17 +01:00
|
|
|
},
|
2016-06-23 15:00:58 +09:00
|
|
|
/**
|
|
|
|
Bio (Markdown version)
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
bio: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
control: "textarea",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
viewableBy: ['guests'],
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
The name displayed throughout the app. Can contain spaces and special characters, doesn't need to be unique
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
displayName: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
publish: true,
|
|
|
|
profile: true,
|
|
|
|
control: "text",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
viewableBy: ['guests'],
|
2016-11-29 18:54:12 +09:00
|
|
|
preload: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
The user's email. Modifiable.
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
email: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
regEx: SimpleSchema.RegEx.Email,
|
|
|
|
required: true,
|
|
|
|
control: "text",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
2017-01-16 12:32:28 +09:00
|
|
|
viewableBy: ownsOrIsAdmin,
|
2016-11-30 10:21:25 +09:00
|
|
|
preload: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
// unique: true // note: find a way to fix duplicate accounts before enabling this
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
A hash of the email, used for Gravatar // TODO: change this when email changes
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
emailHash: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
publish: true,
|
2016-10-30 18:25:51 +01:00
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-29 18:54:12 +09:00
|
|
|
preload: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
The HTML version of the bio field
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
htmlBio: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
publish: true,
|
|
|
|
profile: true,
|
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
The user's karma
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
karma: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: Number,
|
2017-01-11 18:02:12 +01:00
|
|
|
decimal: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
publish: true,
|
2016-10-30 18:25:51 +01:00
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
The user's profile URL slug // TODO: change this when displayName changes
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
slug: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
publish: true,
|
2016-10-30 18:25:51 +01:00
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
viewableBy: ['guests'],
|
2016-11-29 18:54:12 +09:00
|
|
|
preload: true,
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
2017-01-16 12:32:28 +09:00
|
|
|
The user's Twitter username // not a real field
|
2016-06-23 15:00:58 +09:00
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
twitterUsername: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
publish: true,
|
|
|
|
profile: true,
|
|
|
|
control: "text",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
viewableBy: ['guests'],
|
2017-01-16 12:32:28 +09:00
|
|
|
resolveAs: 'twitterUsername: String',
|
2016-06-23 15:00:58 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
A link to the user's homepage
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
website: {
|
2016-06-23 15:00:58 +09:00
|
|
|
type: String,
|
|
|
|
regEx: SimpleSchema.RegEx.Url,
|
|
|
|
publish: true,
|
|
|
|
profile: true,
|
|
|
|
optional: true,
|
|
|
|
control: "text",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
viewableBy: ['guests'],
|
2016-07-19 17:30:59 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
Groups
|
|
|
|
*/
|
2017-01-18 10:18:33 +09:00
|
|
|
groups: {
|
2017-01-11 18:02:12 +01:00
|
|
|
type: [String],
|
2016-07-19 17:30:59 +09:00
|
|
|
optional: true,
|
|
|
|
control: "checkboxgroup",
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['admins'],
|
|
|
|
editableBy: ['admins'],
|
|
|
|
viewableBy: ['guests'],
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2016-07-19 17:30:59 +09:00
|
|
|
options: function () {
|
2016-12-06 10:55:47 +01:00
|
|
|
const groups = _.without(_.keys(Users.groups), "guests", "members", "admins");
|
2016-07-19 17:30:59 +09:00
|
|
|
return groups.map(group => {return {value: group, label: group};});
|
|
|
|
}
|
|
|
|
},
|
2016-11-29 18:54:12 +09:00
|
|
|
preload: true,
|
2016-07-19 17:30:59 +09:00
|
|
|
},
|
2016-11-22 18:14:51 -05:00
|
|
|
};
|
2016-10-29 16:37:33 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
export default schema;
|