mirror of
https://github.com/vale981/Vulcan
synced 2025-03-12 05:26:38 -04:00
78 lines
1.4 KiB
JavaScript
78 lines
1.4 KiB
JavaScript
![]() |
/*
|
||
|
|
||
|
Posts collection
|
||
|
|
||
|
*/
|
||
|
|
||
|
import schema from './schema.js';
|
||
|
import { createCollection, getDefaultResolvers, getDefaultMutations } from 'meteor/vulcan:core';
|
||
|
import Users from 'meteor/vulcan:users';
|
||
|
|
||
|
/**
|
||
|
* @summary The global namespace for Posts.
|
||
|
* @namespace Posts
|
||
|
*/
|
||
|
const Posts = createCollection({
|
||
|
|
||
|
collectionName: 'Posts',
|
||
|
|
||
|
typeName: 'Post',
|
||
|
|
||
|
schema,
|
||
|
|
||
|
resolvers: getDefaultResolvers('Posts'),
|
||
|
|
||
|
mutations: getDefaultMutations('Posts'),
|
||
|
|
||
|
});
|
||
|
|
||
|
// refactor: moved here from schema.js
|
||
|
Posts.config = {};
|
||
|
|
||
|
Posts.config.STATUS_PENDING = 1;
|
||
|
Posts.config.STATUS_APPROVED = 2;
|
||
|
Posts.config.STATUS_REJECTED = 3;
|
||
|
Posts.config.STATUS_SPAM = 4;
|
||
|
Posts.config.STATUS_DELETED = 5;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @summary Posts statuses
|
||
|
* @type {Object}
|
||
|
*/
|
||
|
Posts.statuses = [
|
||
|
{
|
||
|
value: 1,
|
||
|
label: 'pending'
|
||
|
},
|
||
|
{
|
||
|
value: 2,
|
||
|
label: 'approved'
|
||
|
},
|
||
|
{
|
||
|
value: 3,
|
||
|
label: 'rejected'
|
||
|
},
|
||
|
{
|
||
|
value: 4,
|
||
|
label: 'spam'
|
||
|
},
|
||
|
{
|
||
|
value: 5,
|
||
|
label: 'deleted'
|
||
|
}
|
||
|
];
|
||
|
|
||
|
Posts.checkAccess = (currentUser, post) => {
|
||
|
if (Users.isAdmin(currentUser) || Users.owns(currentUser, post)) { // admins can always see everything, users can always see their own posts
|
||
|
return true;
|
||
|
} else if (post.isFuture) {
|
||
|
return false;
|
||
|
} else {
|
||
|
const status = _.findWhere(Posts.statuses, {value: post.status});
|
||
|
return Users.canDo(currentUser, `posts.view.${status.label}`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Posts;
|