Skip to content

Commit

Permalink
Merge pull request #226 from binary-coffee-dev/feature/490
Browse files Browse the repository at this point in the history
Fix issue with new comments policy (#490)
  • Loading branch information
wil92 authored Apr 1, 2024
2 parents 29f6515 + cc6d8cf commit 834b1cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/api/comment/policies/canComment.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict';

module.exports = async (ctx, config, { strapi }) => {
module.exports = async (ctx, config, {strapi}) => {
if (!(ctx && ctx.state && ctx.state.user)) {
return false;
}
if (!strapi.service('api::post.post').isAdmin(ctx)) {
const startOfDay = strapi.config.functions.dateUtil.getStartDay();
const nextDay = strapi.config.functions.dateUtil.getEndDay();
const commentsCount = await strapi.query('api::comment.comment').count({
$and: [
{createdAt: {$lte: nextDay}},
{createdAt: {$gte: startOfDay}}
],
user: ctx.state.user.id
where: {
$and: [
{createdAt: {$lte: nextDay}},
{createdAt: {$gte: startOfDay}}
],
user: ctx.state.user.id
}
});
if (commentsCount >= strapi.config.custom.maxNumberOfCommentsPerDay) {
console.log('Limit of comments by post');
Expand Down

0 comments on commit 834b1cd

Please sign in to comment.