feat: add notification preference system with per-type per-channel toggles and admin defaults

Implement configurable notification preferences across in-app and push channels, including a new `notification_preferences` table with soft-delete support, per-user toggle endpoints, admin defaults management, and canonical type definitions. The change introduces `NOTIFICATION_TYPES` and `NOTIFICATION_CHANNELS` constants, `NotificationPrefForm`/`NotificationDefaultForm` models, `notification_enabled` resolution logic, and UI integration via the profile notifications tab and admin panel.
This commit is contained in:
2026-06-13 10:09:48 +00:00
parent 1a26428952
commit 5e4f0b1f3f
27 changed files with 1330 additions and 33 deletions
+48
View File
@@ -260,6 +260,9 @@
<a href="/profile/{{ profile_user['username'] }}?tab=activity" class="profile-tab {% if current_tab == 'activity' %}active{% endif %}"><span class="icon">&#x1F4CA;</span> Activity</a>
<a href="/profile/{{ profile_user['username'] }}?tab=followers" class="profile-tab {% if current_tab == 'followers' %}active{% endif %}"><span class="icon">&#x1F465;</span> Followers ({{ followers_count }})</a>
<a href="/profile/{{ profile_user['username'] }}?tab=following" class="profile-tab {% if current_tab == 'following' %}active{% endif %}"><span class="icon">&#x1F464;</span> Following ({{ following_count }})</a>
{% if is_owner or viewer_is_admin %}
<a href="/profile/{{ profile_user['username'] }}?tab=notifications" class="profile-tab {% if current_tab == 'notifications' %}active{% endif %}"><span class="icon">&#x1F514;</span> Notifications</a>
{% endif %}
<button class="btn-ghost btn-icon profile-tab-btn">&#x25B3;</button>
</div>
@@ -352,6 +355,51 @@
{% if follow_pagination.has_next %}<a class="btn btn-ghost btn-sm" href="/profile/{{ profile_user['username'] }}?tab={{ current_tab }}&page={{ follow_pagination.next_page }}">Next</a>{% endif %}
</div>
{% endif %}
{% elif current_tab == 'notifications' %}
{% if is_owner or viewer_is_admin %}
<div class="notif-prefs" data-notif-prefs data-username="{{ profile_user['username'] }}">
<div class="notif-prefs-intro">
{% if not is_owner %}<p class="notif-prefs-admin">Editing notification settings for <strong>{{ profile_user['username'] }}</strong>.</p>{% endif %}
<p>Choose how you want to be notified for each event. <strong>In-app</strong> shows the notification on DevPlace; <strong>Push</strong> sends it to your subscribed devices.</p>
</div>
<table class="notif-prefs-table">
<thead>
<tr>
<th>Notification</th>
<th class="notif-prefs-col">In-app</th>
<th class="notif-prefs-col">Push</th>
</tr>
</thead>
<tbody>
{% for pref in notification_prefs %}
<tr>
<td>
<span class="notif-prefs-label">{{ pref.label }}</span>
<span class="notif-prefs-desc">{{ pref.description }}</span>
</td>
<td class="notif-prefs-col">
<label class="notif-switch">
<input type="checkbox" data-notif-toggle data-type="{{ pref.key }}" data-channel="in_app" {% if pref.in_app %}checked{% endif %}>
<span class="notif-switch-track"></span>
</label>
</td>
<td class="notif-prefs-col">
<label class="notif-switch">
<input type="checkbox" data-notif-toggle data-type="{{ pref.key }}" data-channel="push" {% if pref.push %}checked{% endif %}>
<span class="notif-switch-track"></span>
</label>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="notif-prefs-actions">
<button type="button" class="btn btn-ghost btn-sm" data-notif-reset>Reset to defaults</button>
</div>
</div>
{% else %}
<div class="empty-state">Not available.</div>
{% endif %}
{% else %}
{% for act in activities %}
<div class="post-card activity-card">