Search by

stijnhau / moderation-bundle

stijnhau

User moderation for Symfony apps: temporary or permanent bans and mutes with reasons, admin role changes, an audit log, and ban enforcement at login and mid-session.

Package info

github.com/stijnhau/moderation-bundle

Type:symfony-bundle

pkg:composer/stijnhau/moderation-bundle

Statistics

Installs: 14

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-11-28 20:24 UTC

This package is auto-updated.

Last update: 2026-11-28 20:54:49 UTC


README

User moderation for Symfony apps, shared by CityWars, Crime-Life and F1Manager: temporary or permanent bans and mutes with a reason, granting and revoking admin, one audit log of who did what, and ban enforcement at login and in open sessions.

Piece What it does
Model\ModerationTrait + ModeratableUserInterface Ban/mute state on the app's user entity: banned at/until/reason, muted at/until/reason. A ban with no end is permanent.
Service\Moderation ban(), unban(), mute(), unmute(), grantAdmin(), revokeAdmin(), each with its rules and saved together with its audit log entry. assertNotMuted() is for the app's forum, message and chat guards.
Model\AbstractAuditLogEntry, Service\AuditLog, Query\AuditLogReader The audit log: action (your own names), actor (null for the system), subject user plus a frozen description, JSON details, and time. Moderation records its own actions; record anything else with AuditLog::record().
Security\BannedUserChecker Refuses banned users at login (as the firewall's user_checker, or called from yours).
Security\ActiveBanListener Logs a banned user out on their next request, adds a flash, and redirects to login. BannedUserLoggedOutEvent lets you adjust the response.

The admin screens are the app's own.

Install

composer require stijnhau/moderation-bundle
  1. The user entity implements ModeratableUserInterface and use ModerationTrait; (you add getModerationName(), isAdmin(), grantAdmin(), revokeAdmin()).

  2. Map an audit log entry: #[ORM\Entity] class AuditLogEntry extends AbstractAuditLogEntry {}.

  3. Configure config/packages/stijnhau_moderation.yaml:

    stijnhau_moderation:
        user_class: App\Entity\User
        require_reason: true
        protect_admins: true             # admins can't ban or mute other admins
        audit_log:
            entry_class: App\Entity\AuditLogEntry   # ~: no audit log
            per_page: 50
        actions:                         # your audit log's names for these actions
            banned: user.banned
            unbanned: user.unbanned
            muted: user.muted
            unmuted: user.unmuted
            admin_granted: admin.granted
            admin_revoked: admin.revoked
        enforcement:
            enabled: true
            redirect_route: app_login
            priority: -10                # kernel.request, after the firewall
            message_permanent: stijnhau_moderation.banned_permanent   # `security` domain, %reason%
            message_temporary: stijnhau_moderation.banned_until       # also %until%
  4. security.yaml: user_checker: Stijnhau\ModerationBundle\Security\BannedUserChecker, or call it from your own checker.

  5. bin/console make:migration.

Time comes from the clock service. Errors are ModerationExceptions, with keys in the stijnhau_moderation domain (en/nl/fr included).

License

MIT, see LICENSE.