Skip to content

Add live data updates system for admin panels and comprehensive session management system for admin interface - #5

Closed
timujinne wants to merge 13 commits into
BeamLabEU:devfrom
timujinne:main
Closed

Add live data updates system for admin panels and comprehensive session management system for admin interface#5
timujinne wants to merge 13 commits into
BeamLabEU:devfrom
timujinne:main

Conversation

@timujinne

Copy link
Copy Markdown
Contributor

Update version to 1.1.1
Add comprehensive session management system for admin interface
Add live data updates system for admin panels
Add automatic user logout on role changes

Add profile changeset function and complete profile editing interface
with first name and last name fields. Includes validation and update
handlers for improved user experience.
Remove unnecessary redirect pipe for login route and add admin
shortcut route for improved navigation. Consolidates authentication
flow and enhances admin dashboard accessibility.
Add profile settings functionality and fix router integration.
Update version references in README and add detailed changelog
entry for new features and improvements.
Add profile settings and fix router integration
Implements real-time data synchronization across all admin interfaces
using isolated PubSub system for Users, Roles and Dashboard statistics.
Key features:
- PhoenixKit.PubSub.Manager: Autonomous PubSub system with lazy initialization
- PhoenixKit.Admin.Events: Centralized event broadcasting API
- Live updates for Users table (creation, updates, role changes)
- Live updates for Roles table (CRUD operations)
- Live updates for Dashboard statistics
- Graceful degradation when database unavailable
- Zero configuration - works independently of parent application
- Complete isolation from parent application PubSub
Technical implementation:
- GenServer-based PubSub manager with automatic startup
- LiveView subscriptions with handle_info event handlers
- Broadcasting integrated into Auth and Roles contexts
- Safe error handling for missing repository configuration
Testing: Comprehensive test suite validates all event types
Documentation: LIVE_UPDATES_README.md with setup and usage guide
Features:
- Complete session monitoring with active/expired session tracking
- Real-time session statistics dashboard with live updates
- Session revocation controls for individual and bulk operations
- Admin navigation integration with sessions sidebar menu
- PubSub events system for real-time session state updates
- Modern responsive UI with search, filtering, and pagination
- Security-focused design with token preview instead of full tokens
- Professional dashboard statistics cards with gradient design
Technical implementation:
- PhoenixKit.Users.Sessions context for session management
- SessionsLive component with real-time event subscriptions
- Admin events system extension for session broadcasting
- Navigation integration in admin sidebar and dashboard cards
- PostgreSQL optimized queries with proper session validation
- Role-based access control (Owner/Admin only)
- Fix alphabetical ordering of module aliases across all files
- Refactor nested function in update_user_status to reduce complexity
- Add implicit try-rescue pattern instead of explicit try blocks
- Improve module aliasing for better readability
- Remove trailing whitespace from test files
- Optimize PubSub event broadcasting for better error handling
These changes resolve all Credo warnings and improve maintainability
without affecting existing functionality.
Add automatic session termination when user roles are modified to ensure
permissions are updated immediately and prevent stale cached roles in user sessions.
- Add log_out_user_from_all_sessions/1 to PhoenixKitWeb.Users.Auth
- Add delete_all_user_session_tokens/1 and get_all_user_session_tokens/1 to Auth context
- Modify assign_role_internal/3, remove_role/2, and sync_user_roles/2 to trigger logout
- Force re-authentication after role changes for security
- Broadcast LiveView session disconnects to active user sessions
- Update role assignment tests to reflect function signature changes
This ensures role changes take effect immediately across all user sessions
and devices without requiring manual re-login prompts.
@timujinnetimujinne reopened this Sep 2, 2025
@ddon

ddon commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

please fix conflicts first

@ddonddon closed this Sep 2, 2025
ddon pushed a commit that referenced this pull request Nov 12, 2025
…cks-011CV2SzTHE9yZpyn9EB8fKg
Add event duplication checks for all SQS processor event types
ddon pushed a commit that referenced this pull request Nov 12, 2025
This merge brings in the latest changes from dev (V16-V21 migrations) and adds V22 migration with additional email system improvements.
## What's New in V22
### Database Schema Enhancements
- Add aws_message_id field to phoenix_kit_email_logs (nullable, unique when present)
- Add bounced_at, complained_at, opened_at, clicked_at timestamps to email_logs
- Add partial unique index on aws_message_id (WHERE aws_message_id IS NOT NULL)
- Add composite index (message_id, aws_message_id) for fast correlation
- Add composite index (email_log_id, event_type) for 10-100x faster duplicate checks
### New Tables
- phoenix_kit_email_orphaned_events - Track SQS events without matching logs
- phoenix_kit_email_metrics - Track system metrics (extraction rates, placeholder logs)
### Documentation
- Add comprehensive Message ID Strategy documentation in EmailLog module
- Explain dual ID system: message_id (internal) vs aws_message_id (provider)
- Document workflow and search priority for event correlation
## Changes from Dev Branch
The dev branch already includes many improvements that were originally planned:
- ✅ Duplicate event checks for ALL event types (PR #5)
- ✅ Template variable validation (PR #8)
- ✅ RateLimiter stub function implementations
- ✅ AWS message_id extraction improvements (PR #7)
- ✅ Placeholder email log handling (PR #6)
## Migration Path
Run `mix phoenix_kit.update` to apply V16-V22 migrations in sequence.
## Database Constraints
- message_id: UNIQUE NOT NULL (existing)
- aws_message_id: PARTIAL UNIQUE WHERE aws_message_id IS NOT NULL (new)
- Composite indexes for faster searches and event deduplication
## Backward Compatibility
All changes are backward compatible:
- Existing logs work with both message_id strategies
- New fields are nullable
- Indexes use create_if_not_exists for idempotency
ddon pushed a commit that referenced this pull request May 12, 2026
Code (PR #537 review items addressed):
- #1 BUG-MEDIUM: wrap `Annotations.delete/1` in `Repo.transaction/1` so
comment-cascade + annotation-delete are atomic. Extracted into
`delete_in_transaction/1` to keep the body flat (credo depth).
- #2 BUG-MEDIUM: sweep stale `resource_type = "annotation"` claims
across 3 moduledocs (annotation.ex, v115.ex, etcher_adapter.ex). The
implementation anchors comments to the file with
`metadata.annotation_uuid` — docs now match reality.
- #5 BUG-LOW: narrow `delete_linked_comments` rescue to expected
exception classes ([DBConnection.OwnershipError, Postgrex.Error,
ArgumentError]) so logic bugs surface instead of being swallowed.
- #11 IMPROVEMENT-LOW: drop `normalize/1` — `Ecto.Changeset.cast/3`
handles both atom- and string-keyed maps natively; the helper added
silent failure-mode risk on typo'd keys.
- #12 IMPROVEMENT-LOW: drop in-repo `Code.ensure_loaded?(PhoenixKit.Annotations)`
guard in MediaBrowser — Annotations is a core module, can't be
missing.
- #19 NITPICK: drop `PhoenixKit.Modules.Storage` from
AnnotationComposer's `@compile no_warn_undefined` (it's core, not
optional — rename should fail loudly).
- #20 NITPICK: simplify `AnnotationComposerPosition.destroyed` guard.
- #21 NITPICK: fix misleading "Etcher's bootstrap uses `||` to preserve
pre-existing slots" comment — PhoenixKit's JS owns the slots.
- #8 IMPROVEMENT-MEDIUM: gettext-wrap ~17 user-facing strings in
AnnotationComposer (flash messages + heex literals + ARIA labels).
Credo / dialyzer:
- Alias `PhoenixKit.Annotations`, `PhoenixKit.Modules.Storage`,
`PhoenixKit.Modules.Storage.EtcherAdapter`, `Storage.File` so the
six "nested modules could be aliased" findings clear.
- Convert `first_attachment_thumbnail/1`'s single-clause `with` to
`case` (credo readability).
- Add PhoenixKitComments-targeted entries to .dialyzer_ignore.exs for
the annotations context + composer (optional sibling package,
guarded at runtime).
- mix.lock picks up `etcher 0.1.0` via deps.get.
mix precommit: compile → format → credo --strict → dialyzer all clean.
Deferred to original author (Alex): #3 (race), #4 (upload rollback),
#6 (authz), #7 (schema-as-source), #9 (geometry validation), #10
(configurable component id), #13/#14 (locale-aware date + traverse_errors),
plus cosmetics #15-18, #22, #23. Disposition table in CLAUDE_REVIEW.md
updated separately.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request May 12, 2026
Code (PR #538#1 — carry-over from PR #536 follow-up):
- V114 down SQL: switch the collision-suffix source from
`substring(uuid::text from 1 for 8)` (UUIDv7 timestamp prefix — same
millisecond ⇒ identical prefix ⇒ duplicate suffixed keys when two+
rows collide on (provider, name)) to `substring(uuid::text from 25
for 8)` (the post-variant random tail, 32 bits of entropy ⇒ 1-in-4B
collision probability per pair). Mirrored in `run_down!` in
`v114_test.exs` since the test duplicates the SQL.
- V114 moduledoc updated to spell out the suffix source and why the
timestamp prefix was wrong.
The fix is forward-compat: systems that already ran V114.down get the
old (potentially-collided) keys; fresh installs and any future
rollback get the corrected behavior.
Docs (PR #538#6):
- AGENTS.md TODO entry for `<.draggable_list>` test coverage widened
to call out the new `:sortable_handle` axis: three branches
(`:draggable=false`, `:draggable=true + sortable_handle=nil`,
`:draggable=true + sortable_handle=".pk-drag-handle"`).
Plus a one-line `mix format` normalization in V116 (multi-line
`execute(...)` collapsed to single line).
mix precommit: compile → format → credo --strict (0 findings) →
dialyzer (160 errors all skipped) clean.
Deferred to maintainer: #2 / #3 / #5 (cosmetics on deployed
migrations), #4 (DB-level self-loop CHECK — needs a V117), #7
(`sortable_handle` typo safety — design call on boolean shape vs
JS warning).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request May 17, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@timujinne@ddon