Skip to content

Commit

Permalink
Add Event Log Notification Settings UI (#295)
Browse files Browse the repository at this point in the history
- Introduce UI for superadmins to manage event log notification
preferences.
- Allows subscriptions to specific events or critical events only.
  • Loading branch information
dhinesh-kumar-m authored Dec 4, 2024
1 parent c02193f commit 53e9345
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 21 deletions.
52 changes: 52 additions & 0 deletions src/_data/event_registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"course_created": {
"name": "Course Created",
"description": "Keep track of newly created content in the system.",
"priority": "moderate"
},
"course_deleted": {
"name": "Course Deleted",
"description": "Monitor this to prevent accidental or unauthorized deletions.",
"priority": "high"
},
"user_registered": {
"name": "User Registered",
"description": "Useful for tracking platform growth and user engagement.",
"priority": "low"
},
"login_failed": {
"name": "Failed Login Attempt",
"description": "This could indicate a potential security breach or unauthorized access attempt.",
"priority": "critical"
},
"admin_login": {
"name": "Admin Login",
"description": "Regular logins ensure accountability for administrative actions.",
"priority": "critical"
},
"sensitive_data_export": {
"name": "Sensitive Data Export",
"description": "Monitor to prevent misuse or data breaches.",
"priority": "high"
},
"staff_privilege_modified": {
"name": "Staff Privilege Modified",
"description": "Track these changes to ensure roles and permissions align with organizational policies.",
"priority": "moderate"
},
"course_updated": {
"name": "Course Updated",
"description": "Helps maintain an accurate course record.",
"priority": "low"
},
"account_deactivated": {
"name": "Account Deactivated",
"description": "Useful for tracking account management and preventing unauthorized actions.",
"priority": "moderate"
},
"super_admin_added": {
"name": "Super Admin Added",
"description": "Ensure this is authorized as super admins have elevated privileges.",
"priority": "high"
}
}
13 changes: 3 additions & 10 deletions src/testpress/events/list/empty_state.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
<div class="text-center">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="mx-auto size-12 text-gray-400"><path d="M16 22h2a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><circle cx="8" cy="16" r="6"/><path d="M9.5 17.5 8 16.25V14"/></svg>
<h3 class="mt-2 text-sm font-semibold text-gray-900">No Event Logs Found</h3>
<p class="mt-1 text-sm text-gray-500">There are no logs to display at the moment. Adjust log preferences if needed.</p>
<div class="mt-6">
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
<svg class="-ml-0.5 mr-1.5 size-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z"></path>
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"></path>
</svg>
Log Preferences
</button>
</div>
<p class="mt-1 text-sm text-gray-500">
No logs available at the moment. Logs will appear here as events are captured in the system.
</p>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/testpress/events/list/event_timeline.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!-- Timeline -->
<div class="bg-white p-6">
<div class="p-6">
<!-- Heading -->
{% for date, events in event_logs %}
<div class="ps-2 my-2 first:mt-0">
Expand Down
9 changes: 0 additions & 9 deletions src/testpress/events/list/heading.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ <h1 class="mt-2 text-lg md:text-xl font-semibold text-gray-800">Event Logs</h1>
</div>
</div>
</div>
<span>
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
<svg class="-ml-0.5 mr-1.5 size-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
Log Preferences
</button>
</span>
</div>
</div>

Expand Down
4 changes: 3 additions & 1 deletion src/testpress/events/list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
tags: testpress
title: Event Logs
date: 2023-04-28
active_tab: list
---

{% extends "layouts/admin_base.html" %}
Expand All @@ -17,7 +18,8 @@
{% include "./heading.html" %}
<div class="sm:block mt-4">
<div class="mx-auto max-w-6xl ">
<div class="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg">
<div class="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg bg-white">
{% include "src/testpress/events/tab.html" %}
{% if event_logs | length > 0 %}
{% include "./event_timeline.html" %}
{% include "partials/prev_next_pagination.html" %}
Expand Down
65 changes: 65 additions & 0 deletions src/testpress/events/settings/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<form action="#" method="POST" x-data="{ notificationPreference: 'all-critical-events' }">
<div class="py-6 px-8">
<fieldset>
<legend class="text-base/6 font-semibold text-gray-900">What needs to be notified?</legend>
<div class="mt-4 space-y-4">
<div class="flex items-start">
<div class="flex h-6 items-center">
<input id="all-critical-issues" name="notification-preference" type="radio" value="all-critical-events" x-model="notificationPreference" class="size-4 border-gray-300 text-emerald-600 focus:ring-emerald-500" checked>
</div>
<div class="ml-3 text-sm/6 relative ">
<label for="all-critical-issues" class="font-medium text-gray-900">
All Critical Events
<span class="inline-block align-middle relative group cursor-help">
<svg class="shrink-0 size-4 text-gray-500 dark:text-neutral-400" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<path d="M12 16v-4"></path>
<path d="M12 8h.01"></path>
</svg>
<div class="w-52 sm:w-96 p-4 left-full top-1/2 ml-2 transform sm:-translate-y-1/2 group-hover:opacity-100 group-hover:visible opacity-0 invisible transition-opacity absolute z-10 max-w-xs bg-white border border-gray-100 text-start rounded-xl shadow-md after:absolute after:top-0 after:-start-4 after:w-4 after:h-full" role="tooltip">
<p class="text-sm text-gray-700">
Critical events include <strong class="font-semibold text-gray-900">failed logins</strong>, <strong class="font-semibold text-gray-900">admin logins</strong>, <strong class="font-semibold text-gray-900">data exports</strong>, and <strong class="font-semibold text-gray-900">new super admins</strong>.
These actions require immediate attention to ensure system security.
</div>
</span>
</label>
<p class="text-gray-500">Stay informed on high-priority issues, like security breaches or failed logins.</p>
</div>
</div>
<div>
<div class="flex items-start">
<div class="flex h-6 items-center">
<input id="only-selected-events" name="notification-preference" type="radio" value="only-selected-events" x-model="notificationPreference" class="size-4 border-gray-300 text-emerald-600 focus:ring-emerald-500">
</div>
<div class="ml-3 text-sm/6">
<label for="only-selected-events" class="font-medium text-gray-900">Only Selected Events</label>
<p class="text-gray-500">Choose specific events that matter to you, such as course deletions or user sign-ups.</p>
</div>
</div>
</div>
</div>
</fieldset>
<div x-show="notificationPreference === 'only-selected-events'" class="px-4 py-6 sm:p-6">
<div class="grid lg:grid-cols-2 gap-3 lg:gap-5">
<!-- Checkbox -->
{% for event_key, event_data in event_registry %}
<label for="event-{{ event_key }}" class="py-3 px-4 flex text-sm bg-white text-gray-800 rounded-xl cursor-pointer rounded-xl ring-1 ring-gray-200 has-[:checked]:ring-2 has-[:checked]:ring-emerald-600 dark:bg-neutral-800 dark:text-neutral-200 dark:ring-neutral-700 dark:has-[:checked]:ring-emerald-500">
<input type="checkbox" id="event-{{ event_key }}" class="bg-transparent border-gray-200 text-emerald-600 rounded-full focus:ring-white focus:ring-offset-0 dark:text-emerald-500 dark:border-neutral-700 dark:focus:ring-neutral-800">
<span class="grow px-4">
<span class="block font-medium">
{{ event_data.name }}
</span>
<span class="block text-sm leading-6 text-gray-500 dark:text-neutral-500">
{{ event_data.description }}
</span>
</span>
</label>
{% endfor %}
<!-- End Checkbox -->
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 text-right sm:px-6">
<button type="submit" class="inline-flex justify-center rounded-md bg-emerald-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-emerald-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-600">Save</button>
</div>
</form>
24 changes: 24 additions & 0 deletions src/testpress/events/settings/heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="lg:flex lg:items-end lg:justify-between">
<div class="min-w-0 flex-1">
<nav class="flex" aria-label="Breadcrumb">
<ol role="list" class="flex items-center space-x-4">
<li>
<div class="flex">
<a href="{{'/testpress/events/list/'|url}}" class="text-sm font-medium text-gray-500 hover:text-gray-700">Settings</a>
</div>
</li>
<li>
<div class="flex items-center">
<svg class="size-5 shrink-0 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
<path fill-rule="evenodd" d="M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" />
</svg>
<a href="{{'/testpress/events/settings/'|url}}" class="ml-4 text-sm font-medium text-gray-500 hover:text-gray-700">Notification Preferences</a>
</div>
</li>
</ol>
</nav>
<div class="">
<h1 class="mt-2 text-lg md:text-xl font-semibold text-gray-800">Notification Preferences</h1>
</div>
</div>
</div>
29 changes: 29 additions & 0 deletions src/testpress/events/settings/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Event Log Settings
date: 2023-04-28
active_tab: settings
---

{% extends "layouts/admin_base.html" %}

{% block body_class %}overflow-y-scroll min-h-screen bg-gray-100{% endblock body_class %}
{% block content %}
<div class="max-w-7xl mx-auto xl:px-8 py-8 lg:grid lg:grid-cols-12 lg:gap-x-5">
{% include "partials/admin_sidebar.html" %}
<div class="space-y-6 sm:px-6 lg:px-0 lg:col-span-9">
<div class="flex flex-1 flex-col bg-gray-100">
<div class="flex-1 px-4 sm:px-0">
{% include "./heading.html" %}
<div class="sm:block mt-4">
<div class="mx-auto max-w-6xl ">
<div class="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg bg-white">
{% include "src/testpress/events/tab.html" %}
{% include './form.html' %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions src/testpress/events/tab.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="border-b border-gray-200 mx-4">
<nav class="-mb-px flex space-x-4" aria-label="Tabs">
<a href="{{'/testpress/events/list/'|url}}" class="{% if active_tab == 'list' %}border-emerald-500 text-emerald-600{% else %}border-transparent text-gray-500 hover:border-gray-200 hover:text-gray-700{% endif %}flex whitespace-nowrap border-b-2 px-1 py-4 text-sm font-medium"> Overview </a>
<a href="{{'/testpress/events/settings/'|url}}" class="{% if active_tab == 'settings' %}border-emerald-500 text-emerald-600{% else %}border-transparent text-gray-500 hover:border-gray-200 hover:text-gray-700{% endif %}flex whitespace-nowrap border-b-2 px-1 py-4 text-sm font-medium"> Notification Preferences </a>
</nav>
</div>

0 comments on commit 53e9345

Please sign in to comment.