Vulcan/packages/nova-users/lib/schema.js

205 lines
4 KiB
JavaScript
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
import mutations from './mutations.js';
2016-06-23 15:00:58 +09:00
const adminGroup = {
name: "admin",
order: 10
};
/**
* @summary Users schema
* @type {Object}
2016-06-23 15:00:58 +09:00
*/
const schema = {
_id: {
type: String,
publish: true,
optional: true,
viewableIf: ['anonymous'],
preload: true,
2016-06-23 15:00:58 +09:00
},
username: {
type: String,
// regEx: /^[a-z0-9A-Z_]{3,15}$/,
publish: true,
optional: true,
viewableIf: ['anonymous'],
preload: true,
},
emails: {
type: [Object],
optional: true,
2016-06-23 15:00:58 +09:00
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
optional: true,
},
"emails.$.verified": {
type: Boolean,
optional: true,
},
createdAt: {
type: Date,
publish: true,
optional: true,
viewableIf: ['anonymous'],
preload: true,
},
isAdmin: {
type: Boolean,
label: "Admin",
control: "checkbox",
optional: true,
insertableIf: ['admins'],
editableIf: ['admins'],
viewableIf: ['anonymous'],
group: adminGroup,
preload: true,
},
profile: {
type: Object,
optional: true,
blackbox: true
},
// telescope-specific data, kept for backward compatibility and migration purposes
telescope: {
type: Object,
blackbox: true,
optional: true,
viewableIf: ['anonymous'],
},
services: {
type: Object,
optional: true,
blackbox: true,
},
2016-06-23 15:00:58 +09:00
/**
Bio (Markdown version)
*/
__bio: {
2016-06-23 15:00:58 +09:00
type: String,
optional: true,
control: "textarea",
insertableIf: ['default'],
editableIf: ['default'],
viewableIf: ['anonymous'],
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
*/
__displayName: {
2016-06-23 15:00:58 +09:00
type: String,
optional: true,
publish: true,
profile: true,
control: "text",
insertableIf: ['default'],
editableIf: ['default'],
viewableIf: ['anonymous'],
preload: true,
2016-06-23 15:00:58 +09:00
},
/**
The user's email. Modifiable.
*/
__email: {
2016-06-23 15:00:58 +09:00
type: String,
optional: true,
regEx: SimpleSchema.RegEx.Email,
required: true,
control: "text",
insertableIf: ['default'],
editableIf: ['default'],
viewableIf: ['anonymous'],
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
*/
__emailHash: {
2016-06-23 15:00:58 +09:00
type: String,
publish: true,
optional: true,
viewableIf: ['anonymous'],
preload: true,
2016-06-23 15:00:58 +09:00
},
/**
The HTML version of the bio field
*/
__htmlBio: {
2016-06-23 15:00:58 +09:00
type: String,
publish: true,
profile: true,
optional: true,
viewableIf: ['anonymous'],
2016-06-23 15:00:58 +09:00
},
/**
The user's karma
*/
__karma: {
2016-06-23 15:00:58 +09:00
type: Number,
decimal: true,
publish: true,
optional: true,
viewableIf: ['anonymous'],
2016-06-23 15:00:58 +09:00
},
/**
The user's profile URL slug // TODO: change this when displayName changes
*/
__slug: {
2016-06-23 15:00:58 +09:00
type: String,
publish: true,
optional: true,
viewableIf: ['anonymous'],
preload: true,
2016-06-23 15:00:58 +09:00
},
/**
The user's Twitter username
*/
__twitterUsername: {
2016-06-23 15:00:58 +09:00
type: String,
optional: true,
publish: true,
profile: true,
control: "text",
insertableIf: ['default'],
editableIf: ['default'],
viewableIf: ['anonymous'],
2016-06-23 15:00:58 +09:00
},
/**
A link to the user's homepage
*/
__website: {
2016-06-23 15:00:58 +09:00
type: String,
regEx: SimpleSchema.RegEx.Url,
publish: true,
profile: true,
optional: true,
control: "text",
insertableIf: ['default'],
editableIf: ['default'],
viewableIf: ['anonymous'],
2016-07-19 17:30:59 +09:00
},
/**
Groups
*/
__groups: {
2016-07-19 17:30:59 +09:00
type: [String],
optional: true,
control: "checkboxgroup",
insertableIf: ['admins'],
editableIf: ['admins'],
viewableIf: ['anonymous'],
form: {
2016-07-19 17:30:59 +09:00
options: function () {
const groups = _.without(_.keys(Users.groups), "anonymous", "default", "admins");
return groups.map(group => {return {value: group, label: group};});
}
},
preload: true,
2016-07-19 17:30:59 +09:00
},
};
export default schema;