Vulcan/packages/telescope-users/lib/users.js

233 lines
3.9 KiB
JavaScript
Raw Normal View History

/**
* Vote schema
* @type {SimpleSchema}
*/
Telescope.schemas.votes = new SimpleSchema({
itemId: {
type: String
},
power: {
type: Number,
optional: true
},
votedAt: {
type: Date,
optional: true
}
});
/**
* User Data schema
* @type {SimpleSchema}
*/
Telescope.schemas.userData = new SimpleSchema({
2015-05-11 11:46:18 +09:00
/**
Bio (Markdown version)
*/
bio: {
type: String,
optional: true,
editableBy: ["member", "admin"],
autoform: {
rows: 5
}
},
2015-05-11 11:46:18 +09:00
/**
Total comment count
*/
commentCount: {
type: Number,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
The name displayed throughout the app. Can contain spaces and special characters, doesn't need to be unique
*/
displayName: {
type: String,
optional: true,
editableBy: ["member", "admin"]
},
2015-05-11 11:46:18 +09:00
/**
An array containing comment downvotes
*/
downvotedComments: {
type: [Telescope.schemas.votes],
optional: true
},
2015-05-11 11:46:18 +09:00
/**
An array containing posts downvotes
*/
downvotedPosts: {
type: [Telescope.schemas.votes],
optional: true
},
2015-05-11 11:46:18 +09:00
/**
The user's email. Modifiable. // TODO: enforce uniqueness and use for login
*/
email: {
type: String,
optional: true,
required: true,
editableBy: ["member", "admin"]
},
2015-05-11 11:46:18 +09:00
/**
A hash of the email, used for Gravatar // TODO: change this when email changes
*/
emailHash: {
type: String,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
The HTML version of the bio field
*/
htmlBio: {
type: String,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
A count of the user's remaining invites
*/
inviteCount: {
type: Number,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
A count of how many users have been invited by the user
*/
invitedCount: {
type: Number,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
Whether the user is invited or not
*/
isInvited: {
type: Boolean,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
The user's karma
*/
karma: {
type: Number,
2015-05-11 11:09:26 +09:00
decimal: true,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
Total post count
*/
postCount: {
type: Number,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
A blackbox modifiable object to store the user's settings
*/
2015-05-11 11:09:26 +09:00
settings: {
type: Object,
optional: true,
editableBy: ["member", "admin"],
blackbox: true
},
2015-05-11 11:46:18 +09:00
/**
The user's profile URL slug // TODO: change this when displayName changes
*/
slug: {
type: String,
optional: true
},
2015-05-11 11:46:18 +09:00
/**
The user's Twitter username
*/
twitterUsername: {
type: String,
optional: true,
editableBy: ["member", "admin"]
},
2015-05-11 11:46:18 +09:00
/**
An array containing comments upvotes
*/
upvotedComments: {
type: [Telescope.schemas.votes],
optional: true
},
2015-05-11 11:46:18 +09:00
/**
An array containing posts upvotes
*/
upvotedPosts: {
type: [Telescope.schemas.votes],
optional: true
},
2015-05-11 11:46:18 +09:00
/**
A link to the user's homepage
*/
website: {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true,
editableBy: ["member", "admin"]
}
});
/**
* Users schema
* @type {SimpleSchema}
*/
2015-05-11 12:15:10 +09:00
Users.schema = new SimpleSchema({
_id: {
type: String,
optional: true
},
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
isAdmin: {
type: Boolean,
optional: true
},
profile: {
type: Object,
optional: true,
blackbox: true
},
telescope: { // telescope-specific data
type: Telescope.schemas.userData,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true
}
});
2015-05-11 12:15:10 +09:00
Users.schema.internationalize();
/**
* Attach schema to Meteor.users collection
*/
2015-05-11 12:15:10 +09:00
Users.attachSchema(Users.schema);
/**
* Users collection permissions
*/
Users.allow({
update: _.partial(Telescope.allowCheck, Meteor.users),
remove: _.partial(Telescope.allowCheck, Meteor.users)
2015-05-03 13:09:57 -04:00
});