You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Docker部署的DemocracyOS中关闭投票/民意调查结束后的评论功能

How to Disable Comments After a Poll Ends in Docker-Deployed DemocracyOS

Hey there! Since you've got DemocracyOS up and running via Docker and want to lock down comments once a poll or survey wraps up, here's a practical, step-by-step approach to implement this feature:

1. Get the DemocracyOS Source Code

If you only pulled the official Docker image without having the source code locally, you can either clone the official DemocracyOS repository, or extract the application files directly from your running container:

# Clone the official repo
git clone <official-democracyos-repo-url>
cd democracyos

Alternative: Extract files from a running container for quick edits:

docker cp <your-container-id>:/app ./democracyos-local
cd democracyos-local

2. Block Comment Submissions on the Backend

First, we need to make sure the backend rejects any new comment requests once a poll ends. Head to the comment creation endpoint—usually server/api/comments/create.js:

// Add this logic *before* the comment is saved to the database
const poll = await Poll.findById(req.body.pollId);
if (!poll) {
  return res.status(404).json({ error: 'Poll not found' });
}

// Check if the poll is closed (adjust the condition to match your poll's status field)
const isPollClosed = poll.status === 'closed' || new Date() > poll.endDate;
if (isPollClosed) {
  return res.status(403).json({ error: 'This poll has ended—no new comments are allowed.' });
}

This will stop any new comments from being saved once the poll is done, even if someone tries to submit via direct API calls.

3. Hide the Comment Input on the Frontend

Next, we'll update the frontend to hide the comment input box and inform users that comments are locked. Find the poll detail comments component—typically client/components/poll-detail/comments-section.jsx:

// First, determine if the poll is ended
const isPollEnded = poll.status === 'closed' || new Date() > poll.endDate;

// Adjust the render logic to show a message instead of the input
return (
  <div className="comments-section">
    {isPollEnded ? (
      <div className="comments-disabled-notice">
        <p>*This poll has concluded. No additional comments can be added.*</p>
      </div>
    ) : (
      {/* Keep your existing comment input form here */}
      <div className="comment-submission-form">
        {/* Your original input/textarea + submit button code */}
      </div>
    )}
    {/* Keep the existing comments list so users can still view past comments */}
    <div className="existing-comments">
      {/* Your comment list rendering code */}
    </div>
  </div>
);

Now users won't see the option to add a comment once the poll ends, but can still read all existing comments.

4. Update Your Docker Deployment

Since you're using Docker, you have two options to apply these changes:

In the root of your modified source code, build a new image to preserve your changes:

docker build -t my-custom-democracyos:v1 .

Then stop your old container and start a new one with your custom image:

docker stop <old-container-name-or-id>
docker rm <old-container-name-or-id>
docker run -d --name democracyos -p 80:3000 my-custom-democracyos:v1

Option 2: Mount Modified Files (Quick Testing)

If you want to test changes without rebuilding the entire image, mount the modified files directly into the container:

docker run -d --name democracyos -p 80:3000 \
  -v $(pwd)/server/api/comments/create.js:/app/server/api/comments/create.js \
  -v $(pwd)/client/components/poll-detail/comments-section.jsx:/app/client/components/poll-detail/comments-section.jsx \
  democracyos/democracyos:latest

Note: This is great for rapid testing, but using a custom image is more reliable for long-term deployment.

5. Test It Out

Create a test poll, set its end date to a time in the past, then try to add a comment. You should see the disabled notice on the frontend, and any attempt to submit a comment will get a 403 error from the backend—this means your feature is working!


内容的提问来源于stack exchange,提问作者testme75

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:12:42