Need Help with Limiting User Posts by Category and Time Frame

Hi everyone,

I’m looking for some guidance on achieving a specific functionality in Discourse. I’m managing a community where I need to implement a rule that prevents users from creating a new topic in two specific categories if they’ve already posted in either of those categories within the last 14 days. This restriction should apply even if their previous topic was deleted.

After some research, I came across the discourse-flexible-rate-limits plugin, which looks like it might be a good starting point. It allows for flexible rate limits based on user groups and actions, but it seems to focus on short-term frequency (minutes, hours, days) and doesn’t directly support:

  1. Checking posts across multiple categories.
  2. Enforcing a time frame as long as 14 days.
  3. Including deleted topics in the check.

Before diving into customizing this plugin or creating something from scratch, I wanted to ask:

  • Does anyone know of an existing plugin or method that might already handle this type of functionality?
  • Are there recommended approaches for modifying an existing plugin like discourse-flexible-rate-limits to include a cross-category and longer-term restriction?
  • Any general advice on how to implement this effectively?

I’d appreciate any insights or suggestions from this amazing community. If there’s interest, I’d also be happy to share updates on how I end up implementing this.

Thank you so much in advance for your help!

I’m not sure that I fully understand, but I think you want a plugin that will remove a user from a group when they post in a set of categories (using a topic create hook) and then run a job daily to add them back to the group after some number of days since their last topic in that set of categories.

Probably 3-5 hours work, maybe a bit more with good specs/tests

2 Likes

Hi, @pfaffman , happy holidays and thanks for reply!

I tried to create a flow chart to make it clear:

flowchart TB
    A0(User attempts to create a new topic in Category A or B) --> A1{Is user in<br>exempt group--Admin, Mod,TL3, TL4,Subscribers?}
    A1 -- No --> B1(Check user's last topic in Categories A, B, or C,<br>including hidden or deleted records)
    A1 -- Yes --> Z1(Allow posting)

    B1 --> B2{Was that last topic<br>created within 14 days?}
    B2 -- Yes --> C1(Block post + show error,<br>display cooldown,<br>link to rules)
    C1 --> E1(Save draft +<br>disable submit button) ---> End(End)
    B2 -- No --> D1(Allow post)

    D1 --> End(End)
    Z1 --> End(End)
And I also try to create a simple spec to help clarify
```mermaid
flowchart TB
    A0(User attempts to create a new topic in Category A or B) --> A1{Is user in<br>exempt group--Admin, Mod,TL3, TL4,Subscribers?}
    A1 -- No --> B1(Check user's last topic in Categories A, B, or C,<br>including hidden or deleted records)
    A1 -- Yes --> Z1(Allow posting)

    B1 --> B2{Was that last topic<br>created within 14 days?}
    B2 -- Yes --> C1(Block post + show error,<br>display cooldown,<br>link to rules)
    C1 --> E1(Save draft +<br>disable submit button) ---> End(End)
    B2 -- No --> D1(Allow post)

    D1 --> End(End)
    Z1 --> End(End)

Flow Explanation

  1. A0: A user initiates creating a new topic in Category A or B.

  2. A1: The system checks whether the user belongs to any exempt group:
    • Administrators
    • Moderators
    • Trust Level 3 (TL3)
    • Trust Level 4 (TL4)
    • A custom “Subscribers” group
    • If Yes, skip the cooldown check and immediately allow posting (Z1).
    • If No, proceed to B1.

  3. B1: The system retrieves the user’s last created topic in Categories A, B, or C. This lookup must include:
    • Soft-deleted topics (not permanently removed from the database).
    • Topics moved to hidden or compliance categories (e.g., Category C).

  4. B2: The system checks if the creation date of that last topic is within the past 14 days.
    Yes → Continue to C1 (the post is blocked).
    No → Proceed to D1 (allow the post).

  5. C1: The system shows an error message informing the user they are still under cooldown. The message should include:
    • A simplified statement that they cannot post yet.
    • The remaining time in days and hours (no minutes).
    • A link to the community rules page (provided below).

  6. E1: After showing the error, the user’s content is automatically saved as a draft, and the “Submit” or “Create Topic” button is disabled.

  7. D1: If more than 14 days have passed since the user’s last topic, the system allows the new topic to be posted.

  8. Z1: The user is in an exempt group, so they can post without restriction.

2. Detailed Specification

2.1 Restricted vs. Exempt Groups

Restricted Groups:
• Any users not in the following exempt groups (commonly TL0, TL1, TL2).
Exempt Groups:

  1. Administrators
  2. Moderators
  3. Trust Level 3 (TL3)
  4. Trust Level 4 (TL4)
  5. Subscribers (a custom group)

These exempt groups skip the 14-day check altogether.

2.2 Categories in Scope

New Topic Attempt:

• Triggered when a user (in a restricted group) tries to create a new topic in Category A or B.

Last Topic Check:

• The system checks the user’s last created topic in Categories A, B, or C (where C is the “hidden” or “compliance” category).

Note: Category C is included to capture situations where a user’s topic is moved for deletion/hiding/compliance. If the user created a topic in Category C within the last 14 days, it also counts towards the cooldown.

2.3 14-Day Cooldown Logic

• If the user’s most recent topic (in A/B/C) was created within 14 days, block new topic creation in A or B.

• If more than 14 days have passed, allow it.

Time Calculation

• Display the remaining time in days and hours (e.g., “3 days 12 hours remaining”).
• No need to show minutes or seconds.

2.4 Blocking and Draft Saving

Blocking Behavior:
• When the user is blocked, show an error message (C1).
• The system automatically saves the user’s content as a draft.
• The “Submit” button becomes disabled so the user cannot proceed.
Sample Error Message (simplified):

Sorry, you can’t create a new topic in this category yet.
Your last topic was posted less than 14 days ago,
and you have {X days and Y hours} left before you can post again.
For more details, see our community rules:
https://community.lezismore.org/t/topic/26/2

2.5 Future Flexibility

  1. Additional Categories:

• Currently only A, B, and C are configured.

• If you need to add or remove categories from this cooldown in the future, ensure the system or plugin can be extended without major code changes.

  1. Different Time Periods:

• The 14-day period could be configurable in the plugin’s settings (in case you want 7 days, 30 days, etc.).

  1. Dynamic Group Assignments:

• Additional or fewer exempt groups (e.g., if you add “Subscribers” or remove it) should be supported.

3. Summary

  1. Restricted Groups (TL0, TL1, TL2, or any user not in an exempt group) are subject to a 14-day cooldown before creating another topic in Categories A or B.

  2. Exempt Groups (Admin, Moderator, TL3, TL4, “Subscribers”) can post without restriction.

  3. The system checks the most recent topic creation in Categories A, B, or C (including soft-deleted or hidden). If it was created within 14 days, the new topic is blocked.

  4. Error Message: Displays the time remaining in days/hours and links to the community rules at:

https://community.lezismore.org/t/topic/26/2

  1. Draft: When blocked, the user’s post is saved as a draft, and the submit button is disabled.

  2. This specification can be extended to additional categories or different timeframes in the future.

I’d appreciate any suggestions!

1 Like

That’s pretty much what I was thinking. My solution is to remove them from the group that allows posting on those categories when they post. That makes it clear immediately they they can’t post and doesn’t require any special code changing how posting works.

3 Likes

Oh I can understand your solution now. :pray: While that approach might seem straightforward, I’m concerned about the following:

  1. Reading vs. Posting Access

• Currently, users at TL1 (or above) can both read and post in Categories A and B.

• If we remove the user from TL1 whenever they violate the 14-day rule, they will lose reading access as well. But we only want to block them from posting, not from reading.

  1. Need to Split Groups

• To solve the “read but can’t post” scenario, we’d have to create multiple sub-groups:

TL1 limited – can read and reply, but cannot create topics in A or B.

TL1 full – can read, reply, and create topics.

• If a user violates the 14-day rule, we would move them from TL1 full to TL1 limited. This seems more complicated.

  1. Automation Complexity

• Even with separate groups, we’d have to automatically move the user back to the “full” group once their cooldown expires.

• This means we must implement logic (e.g., a scheduled job or custom code) that calculates when the 14-day period is over and then reassigns the user from TL1 limited back to TL1 full.

• As a non-programer, I don’t feel confident handling such a complex automation by myself.

In other words, while removing users from certain groups might avoid modifying the posting logic directly, it creates additional groups and complex rules. We only want to restrict posting for 14 days, not reading access or other privileges.

Thank you very much for any suggestions or ideas. I’ve tried integrating things via Discourse APIs and webhooks in n8n, but given my limited coding background, it has been quite challenging for me.