Commit graph

234 commits

Author SHA1 Message Date
aa0e7f3d05
help update 2026-02-04 17:56:48 -06:00
6aab59dcf5
refactor: centralize LiveView access control checks
Extract duplicate access control logic from multiple LiveView files into
a reusable AccessControl helper module.

**Changes:**
- NEW: lib/towerops_web/live/helpers/access_control.ex
- NEW: test/towerops_web/live/helpers/access_control_test.exs
- Refactor device_live/index.ex to use AccessControl.verify_site_access/2
  and verify_device_access/2
- Refactor device_live/form.ex to use AccessControl.verify_device_access/2
- Refactor alert_live/index.ex to use AccessControl.verify_alert_access/2
- Refactor device_live/show.ex to use AccessControl.verify_device_access/2
- Remove unused Repo aliases from refactored files

**Benefits:**
- Reduces code duplication across 7+ locations
- Centralizes security-critical access checks
- Improves testability (helper module has >90% coverage)
- Consistent error handling across all LiveViews

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-04 17:51:05 -06:00
6689eb27b4
prevent poller fallback when assigned poller is selected 2026-02-04 16:24:19 -06:00
8382b5df6a
make devices site optional and many test fix 2026-02-04 15:05:42 -06:00
1a054fd598
make sites optional 2026-02-04 13:05:32 -06:00
4ef4f4fbf6
handle exceptions gracefully on api endpoints 2026-02-04 12:18:14 -06:00
c93144cc37
snmp v3 support 2026-02-04 12:02:38 -06:00
3583624e0d
fix: prevent nil boolean error in device edit page
Fixed production bug where visiting the edit page for a device with no
SNMP discovery data would crash with "expected boolean on left-side of
'and', got: nil" error.

The mikrotik_device?/1 function was using && operator which returns nil
when device.snmp_device is nil, instead of returning false. The template
conditional on line 455 requires a proper boolean value.

Changed from:
  device.snmp_device && (...)

To:
  not is_nil(device.snmp_device) and (...)

This ensures the function always returns a boolean (true/false) instead
of potentially returning nil.

Added regression test to verify the page renders correctly when a device
has no SNMP discovery data yet.

Fixes: https://app.honeybadger.io/projects/136860/faults/127120431
2026-02-03 15:32:51 -06:00
f6509cac08
more tests 2026-02-03 15:27:05 -06:00
3276a1cd8c
fix user session controller test
Update email input ID assertion to match actual template implementation
2026-02-03 13:42:24 -06:00
50257dbe68
more tests 2026-02-03 13:20:33 -06:00
88d549cd92
more tests 2026-02-03 12:03:54 -06:00
b78a40555c
more tests 2026-02-03 11:16:43 -06:00
8667d6a288
more tests 2026-02-03 11:02:38 -06:00
ec5c98781f
fix org test 2026-02-03 10:45:58 -06:00
086085156f
more tests 2026-02-03 10:43:30 -06:00
13b3810010
more tests 2026-02-03 10:28:39 -06:00
1ce3763e5f
more tests 2026-02-03 10:19:56 -06:00
89a076fb67
feat: migrate equipment features to gettext and fix sudo mode tests
Migrates all equipment-related flash messages to gettext for internationalization:
- DeviceLive.Index: device discovery, reordering, error messages
- DeviceLive.Show: backup messages, permission errors
- DeviceLive.Form: device CRUD operations
- AlertLive.Index: alert acknowledgment messages
- SiteLive.Show: site discovery messages
- SiteLive.Form: site CRUD and SNMP/agent propagation

Fixes sudo mode test suite issues:
- Updates Accounts.sudo_mode?/2 test to check last_sudo_at instead of authenticated_at
- Adds register_and_log_in_user_with_sudo/1 helper to ConnCase
- Fixes UserAuth sudo mode tests to use session-based authentication
- Updates MyData tests to use sudo mode (now required per router config)
- Removes obsolete UserSettingsLive "without sudo mode" test
- Fixes grant_sudo_mode/1 DateTime truncation to seconds

All equipment module tests passing. Ready for Phase 3 (Admin Features).
2026-02-02 12:41:58 -06:00
bd6dad85e1
purge more passkey and gettext updates 2026-02-02 10:20:59 -06:00
6c8e670dae
docs: add gettext internationalization design
- Add comprehensive i18n design document with domain-based organization
  (default, errors, auth, equipment, admin, emails domains)
- Document helper functions, implementation patterns, and migration workflow
- Fix multiple test suite issues:
  * user_settings_live_test.exs: Update all tests to match current UI structure
    - Fix user.name references (use first_name/last_name)
    - Fix TOTP device creation (use create_totp_device/2)
    - Update tab URLs and form IDs
    - Update tab names (Account, API, Notifications)
    - Remove obsolete tabs (Organizations, Activity)
    - Fix password tests (pattern match redirect without flash token)
    - Update sudo mode behavior
  * account_data_controller_test.exs: Fix user profile assertions
  * rate_limit_test.exs: Fix unused variable warning
  * settings_live_test.exs: Fix organization form validation test
2026-02-02 09:33:01 -06:00
f938b263cd
Mikrotik backup and gettext start 2026-02-02 09:11:22 -06:00
bcd2570b10
user settings test update 2026-02-01 15:02:35 -06:00
a66aec675e Merge branch 'gmcintire/user-first-last-name' into 'main'
Replace single name field with first_name and last_name

See merge request towerops/towerops!3
2026-02-01 15:00:24 -06:00
e46ecbfca2 Replace single name field with first_name and last_name 2026-02-01 15:00:23 -06:00
91517aa934 Merge branch 'gmcintire/security-audit' into 'main'
Add rate limiting to auth and API endpoints using Hammer

See merge request towerops/towerops!2
2026-02-01 14:59:54 -06:00
02833d0b44 Add rate limiting to auth and API endpoints using Hammer 2026-02-01 14:59:54 -06:00
f0d6ae42d0
feat: update UserAuth to redirect to sudo verify page 2026-02-01 14:58:07 -06:00
9ff9c4ddc8
fix: address UserSudoController critical issues
Critical fixes:
- Renamed controller actions to follow Phoenix conventions (verify→new, create→verify)
- Added sudo mode check in GET action using last_sudo_at timestamp
- Added TOTP enrollment check in GET action with redirect
- Changed default return path from /orgs to /users/settings
- Updated route paths from /users/sudo/verify to /users/sudo-verify (dash separator)
- Added success flash message "Identity verified."

Implementation details:
- new/2 (GET): Checks recently_verified_sudo?/1 helper that examines last_sudo_at
  instead of authenticated_at to distinguish sudo verification from regular login
- verify/2 (POST): Adds info flash and defaults to /users/settings
- recently_verified_sudo?/1: Private helper checking last_sudo_at within 10 minutes
- Updated all routes, templates, and tests to use new paths and action names

Tests:
- Added tests for already-in-sudo-mode redirect behavior
- Added test for TOTP enrollment requirement
- Updated all test assertions for new route paths and success messages
- All 15 controller tests passing
- Full test suite passing (4076 tests, 0 failures)
2026-02-01 14:45:05 -06:00
264154a3d8
feat: implement sudo mode MFA-only verification controller
- Add UserSudoController with GET and POST /users/sudo/verify routes
- Create verify.html.heex template for TOTP verification form
- Only accept TOTP codes (6 numeric digits), reject recovery codes
- Update grant_sudo_mode to set authenticated_at virtual field
- Exclude /users/sudo paths from return_to overwriting
- Add comprehensive controller tests (12 test cases)
- Verify redirect behavior, error handling, and session management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-01 14:34:17 -06:00
d7234e02a3
fix: improve verify_totp_only validation logic 2026-02-01 14:24:19 -06:00
42565779bc
feat: add Accounts.verify_totp_only/2 function 2026-02-01 14:17:09 -06:00
92350173b0
feat: add audit logging to grant_sudo_mode/1 2026-02-01 14:09:40 -06:00
ada851e7ed
feat: add Accounts.grant_sudo_mode/1 function 2026-02-01 14:02:41 -06:00
2a5622d95a
impersonate fix and change log level for device polling 2026-02-01 13:33:36 -06:00
7ca07010ab
Use detected timezone from session in user registration 2026-02-01 12:18:33 -06:00
c856b2142c
Add timezone validation to reject invalid IANA timezone strings
Prevents invalid timezone values from being stored in the database
by validating against Elixir's time zone database during registration.
2026-02-01 11:56:04 -06:00
0037f18848
Accept timezone parameter in user registration changeset 2026-02-01 11:21:50 -06:00
d9876d8217
Remove misleading duplicate header test from CaptureTimezone
The test incorrectly suggested the plug handles duplicate headers,
but put_req_header replaces values. Cloudflare only sends one
cf-timezone header, making this test unnecessary.
2026-02-01 11:08:12 -06:00
c4e8c70e7d
Add CaptureTimezone plug to extract cf-timezone header 2026-02-01 11:02:57 -06:00
61a06fc11c
Add firmware version tracking system
- Add firmware context module with upsert, query, and logging functions
- Add FirmwareVersionFetcherWorker to fetch MikroTik RSS daily
- Add Oban cron schedules (2 AM dev, 4 AM prod)
- Add version change detection to Discovery module
- Track firmware history with PubSub broadcasts
- All tests passing

Phase 3-5 of firmware tracking implementation complete.
Next: LiveView UI indicators.
2026-02-01 10:46:27 -06:00
d392c2d788
Add VersionComparator module for semantic version comparison
Implements compare/2 and newer?/2 functions for comparing semantic versions.

Parsing rules:
- Supports 0-3 part versions (e.g., '7', '7.14', '7.14.1')
- Strips v/V prefix and whitespace
- Ignores suffixes after hyphen or space
- Pads missing parts with 0
- Invalid versions (4+ parts, non-numeric, negative) fall back to 0.0.0

Part of firmware version tracking feature (Phase 2).
2026-02-01 10:24:13 -06:00
004189aaf9
Add firmware tracking database schema
- Create firmware_releases table to store latest available firmware versions
- Create device_firmware_history table to track version changes over time
- Add FirmwareRelease and DeviceFirmwareHistory Ecto schemas with validations
- Add comprehensive tests for both schemas (23 tests, 100% coverage)

firmware_releases stores one record per vendor/product_line with latest version.
device_firmware_history is append-only audit log of device firmware changes.

Part of firmware version tracking system for MikroTik (extensible to other vendors).
2026-02-01 10:13:16 -06:00
b30f2cf5af
filter more honeybadger alerts, format dates to users time zone, email template cleanup 2026-02-01 09:27:42 -06:00
feed25080c
add HIBP password check 2026-02-01 08:57:01 -06:00
2fab08f5f8
forgot password flow 2026-01-31 17:03:22 -06:00
021c86a130
more tests and fixes 2026-01-31 16:00:07 -06:00
dff9c26905
fix TOTP enrollment with recovery codes 2026-01-31 14:54:44 -06:00
c690827ee0 user setting re-auth redirect hopeful fix 2026-01-31 13:32:26 -06:00
480789c3e2 banner dissmiss and mikrotik version and license 2026-01-31 13:07:09 -06:00