removing Posts global

This commit is contained in:
Sacha Greif 2016-06-23 11:40:35 +09:00
parent 7a7b72c540
commit d9e69110a6
53 changed files with 198 additions and 89 deletions

View file

@ -1,4 +1,5 @@
import marked from 'marked'; import marked from 'marked';
import Posts from "meteor/nova:posts";
// TODO: switch over to Tom's migration package. // TODO: switch over to Tom's migration package.

View file

@ -4,6 +4,7 @@ import { Button } from 'react-bootstrap';
import moment from 'moment'; import moment from 'moment';
import { ModalTrigger } from "meteor/nova:core"; import { ModalTrigger } from "meteor/nova:core";
import { Link } from 'react-router'; import { Link } from 'react-router';
import Posts from "meteor/nova:posts";
class CustomPostsItem extends Telescope.components.PostsItem { class CustomPostsItem extends Telescope.components.PostsItem {

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
/* /*
Let's assign a color to each post (why? cause we want to, that's why). Let's assign a color to each post (why? cause we want to, that's why).
We'll do that by adding a custom field to the Posts collection. We'll do that by adding a custom field to the Posts collection.

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
serveAPI = function(terms){ serveAPI = function(terms){
var posts = []; var posts = [];

View file

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router'; import { Link } from 'react-router';
import Posts from "meteor/nova:posts";
const PostsCommenters = ({post}) => { const PostsCommenters = ({post}) => {
return ( return (

View file

@ -1,6 +1,7 @@
import React, { PropTypes, Component } from 'react'; import React, { PropTypes, Component } from 'react';
import { ListContainer } from "meteor/utilities:react-list-container"; import { ListContainer } from "meteor/utilities:react-list-container";
import moment from 'moment'; import moment from 'moment';
import Posts from "meteor/nova:posts";
class PostsDay extends Component { class PostsDay extends Component {

View file

@ -4,6 +4,7 @@ import NovaForm from "meteor/nova:forms";
import { DocumentContainer } from "meteor/utilities:react-list-container"; import { DocumentContainer } from "meteor/utilities:react-list-container";
//import { Messages } from "meteor/nova:core"; //import { Messages } from "meteor/nova:core";
//import Actions from "../actions.js"; //import Actions from "../actions.js";
import Posts from "meteor/nova:posts";
class PostsEditForm extends Component{ class PostsEditForm extends Component{
@ -18,7 +19,7 @@ class PostsEditForm extends Component{
const deletePostSuccess = this.context.intl.formatMessage({id: "posts.delete_success"}, {title: post.title}); const deletePostSuccess = this.context.intl.formatMessage({id: "posts.delete_success"}, {title: post.title});
if (window.confirm(deletePostConfirm)) { if (window.confirm(deletePostConfirm)) {
this.context.actions.call('posts.deleteById', post._id, (error, result) => { this.context.actions.call('posts.remove', post._id, (error, result) => {
this.context.messages.flash(deletePostSuccess, "success"); this.context.messages.flash(deletePostSuccess, "success");
this.context.events.track("post deleted", {'_id': post._id}); this.context.events.track("post deleted", {'_id': post._id});
}); });

View file

@ -1,5 +1,6 @@
import React, { PropTypes, Component } from 'react'; import React, { PropTypes, Component } from 'react';
import { ListContainer, DocumentContainer } from "meteor/utilities:react-list-container"; import { ListContainer, DocumentContainer } from "meteor/utilities:react-list-container";
import Posts from "meteor/nova:posts";
class PostsHome extends Component { class PostsHome extends Component {

View file

@ -4,6 +4,7 @@ import { Button } from 'react-bootstrap';
import moment from 'moment'; import moment from 'moment';
import { ModalTrigger } from "meteor/nova:core"; import { ModalTrigger } from "meteor/nova:core";
import { Link } from 'react-router'; import { Link } from 'react-router';
import Posts from "meteor/nova:posts";
class PostsItem extends Component { class PostsItem extends Component {

View file

@ -2,6 +2,7 @@ import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl'; import { intlShape } from 'react-intl';
import NovaForm from "meteor/nova:forms"; import NovaForm from "meteor/nova:forms";
import { withRouter } from 'react-router' import { withRouter } from 'react-router'
import Posts from "meteor/nova:posts";
const PostsNewForm = (props, context) => { const PostsNewForm = (props, context) => {

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import Posts from "meteor/nova:posts";
const PostsPage = ({document, currentUser}) => { const PostsPage = ({document, currentUser}) => {

View file

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { DocumentContainer } from "meteor/utilities:react-list-container"; import { DocumentContainer } from "meteor/utilities:react-list-container";
import Posts from "meteor/nova:posts";
const PostsSingle = (props, context) => { const PostsSingle = (props, context) => {
return ( return (

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import Posts from "meteor/nova:posts";
const PostsThumbnail = ({post}) => { const PostsThumbnail = ({post}) => {
return ( return (

View file

@ -1,6 +1,7 @@
import React, { PropTypes, Component } from 'react'; import React, { PropTypes, Component } from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { ListContainer } from "meteor/utilities:react-list-container"; import { ListContainer } from "meteor/utilities:react-list-container";
import Posts from "meteor/nova:posts";
const UsersProfile = ({user, currentUser}) => { const UsersProfile = ({user, currentUser}) => {

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
// generate slug on insert // generate slug on insert
Categories.before.insert(function (userId, doc) { Categories.before.insert(function (userId, doc) {
// if no slug has been provided, generate one // if no slug has been provided, generate one

View file

@ -1,4 +1,5 @@
import PublicationUtils from 'meteor/utilities:smart-publications'; import PublicationUtils from 'meteor/utilities:smart-publications';
import Posts from "meteor/nova:posts";
Posts.addField( Posts.addField(
{ {

View file

@ -1,3 +1,4 @@
import Posts from "meteor/nova:posts";
/** /**
* @summary Get all of a category's parents * @summary Get all of a category's parents

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Meteor.methods({ Meteor.methods({
"categories.deleteById": function (categoryId) { "categories.deleteById": function (categoryId) {

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Meteor.publish('categories', function() { Meteor.publish('categories', function() {
if(Users.can.viewById(this.userId)){ if(Users.can.viewById(this.userId)){
var categories = Categories.find(); var categories = Categories.find();

View file

@ -1,4 +1,5 @@
import cloudinary from "cloudinary"; import cloudinary from "cloudinary";
import Posts from "meteor/nova:posts";
const Cloudinary = cloudinary.v2; const Cloudinary = cloudinary.v2;

View file

@ -1,4 +1,5 @@
import marked from 'marked'; import marked from 'marked';
import Posts from "meteor/nova:posts";
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// Collection Hooks // // Collection Hooks //
@ -58,6 +59,10 @@ Comments.before.update(function (userId, doc, fieldNames, modifier) {
### comments.edit.async ### comments.edit.async
### users.remove.async
- UsersRemoveDeleteComments
*/ */
// ------------------------------------- comments.new.method -------------------------------- // // ------------------------------------- comments.new.method -------------------------------- //
@ -277,3 +282,16 @@ Telescope.callbacks.add("comments.edit.method", CommentsEditSubmittedPropertiesC
// ------------------------------------- comments.edit.async -------------------------------- // // ------------------------------------- comments.edit.async -------------------------------- //
// ------------------------------------- users.remove.async -------------------------------- //
function UsersRemoveDeleteComments (user, options) {
if (options.deleteComments) {
var deletedComments = Comments.remove({userId: userId});
} else {
// not sure if anything should be done in that scenario yet
// Comments.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
}
}
Telescope.callbacks.add("users.remove.async", UsersRemoveDeleteComments);

View file

@ -1,4 +1,5 @@
import PublicationUtils from 'meteor/utilities:smart-publications'; import PublicationUtils from 'meteor/utilities:smart-publications';
import Posts from "meteor/nova:posts";
Posts.addField([ Posts.addField([
/** /**

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Comments.methods = {}; Comments.methods = {};
// ------------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------------- //
// -------------------------------------- Submit Comment ------------------------------------- // // -------------------------------------- Submit Comment ------------------------------------- //

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Comments.getNotificationProperties = function (data) { Comments.getNotificationProperties = function (data) {
const comment = data.comment; const comment = data.comment;
var commentAuthor = Meteor.users.findOne(comment.userId); var commentAuthor = Meteor.users.findOne(comment.userId);

View file

@ -1,4 +1,5 @@
import PublicationsUtils from 'meteor/utilities:smart-publications'; import PublicationsUtils from 'meteor/utilities:smart-publications';
import Posts from "meteor/nova:posts";
Comments.publishedFields = {}; Comments.publishedFields = {};

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Comments._ensureIndex({postId: 1}); Comments._ensureIndex({postId: 1});
Comments._ensureIndex({parentCommentId: 1}); Comments._ensureIndex({parentCommentId: 1});

View file

@ -34,8 +34,7 @@ Package.onUse(function(api) {
], 'client'); ], 'client');
api.addFiles([ api.addFiles([
'lib/server/start.js', 'lib/server/start.js'
'lib/server/routes.js'
], ['server']); ], ['server']);
api.mainModule("lib/export.js", "server"); api.mainModule("lib/export.js", "server");

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import Posts from "meteor/nova:posts";
const methodList = Meteor.isServer ? Meteor.server.method_handlers : Meteor.connection._methodHandlers; const methodList = Meteor.isServer ? Meteor.server.method_handlers : Meteor.connection._methodHandlers;

View file

@ -1,6 +1,7 @@
import PublicationUtils from 'meteor/utilities:smart-publications'; import PublicationUtils from 'meteor/utilities:smart-publications';
import EmbedlyURL from './components/EmbedlyURL.jsx'; import EmbedlyURL from './components/EmbedlyURL.jsx';
import ThumbnailURL from './components/ThumbnailURL.jsx'; import ThumbnailURL from './components/ThumbnailURL.jsx';
import Posts from "meteor/nova:posts";
Posts.addField([ Posts.addField([
{ {

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
getEmbedlyData = function (url) { getEmbedlyData = function (url) {
var data = {}; var data = {};
var extractBase = 'http://api.embed.ly/1/extract'; var extractBase = 'http://api.embed.ly/1/extract';

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Users.addField({ Users.addField({
fieldName: 'telescope.isDummy', fieldName: 'telescope.isDummy',
fieldSchema: { fieldSchema: {

View file

@ -1,4 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import Posts from "meteor/nova:posts";
var toTitleCase = function (str) { var toTitleCase = function (str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});

View file

@ -1,4 +1,5 @@
import NewsletterSubscribe from './components/NewsletterSubscribe.jsx'; import NewsletterSubscribe from './components/NewsletterSubscribe.jsx';
import Posts from "meteor/nova:posts";
Posts.addField({ Posts.addField({
fieldName: 'scheduledAt', fieldName: 'scheduledAt',

View file

@ -1,5 +1,7 @@
import { Avatar } from 'meteor/nova:core'; import { Avatar } from 'meteor/nova:core';
import moment from 'moment'; import moment from 'moment';
import Posts from "meteor/nova:posts";
// import Email from 'meteor/nova:email'; // import Email from 'meteor/nova:email';
// create new "campaign" view for all posts from the past X days that haven't been scheduled yet // create new "campaign" view for all posts from the past X days that haven't been scheduled yet

View file

@ -2,6 +2,7 @@ import htmlToText from 'html-to-text';
// import Email from 'meteor/nova:email'; // import Email from 'meteor/nova:email';
import Campaign from "./campaign.js"; import Campaign from "./campaign.js";
import moment from 'moment'; import moment from 'moment';
import Posts from "meteor/nova:posts";
const defaultPosts = 5; const defaultPosts = 5;

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
import marked from 'marked'; import marked from 'marked';
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
@ -92,6 +92,10 @@ Posts.before.update(function (userId, doc, fieldNames, modifier) {
- PostsApprovedNotification - PostsApprovedNotification
### users.remove.async
- UsersRemoveDeletePosts
*/ */
// ------------------------------------- posts.new.method -------------------------------- // // ------------------------------------- posts.new.method -------------------------------- //
@ -345,3 +349,15 @@ function PostsApprovedNotification (post) {
} }
} }
Telescope.callbacks.add("posts.approve.async", PostsApprovedNotification); Telescope.callbacks.add("posts.approve.async", PostsApprovedNotification);
// ------------------------------------- users.remove.async -------------------------------- //
function UsersRemoveDeletePosts (user, options) {
if (options.deletePosts) {
var deletedPosts = Posts.remove({userId: userId});
} else {
// not sure if anything should be done in that scenario yet
// Posts.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
}
}
Telescope.callbacks.add("users.remove.async", UsersRemoveDeletePosts);

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js';
const adminGroup = { const adminGroup = {
name: "admin", name: "admin",

View file

@ -1,3 +1,5 @@
import Posts from './namespace.js';
const getPost = (postId) => { const getPost = (postId) => {
return typeof Posts.findOne(postId) === "undefined" ? {post: Posts.findOne()} : {post: Posts.findOne(postId)}; return typeof Posts.findOne(postId) === "undefined" ? {post: Posts.findOne()} : {post: Posts.findOne(postId)};
}; };

View file

@ -0,0 +1,14 @@
import Posts from './namespace.js';
import './namespace.js';
import './collection.js';
import './parameters.js';
import './notifications.js';
import './views.js';
import './helpers.js';
import './published_fields.js';
import './callbacks.js';
import './emails.js';
import './methods.js';
export default Posts;

View file

@ -1,5 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import Posts from './config'; import Posts from './namespace.js';
////////////////// //////////////////
// Link Helpers // // Link Helpers //
@ -126,4 +126,37 @@ Posts.getThumbnailUrl = (post) => {
return thumbnailUrl.indexOf('//') > -1 ? Telescope.utils.addHttp(thumbnailUrl) : Telescope.utils.getSiteUrl().slice(0,-1) + thumbnailUrl; return thumbnailUrl.indexOf('//') > -1 ? Telescope.utils.addHttp(thumbnailUrl) : Telescope.utils.getSiteUrl().slice(0,-1) + thumbnailUrl;
} }
}; };
Posts.helpers({ getThumbnailUrl() { return Posts.getThumbnailUrl(this); } }); Posts.helpers({ getThumbnailUrl() { return Posts.getThumbnailUrl(this); } });
///////////////////
// Users Helpers //
///////////////////
/**
* @summary Check if a given user can view a specific post
* @param {Object} user - can be undefined!
* @param {Object} post
*/
Users.can.viewPost = function (user, post) {
if (Users.is.admin(user)) {
return true;
} else {
switch (post.status) {
case Posts.config.STATUS_APPROVED:
return Users.can.view(user);
case Posts.config.STATUS_REJECTED:
case Posts.config.STATUS_SPAM:
case Posts.config.STATUS_PENDING:
return Users.can.view(user) && Users.is.owner(user, post);
case Posts.config.STATUS_DELETED:
return false;
}
}
}
Users.helpers({canViewPost: function () {return Users.can.viewPost(this, post);}});

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
/** /**
* *
@ -48,6 +48,30 @@ Posts.methods.edit = function (postId, modifier, post) {
return Posts.findOne(postId); return Posts.findOne(postId);
}; };
/**
* @summary Increase the number of clicks on a post
* @param {string} postId the ID of the post being edited
* @param {string} ip the IP of the current user
*/
Posts.methods.increaseClicks = (postId, ip) => {
var clickEvent = {
name: 'click',
properties: {
postId: postId,
ip: ip
}
};
// make sure this IP hasn't previously clicked on this post
var existingClickEvent = Events.findOne({name: 'click', 'properties.postId': postId, 'properties.ip': ip});
if(!existingClickEvent){
Events.log(clickEvent);
Posts.update(postId, { $inc: { clickCount: 1 }});
}
};
// ------------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------------- //
// ----------------------------------------- Methods ----------------------------------------- // // ----------------------------------------- Methods ----------------------------------------- //
// ------------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------------- //
@ -177,7 +201,7 @@ Meteor.methods({
* @isMethod true * @isMethod true
* @param {String} postId - the id of the post * @param {String} postId - the id of the post
*/ */
'posts.deleteById': function(postId) { 'posts.remove': function(postId) {
check(postId, String); check(postId, String);
@ -199,7 +223,7 @@ Meteor.methods({
// delete post // delete post
Posts.remove(postId); Posts.remove(postId);
Telescope.callbacks.runAsync("postDeleteAsync", post); Telescope.callbacks.runAsync("posts.remove.async", post);
}, },

View file

@ -11,7 +11,7 @@ const PostsStub = {
/* we need to handle two scenarios: when the package is called as a Meteor package, /* we need to handle two scenarios: when the package is called as a Meteor package,
and when it's called as a NPM package */ and when it's called as a NPM package */
Posts = typeof Mongo !== "undefined" ? new Mongo.Collection("posts") : PostsStub; const Posts = typeof Mongo !== "undefined" ? new Mongo.Collection("posts") : PostsStub;
/** /**
* @summary Posts config namespace * @summary Posts config namespace

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
Posts.getNotificationProperties = function (data) { Posts.getNotificationProperties = function (data) {
const post = data.post; const post = data.post;

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
import moment from 'moment'; import moment from 'moment';
/** /**

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
import PublicationsUtils from 'meteor/utilities:smart-publications'; import PublicationsUtils from 'meteor/utilities:smart-publications';
Posts.publishedFields = {}; Posts.publishedFields = {};

View file

@ -1,3 +1,4 @@
import Posts from '../namespace.js';
import { CursorCounts } from "meteor/utilities:react-list-container"; import { CursorCounts } from "meteor/utilities:react-list-container";
Posts._ensureIndex({"status": 1, "postedAt": 1}); Posts._ensureIndex({"status": 1, "postedAt": 1});

View file

@ -1,21 +1,4 @@
var increasePostClicks = function(postId, ip){ import Posts from '../namespace.js';
var clickEvent = {
name: 'click',
properties: {
postId: postId,
ip: ip
}
};
// make sure this IP hasn't previously clicked on this post
var existingClickEvent = Events.findOne({name: 'click', 'properties.postId': postId, 'properties.ip': ip});
if(!existingClickEvent){
Events.log(clickEvent);
Posts.update(postId, { $inc: { clickCount: 1 }});
}
};
Picker.route('/out', function(params, req, res, next) { Picker.route('/out', function(params, req, res, next) {
var query = params.query; var query = params.query;
@ -23,7 +6,7 @@ Picker.route('/out', function(params, req, res, next) {
var post = Posts.findOne({url: query.url}); var post = Posts.findOne({url: query.url});
if (post) { if (post) {
var ip = req.connection.remoteAddress; var ip = req.connection.remoteAddress;
increasePostClicks(post._id, ip); Posts.methods.increaseClicks(post._id, ip);
res.writeHead(302, {'Location': query.url}); res.writeHead(302, {'Location': query.url});
res.end(); res.end();
} else { } else {

View file

@ -1,4 +1,4 @@
import Posts from './config' import Posts from './namespace.js'
/** /**
* @summary Post views are filters used for subscribing to and viewing posts * @summary Post views are filters used for subscribing to and viewing posts

View file

@ -28,22 +28,25 @@ Package.onUse(function (api) {
], ['client', 'server'], {weak: true}); ], ['client', 'server'], {weak: true});
api.addFiles([ api.addFiles([
'lib/config.js', // 'lib/namespace.js',
'lib/collection.js', // 'lib/collection.js',
'lib/parameters.js', // 'lib/parameters.js',
'lib/notifications.js', // 'lib/notifications.js',
'lib/views.js', // 'lib/views.js',
'lib/helpers.js', // 'lib/helpers.js',
'lib/published_fields.js', // 'lib/published_fields.js',
'lib/callbacks.js', // 'lib/callbacks.js',
'lib/emails.js', // 'lib/emails.js',
'lib/methods.js' // 'lib/methods.js'
], ['client', 'server']); ], ['client', 'server']);
api.addFiles([ api.addFiles([
'lib/server/publications.js' 'lib/server/publications.js',
'lib/server/routes.js'
], ['server']); ], ['server']);
api.mainModule("lib/export.js", "server");
api.mainModule("lib/export.js", "client");
// var languages = ["ar", "bg", "cs", "da", "de", "el", "en", "es", "et", "fr", "hu", "id", "it", "ja", "kk", "ko", "nl", "pl", "pt-BR", "ro", "ru", "sl", "sv", "th", "tr", "vi", "zh-CN"]; // var languages = ["ar", "bg", "cs", "da", "de", "el", "en", "es", "et", "fr", "hu", "id", "it", "ja", "kk", "ko", "nl", "pl", "pt-BR", "ro", "ru", "sl", "sv", "th", "tr", "vi", "zh-CN"];
// var languagesPaths = languages.map(function (language) { // var languagesPaths = languages.map(function (language) {
@ -51,8 +54,8 @@ Package.onUse(function (api) {
// }); // });
// api.addFiles(languagesPaths, ["client", "server"]); // api.addFiles(languagesPaths, ["client", "server"]);
api.export([ // api.export([
'Posts' // 'Posts'
]); // ]);
}); });

View file

@ -12,10 +12,16 @@ var completeUserProfile = function (userId, modifier, user) {
Users.methods = {}; Users.methods = {};
/**
* @summary Edit a user in the database
* @param {string} userId the ID of the user being edited
* @param {Object} modifier the modifier object
* @param {Object} user - the current user object
*/
Users.methods.edit = (userId, modifier, user) => { Users.methods.edit = (userId, modifier, user) => {
if (typeof user === "undefined") { if (typeof user === "undefined") {
user = Posts.findOne(userId); user = Users.findOne(userId);
} }
// ------------------------------ Callbacks ------------------------------ // // ------------------------------ Callbacks ------------------------------ //
@ -128,23 +134,15 @@ Meteor.methods({
}, },
'users.remove'(userId, removePosts) { 'users.remove'(userId, options) {
if (Users.is.adminById(this.userId)) { if (Users.is.adminById(this.userId)) {
removePosts = (typeof removePosts === "undefined") ? false : removePosts; const user = Users.findOne(userId);
Meteor.users.remove(userId); Meteor.users.remove(userId);
if (removePosts) { Telescope.callbacks.runAsync("users.remove.async", user, options);
var deletedPosts = Posts.remove({userId: userId});
var deletedComments = Comments.remove({userId: userId});
return "Deleted "+deletedPosts+" posts and "+deletedComments+" comments";
} else {
// not sure if anything should be done in that scenario yet
// Posts.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
// Comments.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
}
} }

View file

@ -41,35 +41,6 @@ Users.can.viewById = function (userId) {
}; };
Users.helpers({canViewById: function () {return Users.can.viewById(this);}}); Users.helpers({canViewById: function () {return Users.can.viewById(this);}});
/**
* @summary Check if a given user can view a specific post
* @param {Object} user - can be undefined!
* @param {Object} post
*/
Users.can.viewPost = function (user, post) {
if (Users.is.admin(user)) {
return true;
} else {
switch (post.status) {
case Posts.config.STATUS_APPROVED:
return Users.can.view(user);
case Posts.config.STATUS_REJECTED:
case Posts.config.STATUS_SPAM:
case Posts.config.STATUS_PENDING:
return Users.can.view(user) && Users.is.owner(user, post);
case Posts.config.STATUS_DELETED:
return false;
}
}
}
Users.helpers({canViewPost: function () {return Users.can.viewPost(this, post);}});
/** /**
* @summary Check if a given user has permission to submit new posts * @summary Check if a given user has permission to submit new posts
* @param {Object} user * @param {Object} user

View file

@ -1,4 +1,5 @@
import PublicationUtils from 'meteor/utilities:smart-publications'; import PublicationUtils from 'meteor/utilities:smart-publications';
import Posts from "meteor/nova:posts";
// ------------------------------------- Posts -------------------------------- // // ------------------------------------- Posts -------------------------------- //

View file

@ -1,3 +1,5 @@
import Posts from "meteor/nova:posts";
Meteor.startup(function () { Meteor.startup(function () {
var scoreInterval = Telescope.settings.get("scoreUpdateInterval") || 30; var scoreInterval = Telescope.settings.get("scoreUpdateInterval") || 30;
if (scoreInterval > 0) { if (scoreInterval > 0) {