Skip to content

Conversation

Copy link

Copilot AI commented Oct 9, 2025

Overview

This PR implements the complete "Advanced Tag-Based Post Filtering with Multi-Tag & Comment Controls" feature epic, adding three major enhancements to improve post discovery and interaction:

  1. Multi-tag filtering with AND/OR logic for advanced search
  2. Comment controls to enable/disable comments on posts
  3. Guest user restrictions to limit content visibility for unauthenticated users

🎯 Features

1. Multi-Tag Filtering

A new endpoint allows filtering posts by multiple tags with flexible logic:

# Get posts with ANY of the specified tags (OR logic)
GET /api/tags/posts?tags=1,2,3&mode=any

# Get posts with ALL of the specified tags (AND logic)
GET /api/tags/posts?tags=1,2,3&mode=all

Use cases:

  • Advanced content discovery
  • Topic-based filtering with multiple categories
  • Finding posts that match all criteria (tutorials that cover both React AND TypeScript)

2. Comment Controls

Post authors can now control whether comments are allowed on their posts:

// Create a post with comments disabled
POST /api/posts
{
  "title": "Important Announcement",
  "content": "...",
  "commentsEnabled": false
}

// Toggle comments on existing posts
PATCH /api/posts/1
{
  "commentsEnabled": false
}

Use cases:

  • Announcements without discussion
  • Archived content
  • Spam prevention
  • Controlled discussions

The API returns 403 Forbidden when attempting to comment on posts with disabled comments.

3. Guest User Restrictions

Optional environment variables to limit what unauthenticated users can see:

# Limit posts visible to guests
GUEST_POST_LIMIT=10

# Limit comments visible to guests per post
GUEST_COMMENT_LIMIT=5

Use cases:

  • Encourage user registration
  • Prevent content scraping
  • Tiered access control

🔄 Database Migration

A new commentsEnabled field has been added to the Post table:

ALTER TABLE `Post` 
ADD COLUMN `commentsEnabled` BOOLEAN NOT NULL DEFAULT true;

Or using Prisma:

npx prisma migrate dev --name add_comments_enabled_to_post

All existing posts will default to commentsEnabled: true, maintaining current behavior.

📊 Technical Details

API Changes

New Endpoints:

  • GET /api/tags/posts?tags=<ids>&mode=<any|all> - Multi-tag filtering

Modified Responses:
All post objects now include:

{
  "commentsEnabled": true,
  ...
}

New Error Responses:

  • 403 Forbidden - "Comments are disabled for this post"
  • 404 Not Found - "One or more tags not found"

Files Changed

  • Controllers (3): tag, interaction, post
  • Services (3): tag, interaction, post
  • Routes (2): tag, interaction
  • Schema (1): Prisma schema with new field
  • Documentation (1): README.md extensively updated

Code Statistics

  • +372 lines added, -74 lines removed (net +298 lines)
  • 10 files modified
  • Zero breaking changes - fully backward compatible

✅ Quality Assurance

  • ✅ All JavaScript files pass syntax validation
  • ✅ All modules import correctly
  • ✅ CodeQL security scan passed - no new vulnerabilities
  • ✅ Prisma schema validated and formatted
  • ✅ 100% backward compatible

📚 Documentation

Comprehensive updates to README.md including:

  • New endpoint documentation with examples
  • Updated existing endpoint docs
  • Environment variable reference
  • Request/response examples
  • Error handling examples

🚀 Deployment

  1. Review and merge this PR
  2. Run database migration: npx prisma migrate dev --name add_comments_enabled_to_post
  3. Optionally set GUEST_POST_LIMIT and GUEST_COMMENT_LIMIT environment variables
  4. Deploy and test in staging
  5. Deploy to production

🔒 Security

  • No new security vulnerabilities introduced (verified by CodeQL)
  • Guest restrictions help prevent content scraping
  • Comment controls provide spam prevention capabilities
  • All existing authentication and authorization checks remain in place

Example Usage

// Frontend: Multi-tag filtering
const posts = await fetch('/api/tags/posts?tags=1,5,12&mode=all')
  .then(r => r.json());

// Frontend: Create post with comments disabled
await fetch('/api/posts', {
  method: 'POST',
  headers: { 
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'Announcement',
    content: 'Important update',
    commentsEnabled: false
  })
});

// Frontend: Check if comments are enabled
if (!post.commentsEnabled) {
  // Hide comment form
  showMessage('Comments are disabled on this post');
}

Backward Compatibility ✅

All changes are fully backward compatible:

  • Existing posts automatically get commentsEnabled: true
  • New fields are optional in all requests
  • No breaking changes to any existing API calls
  • Guest limits only apply when environment variables are set
  • Existing client applications continue to work without modifications

Closes #[issue-number]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.14.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2025-10-09T15:04:36Z&#34;,&#34;project_hash&#34;:&#34;86700263&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;a595029d&#34;,&#34;endpoint&#34;:&#34;REDACTED&#34;,&#34;disable&#34;:false,&#34;arch&#34;:&#34;x64&#34;,&#34;os&#34;:&#34;linux&#34;,&#34;node_version&#34;:&#34;v20.19.5&#34;,&#34;ci&#34;:true,&#34;ci_name&#34;:&#34;GitHub Actions&#34;,&#34;command&#34;:&#34;generate --postinstall \&#34;UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING\&#34;&#34;,&#34;schema_providers&#34;:[&#34;mysql&#34;],&#34;schema_preview_features&#34;:[],&#34;schema_generators_providers&#34;:[&#34;prisma-client-js&#34;],&#34;cache_file&#34;:&#34;/home/REDACTED/.cache/checkpoint-nodejs/prisma-a595029d&#34;,&#34;cache_duration&#34;:43200000,&#34;remind_duration&#34;:172800000,&#34;force&#34;:false,&#34;timeout&#34;:5000,&#34;unref&#34;:true,&#34;child_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child&#34;,&#34;client_event_id&#34;:&#34;&#34;,&#34;previous_client_event_id&#34;:&#34;&#34;,&#34;check_if_update_available&#34;:true} (dns block)
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.14.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2025-10-09T15:06:09Z&#34;,&#34;project_hash&#34;:&#34;86700263&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;a595029d&#34;,&#34;endpoint&#34;:&#34;REDACTED&#34;,&#34;disable&#34;:false,&#34;arch&#34;:&#34;x64&#34;,&#34;os&#34;:&#34;linux&#34;,&#34;node_version&#34;:&#34;v20.19.5&#34;,&#34;ci&#34;:true,&#34;ci_name&#34;:&#34;GitHub Actions&#34;,&#34;command&#34;:&#34;migrate dev --name [redacted]&#34;,&#34;schema_providers&#34;:[&#34;mysql&#34;],&#34;schema_preview_features&#34;:[],&#34;schema_generators_providers&#34;:[&#34;prisma-client-js&#34;],&#34;cache_file&#34;:&#34;/home/REDACTED/.cache/checkpoint-nodejs/prisma-a595029d&#34;,&#34;cache_duration&#34;:43200000,&#34;remind_duration&#34;:172800000,&#34;force&#34;:false,&#34;timeout&#34;:5000,&#34;unref&#34;:true,&#34;child_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child&#34;,&#34;client_event_id&#34;:&#34;&#34;,&#34;previous_client_event_id&#34;:&#34;&#34;,&#34;check_if_update_available&#34;:true} (dns block)
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.14.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2025-10-09T15:06:19Z&#34;,&#34;project_hash&#34;:&#34;86700263&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;a595029d&#34;,&#34;endpoint&#34;:&#34;REDACTED&#34;,&#34;disable&#34;:false,&#34;arch&#34;:&#34;x64&#34;,&#34;os&#34;:&#34;linux&#34;,&#34;node_version&#34;:&#34;v20.19.5&#34;,&#34;ci&#34;:true,&#34;ci_name&#34;:&#34;GitHub Actions&#34;,&#34;command&#34;:&#34;generate&#34;,&#34;schema_providers&#34;:[&#34;mysql&#34;],&#34;schema_preview_features&#34;:[],&#34;schema_generators_providers&#34;:[&#34;prisma-client-js&#34;],&#34;cache_file&#34;:&#34;/home/REDACTED/.cache/checkpoint-nodejs/prisma-a595029d&#34;,&#34;cache_duration&#34;:43200000,&#34;remind_duration&#34;:172800000,&#34;force&#34;:false,&#34;timeout&#34;:5000,&#34;unref&#34;:true,&#34;child_path&#34;:&#34;/home/REDACTED/work/Backend/Backend/node_modules/prisma/build/child&#34;,&#34;client_event_id&#34;:&#34;&#34;,&#34;previous_client_event_id&#34;:&#34;&#34;,&#34;check_if_update_available&#34;:true} (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>✨ Feature Request: Advanced Tag-Based Post Filtering with Multi-Tag & Comment Controls</issue_title>
<issue_description>📝 Epic: Tag-Based Post Filtering & Guest Restrictions

This epic covers a set of related features to improve post discovery and interaction through tag filtering, multi-tag selection, comment controls, and guest fetch limits.

It is broken down into smaller issues so they can be implemented and reviewed independently.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #13


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 9, 2025 15:10
Co-authored-by: sumit1642 <159118374+sumit1642@users.noreply.github.com>
Co-authored-by: sumit1642 <159118374+sumit1642@users.noreply.github.com>
Co-authored-by: sumit1642 <159118374+sumit1642@users.noreply.github.com>
Copilot AI changed the title [WIP] Add advanced tag-based post filtering with multi-tag and comment controls ✨ Add Advanced Tag-Based Post Filtering with Multi-Tag & Comment Controls Oct 9, 2025
Copilot AI requested a review from sumit1642 October 9, 2025 15:31
@sumit1642 sumit1642 requested a review from Copilot October 21, 2025 01:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements advanced tag-based post filtering with multi-tag support, comment controls, and guest user restrictions. The changes enable more sophisticated content discovery through AND/OR tag filtering logic, allow post authors to disable comments on their posts, and provide optional limits on content visibility for unauthenticated users.

Key Changes:

  • Added multi-tag filtering endpoint (GET /api/tags/posts) with configurable AND/OR logic modes
  • Implemented commentsEnabled field on posts with validation checks preventing comments on disabled posts
  • Added guest user restrictions via environment variables (GUEST_POST_LIMIT, GUEST_COMMENT_LIMIT)

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
services/tag.service.js Added getPostsByMultipleTags function and guest post limits to existing tag queries
services/post.service.js Added commentsEnabled parameter to post creation and guest post limits to queries
services/interaction.service.js Added comment enabled validation and guest comment limits
routes/tag.routes.js Added new multi-tag filtering route
routes/interaction.routes.js Changed comment fetching route to use optional authentication
prisma/schema.prisma Added commentsEnabled boolean field to Post model
controllers/tag.controller.js Implemented multi-tag filtering controller with validation
controllers/post.controller.js Added commentsEnabled support to create and update operations
controllers/interaction.controller.js Added disabled comments error handling and optional auth support
README.md Documented new endpoints, fields, and environment variables

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

title: post.title,
content: post.content,
published: post.published,
commentsEnabled: post.commentsEnabled ?? true,
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback value ?? true is unnecessary since the database field has a default value of true. This fallback should only be used if dealing with legacy data that might have null values. If all posts are guaranteed to have this field set, remove the nullish coalescing to simplify the code.

Suggested change
commentsEnabled: post.commentsEnabled ?? true,
commentsEnabled: post.commentsEnabled,

Copilot uses AI. Check for mistakes.
title: post.title,
content: post.content,
published: post.published,
commentsEnabled: post.commentsEnabled ?? true,
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback value ?? true is unnecessary since the database field has a default value of true. This fallback should only be used if dealing with legacy data that might have null values. If all posts are guaranteed to have this field set, remove the nullish coalescing to simplify the code.

Suggested change
commentsEnabled: post.commentsEnabled ?? true,
commentsEnabled: post.commentsEnabled,

Copilot uses AI. Check for mistakes.
title: post.title,
content: post.content,
published: post.published,
commentsEnabled: post.commentsEnabled ?? true,
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback value ?? true is unnecessary since the database field has a default value of true. This fallback should only be used if dealing with legacy data that might have null values. If all posts are guaranteed to have this field set, remove the nullish coalescing to simplify the code.

Suggested change
commentsEnabled: post.commentsEnabled ?? true,
commentsEnabled: post.commentsEnabled,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Feature Request: Advanced Tag-Based Post Filtering with Multi-Tag & Comment Controls

2 participants