nexus-framework 0.4.2__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/PKG-INFO +1 -1
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/pyproject.toml +1 -1
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/__init__.py +1 -1
- nexus_framework-0.4.4/src/nexus/activitylog/__init__.py +17 -0
- nexus_framework-0.4.4/src/nexus/activitylog/activitylog_service_provider.py +17 -0
- nexus_framework-0.4.4/src/nexus/activitylog/logger.py +124 -0
- nexus_framework-0.4.4/src/nexus/activitylog/models.py +74 -0
- nexus_framework-0.4.4/src/nexus/activitylog/traits.py +86 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/guard.py +26 -9
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/manager.py +12 -12
- nexus_framework-0.4.4/src/nexus/auth/user_provider.py +146 -0
- nexus_framework-0.4.4/src/nexus/console/commands/install_tools.py +436 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/model.py +51 -6
- nexus_framework-0.4.4/src/nexus/exceptions/__init__.py +8 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/__init__.py +2 -0
- nexus_framework-0.4.4/src/nexus/facades/activitylog.py +38 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/exceptions.py +4 -0
- nexus_framework-0.4.4/src/nexus/permissions/__init__.py +20 -0
- nexus_framework-0.4.4/src/nexus/permissions/manager.py +39 -0
- nexus_framework-0.4.4/src/nexus/permissions/middleware.py +69 -0
- nexus_framework-0.4.4/src/nexus/permissions/models.py +147 -0
- nexus_framework-0.4.4/src/nexus/permissions/permission_service_provider.py +17 -0
- nexus_framework-0.4.4/src/nexus/permissions/traits.py +238 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/converters/laravel.py +0 -1
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/standard.py +5 -4
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/web.py +3 -3
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/view/compiler.py +8 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/PKG-INFO +1 -1
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/SOURCES.txt +12 -0
- nexus_framework-0.4.2/src/nexus/auth/user_provider.py +0 -67
- nexus_framework-0.4.2/src/nexus/console/commands/install_tools.py +0 -221
- nexus_framework-0.4.2/src/nexus/exceptions/__init__.py +0 -7
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/README.md +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/setup.cfg +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/application.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/access/gate.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/auth_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/authenticatable.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/hashing.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/guard.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/has_api_tokens.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/migration.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/new_access_token.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/auth/sanctum/personal_access_token.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/cache/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/cache/cache_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/cache/driver.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/cache/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/cache/store.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/config/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/config/repository.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/cli.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/command.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/clear.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/config.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/database.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/db_reverse.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/key_generate.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/make.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/new_command.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/queue.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/route_list.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/schedule.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/serve.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/starter.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/commands/tinker.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/console_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/generators/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/generators/stubs.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/console/kernel.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/container/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/container/container.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/container/exceptions.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/connection.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/database_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/factory.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/migrations/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/migrations/migration.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/migrations/migrator.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/exceptions.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/base.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/belongs_to.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/belongs_to_many.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/has_many.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/relations/has_one.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/models/soft_deletes.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/query/builder.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/schema/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/schema/blueprint.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/schema/schema.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/seeder.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/studio/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/database/studio/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/events/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/events/dispatcher.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/events/event_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/exceptions/exception_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/exceptions/handler.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/app.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/artisan.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/auth.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/cache.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/config.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/date.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/db.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/event.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/facade.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/gate.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/hash.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/inertia.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/log.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/mail.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/notification.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/queue.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/rate_limiter.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/request.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/route.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/schedule.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/schema.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/session.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/storage.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/telescope.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/url.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/validator.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/facades/view.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/filesystem/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/filesystem/driver.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/filesystem/filesystem_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/filesystem/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/foundation/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/foundation/application.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/foundation/provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/foundation/runner.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/foundation/service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/request.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/requests/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/requests/form_request.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/resources/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/resources/json_resource.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/resources/resource_collection.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/response.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/http/uploaded_file.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/helpers.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/inertia.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/inertia_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/lazy.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/inertia/response.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/logging/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/logging/logging_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/logging/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/mail/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/mail/mail_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/mail/mailable.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/mail/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/mail/transport.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/notifications/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/notifications/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/notifications/notification.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/notifications/notification_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/converters/base.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/converters/django.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/converters/flask.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/converters/reverse.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/detector.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/porter/porter_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/py.typed +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/driver.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/job.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/queue_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/queue/worker.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/limiter.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/route.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/router.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/throttle.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/routing/url.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/schedule/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/schedule/event.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/schedule/schedule.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/schedule/schedule_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/security/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/security/cors.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/security/csrf.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/security/headers.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/driver.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/manager.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/session.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/session/session_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/api.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/inertia.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/starters/openapi.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/arr.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/carbon.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/collection.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/dependencies.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/env.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/helpers.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/support/str.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/debugbar.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/entry.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/middleware.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/telescope.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/telescope/telescope_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/client.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/database.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/event_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/log_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/mail_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/notification_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/queue_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/fakes/storage_fake.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/response.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/test_case.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/testing/time.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/validation/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/validation/rule.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/validation/validation_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/validation/validator.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/view/__init__.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/view/factory.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus/view/view_service_provider.py +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/dependency_links.txt +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/entry_points.txt +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/requires.txt +0 -0
- {nexus_framework-0.4.2 → nexus_framework-0.4.4}/src/nexus_framework.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nexus-framework
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: An expressive, batteries-included asynchronous web framework for Python inspired by Laravel.
|
|
5
5
|
Author-email: Nexus Core Team <core@nexus-framework.org>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nexus-framework"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.4"
|
|
8
8
|
description = "An expressive, batteries-included asynchronous web framework for Python inspired by Laravel."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Nexus Activity Log (Audit Trail) Module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from nexus.activitylog.activitylog_service_provider import ActivityLogServiceProvider
|
|
6
|
+
from nexus.activitylog.logger import ActivityLogger, activity
|
|
7
|
+
from nexus.activitylog.models import Activity
|
|
8
|
+
from nexus.activitylog.traits import LogsActivity
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Activity",
|
|
12
|
+
"ActivityLogServiceProvider",
|
|
13
|
+
"ActivityLogger",
|
|
14
|
+
"LogsActivity",
|
|
15
|
+
"activity",
|
|
16
|
+
]
|
|
17
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Nexus Activity Log (Audit Log) Service Provider."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from nexus.activitylog.logger import activity
|
|
6
|
+
from nexus.foundation.provider import ServiceProvider
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ActivityLogServiceProvider(ServiceProvider):
|
|
10
|
+
"""Registers activity logger service in the application container."""
|
|
11
|
+
|
|
12
|
+
def register(self) -> None:
|
|
13
|
+
self.app.singleton("activitylog", lambda _app: activity)
|
|
14
|
+
|
|
15
|
+
def boot(self) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Nexus Fluent Activity Logger."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
from typing import Any, Self
|
|
7
|
+
|
|
8
|
+
from nexus.activitylog.models import Activity
|
|
9
|
+
from nexus.facades.auth import Auth
|
|
10
|
+
from nexus.http.request import Request
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ActivityLogger:
|
|
14
|
+
"""Fluent builder for capturing and saving structured audit activity records."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, log_name: str = "default") -> None:
|
|
17
|
+
self._log_name = log_name
|
|
18
|
+
self._description = ""
|
|
19
|
+
self._subject_type: str | None = None
|
|
20
|
+
self._subject_id: str | int | None = None
|
|
21
|
+
self._causer_type: str | None = None
|
|
22
|
+
self._causer_id: str | int | None = None
|
|
23
|
+
self._properties: dict[str, Any] = {}
|
|
24
|
+
self._event: str | None = None
|
|
25
|
+
self._ip_address: str | None = None
|
|
26
|
+
self._user_agent: str | None = None
|
|
27
|
+
|
|
28
|
+
# Auto-detect currently authenticated user as causer if available
|
|
29
|
+
with contextlib.suppress(Exception):
|
|
30
|
+
user = Auth.guard("web").user()
|
|
31
|
+
if user:
|
|
32
|
+
self.caused_by(user)
|
|
33
|
+
|
|
34
|
+
def use_log(self, log_name: str) -> Self:
|
|
35
|
+
"""Set the log category name."""
|
|
36
|
+
self._log_name = log_name
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
def caused_by(self, causer: Any) -> Self:
|
|
40
|
+
"""Set the actor / causer who performed this action."""
|
|
41
|
+
if causer is None:
|
|
42
|
+
self._causer_type = None
|
|
43
|
+
self._causer_id = None
|
|
44
|
+
elif isinstance(causer, (int, str)):
|
|
45
|
+
self._causer_type = "User"
|
|
46
|
+
self._causer_id = causer
|
|
47
|
+
else:
|
|
48
|
+
self._causer_type = causer.__class__.__name__
|
|
49
|
+
self._causer_id = getattr(causer, "id", None)
|
|
50
|
+
return self
|
|
51
|
+
|
|
52
|
+
def performed_on(self, subject: Any) -> Self:
|
|
53
|
+
"""Set the subject model or entity acted upon."""
|
|
54
|
+
if subject is None:
|
|
55
|
+
self._subject_type = None
|
|
56
|
+
self._subject_id = None
|
|
57
|
+
elif isinstance(subject, (int, str)):
|
|
58
|
+
self._subject_type = "Model"
|
|
59
|
+
self._subject_id = subject
|
|
60
|
+
else:
|
|
61
|
+
self._subject_type = subject.__class__.__name__
|
|
62
|
+
self._subject_id = getattr(subject, "id", None)
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def on(self, subject: Any) -> Self:
|
|
66
|
+
"""Alias for performed_on()."""
|
|
67
|
+
return self.performed_on(subject)
|
|
68
|
+
|
|
69
|
+
def by(self, causer: Any) -> Self:
|
|
70
|
+
"""Alias for caused_by()."""
|
|
71
|
+
return self.caused_by(causer)
|
|
72
|
+
|
|
73
|
+
def event(self, event_name: str) -> Self:
|
|
74
|
+
"""Set the event name (e.g. 'created', 'updated', 'deleted', 'login')."""
|
|
75
|
+
self._event = event_name
|
|
76
|
+
return self
|
|
77
|
+
|
|
78
|
+
def with_properties(self, properties: dict[str, Any]) -> Self:
|
|
79
|
+
"""Merge additional context properties into the activity payload."""
|
|
80
|
+
self._properties.update(properties)
|
|
81
|
+
return self
|
|
82
|
+
|
|
83
|
+
def with_property(self, key: str, value: Any) -> Self:
|
|
84
|
+
"""Add a single property to the payload."""
|
|
85
|
+
self._properties[key] = value
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def with_request(self, request: Request) -> Self:
|
|
89
|
+
"""Extract IP address and User-Agent from incoming HTTP request."""
|
|
90
|
+
client = getattr(request, "client", None)
|
|
91
|
+
if client and isinstance(client, tuple):
|
|
92
|
+
self._ip_address = client[0]
|
|
93
|
+
self._user_agent = request.headers.get("user-agent")
|
|
94
|
+
return self
|
|
95
|
+
|
|
96
|
+
def log(self, description: str) -> Activity:
|
|
97
|
+
"""Commit and persist the activity record to the database."""
|
|
98
|
+
self._description = description
|
|
99
|
+
|
|
100
|
+
payload: dict[str, Any] = {
|
|
101
|
+
"log_name": self._log_name,
|
|
102
|
+
"description": self._description,
|
|
103
|
+
"subject_type": self._subject_type,
|
|
104
|
+
"subject_id": self._subject_id,
|
|
105
|
+
"causer_type": self._causer_type,
|
|
106
|
+
"causer_id": self._causer_id,
|
|
107
|
+
"properties": self._properties,
|
|
108
|
+
"event": self._event,
|
|
109
|
+
"ip_address": self._ip_address,
|
|
110
|
+
"user_agent": self._user_agent,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
activity_record = Activity(payload)
|
|
115
|
+
activity_record.save()
|
|
116
|
+
return activity_record
|
|
117
|
+
except Exception: # noqa: BLE001
|
|
118
|
+
# Fallback return in-memory instance
|
|
119
|
+
return Activity(payload)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def activity(log_name: str = "default") -> ActivityLogger:
|
|
123
|
+
"""Entry point to create a new fluent ActivityLogger."""
|
|
124
|
+
return ActivityLogger(log_name=log_name)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Nexus Activity Log (Audit Log) Active Record Model."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import json
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from nexus.database.models import Model
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Activity(Model):
|
|
13
|
+
"""Represents an audit trail event recording actions, causers, and subjects."""
|
|
14
|
+
|
|
15
|
+
table = "activity_log"
|
|
16
|
+
fillable = [
|
|
17
|
+
"log_name",
|
|
18
|
+
"description",
|
|
19
|
+
"subject_type",
|
|
20
|
+
"subject_id",
|
|
21
|
+
"causer_type",
|
|
22
|
+
"causer_id",
|
|
23
|
+
"properties",
|
|
24
|
+
"event",
|
|
25
|
+
"ip_address",
|
|
26
|
+
"user_agent",
|
|
27
|
+
]
|
|
28
|
+
casts = {
|
|
29
|
+
"properties": "json",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def changes(self) -> dict[str, Any]:
|
|
33
|
+
"""Return before/after property changes if present."""
|
|
34
|
+
props = self.properties or {}
|
|
35
|
+
if isinstance(props, str):
|
|
36
|
+
try:
|
|
37
|
+
props = json.loads(props)
|
|
38
|
+
except Exception: # noqa: BLE001
|
|
39
|
+
props = {}
|
|
40
|
+
return {
|
|
41
|
+
"attributes": props.get("attributes", {}),
|
|
42
|
+
"old": props.get("old", {}),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def causer(self) -> Any:
|
|
46
|
+
"""Resolve the causer model instance if available."""
|
|
47
|
+
if not self.causer_type or not self.causer_id:
|
|
48
|
+
return None
|
|
49
|
+
cls = self._resolve_model_class(self.causer_type)
|
|
50
|
+
return cls.find(self.causer_id) if cls and hasattr(cls, "find") else None
|
|
51
|
+
|
|
52
|
+
def subject(self) -> Any:
|
|
53
|
+
"""Resolve the subject model instance if available."""
|
|
54
|
+
if not self.subject_type or not self.subject_id:
|
|
55
|
+
return None
|
|
56
|
+
cls = self._resolve_model_class(self.subject_type)
|
|
57
|
+
return cls.find(self.subject_id) if cls and hasattr(cls, "find") else None
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def _resolve_model_class(type_name: str) -> type | None:
|
|
61
|
+
import importlib
|
|
62
|
+
|
|
63
|
+
candidates = [
|
|
64
|
+
f"app.models.{type_name.lower()}",
|
|
65
|
+
f"app.models.{type_name}",
|
|
66
|
+
"app.models",
|
|
67
|
+
]
|
|
68
|
+
for mod_path in candidates:
|
|
69
|
+
with contextlib.suppress(Exception):
|
|
70
|
+
mod = importlib.import_module(mod_path)
|
|
71
|
+
if hasattr(mod, type_name):
|
|
72
|
+
cls: type = getattr(mod, type_name)
|
|
73
|
+
return cls
|
|
74
|
+
return None
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Nexus LogsActivity Active Record Model Trait/Mixin."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from nexus.activitylog.logger import activity
|
|
8
|
+
from nexus.activitylog.models import Activity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LogsActivity:
|
|
12
|
+
"""Active Record model mixin providing automated lifecycle audit logging."""
|
|
13
|
+
|
|
14
|
+
activity_log_name: str = "default"
|
|
15
|
+
activity_log_attributes: list[str] | str = "*"
|
|
16
|
+
|
|
17
|
+
def get_log_name(self) -> str:
|
|
18
|
+
"""Return the log name for this model."""
|
|
19
|
+
return getattr(self, "activity_log_name", "default")
|
|
20
|
+
|
|
21
|
+
def get_activity_log_attributes(self) -> dict[str, Any]:
|
|
22
|
+
"""Extract attributes configured for audit recording."""
|
|
23
|
+
attrs = getattr(self, "_attributes", {}) or getattr(self, "attributes", {})
|
|
24
|
+
if self.activity_log_attributes == "*":
|
|
25
|
+
# Exclude sensitive keys by default
|
|
26
|
+
return {k: v for k, v in attrs.items() if k not in ("password", "remember_token")}
|
|
27
|
+
allowed = set(self.activity_log_attributes)
|
|
28
|
+
return {k: v for k, v in attrs.items() if k in allowed}
|
|
29
|
+
|
|
30
|
+
def log_created_activity(self) -> Activity:
|
|
31
|
+
"""Record a creation event."""
|
|
32
|
+
model_name = self.__class__.__name__
|
|
33
|
+
model_id = getattr(self, "id", None)
|
|
34
|
+
return (
|
|
35
|
+
activity(self.get_log_name())
|
|
36
|
+
.performed_on(self)
|
|
37
|
+
.event("created")
|
|
38
|
+
.with_properties({"attributes": self.get_activity_log_attributes()})
|
|
39
|
+
.log(f"Created {model_name} #{model_id}" if model_id else f"Created {model_name}")
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def log_updated_activity(self, old_attributes: dict[str, Any] | None = None) -> Activity:
|
|
43
|
+
"""Record an update event with before/after diffs."""
|
|
44
|
+
model_name = self.__class__.__name__
|
|
45
|
+
model_id = getattr(self, "id", None)
|
|
46
|
+
new_attrs = self.get_activity_log_attributes()
|
|
47
|
+
|
|
48
|
+
props: dict[str, Any] = {"attributes": new_attrs}
|
|
49
|
+
if old_attributes:
|
|
50
|
+
props["old"] = {k: old_attributes.get(k) for k in new_attrs if old_attributes.get(k) != new_attrs.get(k)}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
activity(self.get_log_name())
|
|
54
|
+
.performed_on(self)
|
|
55
|
+
.event("updated")
|
|
56
|
+
.with_properties(props)
|
|
57
|
+
.log(f"Updated {model_name} #{model_id}" if model_id else f"Updated {model_name}")
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def log_deleted_activity(self) -> Activity:
|
|
61
|
+
"""Record a deletion event."""
|
|
62
|
+
model_name = self.__class__.__name__
|
|
63
|
+
model_id = getattr(self, "id", None)
|
|
64
|
+
return (
|
|
65
|
+
activity(self.get_log_name())
|
|
66
|
+
.performed_on(self)
|
|
67
|
+
.event("deleted")
|
|
68
|
+
.with_properties({"attributes": self.get_activity_log_attributes()})
|
|
69
|
+
.log(f"Deleted {model_name} #{model_id}" if model_id else f"Deleted {model_name}")
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def activities(self) -> list[Activity]:
|
|
73
|
+
"""Retrieve all activity log entries for this model instance."""
|
|
74
|
+
model_name = self.__class__.__name__
|
|
75
|
+
model_id = getattr(self, "id", None)
|
|
76
|
+
if not model_id:
|
|
77
|
+
return []
|
|
78
|
+
try:
|
|
79
|
+
return list(
|
|
80
|
+
Activity.where("subject_type", model_name)
|
|
81
|
+
.where("subject_id", model_id)
|
|
82
|
+
.latest()
|
|
83
|
+
.get()
|
|
84
|
+
)
|
|
85
|
+
except Exception: # noqa: BLE001
|
|
86
|
+
return []
|
|
@@ -77,11 +77,25 @@ class SessionGuard(StatefulGuard):
|
|
|
77
77
|
) -> None:
|
|
78
78
|
self.name = name
|
|
79
79
|
self.provider = provider
|
|
80
|
-
self.
|
|
80
|
+
self._session = session
|
|
81
81
|
self.request = request
|
|
82
82
|
self._user: Authenticatable | None = None
|
|
83
83
|
self._logged_out: bool = False
|
|
84
84
|
|
|
85
|
+
@property
|
|
86
|
+
def session(self) -> Session:
|
|
87
|
+
"""Get active session (from request context if available, otherwise fallback)."""
|
|
88
|
+
from nexus.facades.session import Session as SessionFacade
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
return SessionFacade._context_var.get()
|
|
92
|
+
except LookupError:
|
|
93
|
+
return self._session
|
|
94
|
+
|
|
95
|
+
@session.setter
|
|
96
|
+
def session(self, value: Session) -> None:
|
|
97
|
+
self._session = value
|
|
98
|
+
|
|
85
99
|
def get_name(self) -> str:
|
|
86
100
|
"""Get session storage key for this guard."""
|
|
87
101
|
return f"login_{self.name}_id"
|
|
@@ -91,20 +105,22 @@ class SessionGuard(StatefulGuard):
|
|
|
91
105
|
if self._logged_out:
|
|
92
106
|
return None
|
|
93
107
|
|
|
94
|
-
if self._user is not None:
|
|
95
|
-
return self._user
|
|
96
|
-
|
|
97
108
|
user_id = self.session.get(self.get_name())
|
|
98
|
-
if user_id is
|
|
99
|
-
self._user =
|
|
109
|
+
if user_id is None:
|
|
110
|
+
self._user = None
|
|
111
|
+
return None
|
|
100
112
|
|
|
113
|
+
if self._user is not None and getattr(self._user, "id", None) == user_id:
|
|
114
|
+
return self._user
|
|
115
|
+
|
|
116
|
+
self._user = self.provider.retrieve_by_id(user_id)
|
|
101
117
|
return self._user
|
|
102
118
|
|
|
103
119
|
def id(self) -> Any | None:
|
|
104
120
|
"""Get the authenticated user's ID."""
|
|
105
121
|
user = self.user()
|
|
106
122
|
if user is not None:
|
|
107
|
-
return user.get_auth_identifier()
|
|
123
|
+
return user.get_auth_identifier() if hasattr(user, "get_auth_identifier") else getattr(user, "id", None)
|
|
108
124
|
return self.session.get(self.get_name())
|
|
109
125
|
|
|
110
126
|
def check(self) -> bool:
|
|
@@ -131,9 +147,10 @@ class SessionGuard(StatefulGuard):
|
|
|
131
147
|
|
|
132
148
|
return False
|
|
133
149
|
|
|
134
|
-
def login(self, user: Authenticatable, remember: bool = False) -> None:
|
|
150
|
+
def login(self, user: Authenticatable | Any, remember: bool = False) -> None:
|
|
135
151
|
"""Log user into session."""
|
|
136
|
-
|
|
152
|
+
user_id = user.get_auth_identifier() if hasattr(user, "get_auth_identifier") else getattr(user, "id", None)
|
|
153
|
+
self.session.put(self.get_name(), user_id)
|
|
137
154
|
self.session.regenerate()
|
|
138
155
|
self._user = user
|
|
139
156
|
self._logged_out = False
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import contextlib
|
|
5
6
|
from collections.abc import Callable
|
|
6
7
|
from typing import TYPE_CHECKING, Any
|
|
7
8
|
|
|
8
9
|
from nexus.auth.guard import Guard, SessionGuard, TokenGuard
|
|
9
10
|
from nexus.auth.hashing import HashManager
|
|
10
|
-
from nexus.auth.user_provider import EloquentUserProvider, UserProvider
|
|
11
|
+
from nexus.auth.user_provider import EloquentUserProvider, UserProvider, resolve_model_class
|
|
11
12
|
|
|
12
13
|
if TYPE_CHECKING:
|
|
13
14
|
from nexus.auth.authenticatable import Authenticatable
|
|
@@ -72,19 +73,18 @@ class AuthManager:
|
|
|
72
73
|
hasher = self.app.make("hash") if self.app.has("hash") else HashManager(self.app)
|
|
73
74
|
|
|
74
75
|
if driver == "eloquent" and model:
|
|
76
|
+
with contextlib.suppress(Exception):
|
|
77
|
+
resolved = resolve_model_class(model)
|
|
78
|
+
return EloquentUserProvider(resolved, hasher)
|
|
75
79
|
return EloquentUserProvider(model, hasher)
|
|
76
80
|
|
|
77
|
-
# Fallback to User model from app.models.user if available
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
except (ImportError, ModuleNotFoundError):
|
|
85
|
-
pass
|
|
86
|
-
|
|
87
|
-
return EloquentUserProvider(model or UserProvider, hasher) # type: ignore[arg-type]
|
|
81
|
+
# Fallback to User model from app.models.User or app.models.user if available
|
|
82
|
+
for cand in ["app.models.User.User", "app.models.User", "app.models.user.User", "app.models.user"]:
|
|
83
|
+
with contextlib.suppress(Exception):
|
|
84
|
+
resolved = resolve_model_class(cand)
|
|
85
|
+
return EloquentUserProvider(resolved, hasher)
|
|
86
|
+
|
|
87
|
+
return EloquentUserProvider(model or "app.models.User.User", hasher)
|
|
88
88
|
|
|
89
89
|
def extend(self, driver: str, callback: Callable[..., Guard]) -> None:
|
|
90
90
|
"""Register a custom guard driver."""
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Nexus User Providers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import importlib
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
9
|
+
|
|
10
|
+
from nexus.auth.authenticatable import Authenticatable
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from nexus.auth.hashing import Hasher
|
|
14
|
+
from nexus.database.models.model import Model
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def resolve_model_class(model: type[Model] | str) -> type[Model]:
|
|
18
|
+
"""Resolve a model class from either a type reference or a dotted string path."""
|
|
19
|
+
if isinstance(model, type):
|
|
20
|
+
return model
|
|
21
|
+
|
|
22
|
+
if not isinstance(model, str) or not model.strip():
|
|
23
|
+
raise ValueError(f"Invalid model class reference: {model!r}")
|
|
24
|
+
|
|
25
|
+
model_str = model.strip()
|
|
26
|
+
|
|
27
|
+
# 1. Dotted path resolution (e.g. "app.models.User.User" or "app.models.User")
|
|
28
|
+
if "." in model_str:
|
|
29
|
+
mod_name, cls_name = model_str.rsplit(".", 1)
|
|
30
|
+
with contextlib.suppress(Exception):
|
|
31
|
+
mod = importlib.import_module(mod_name)
|
|
32
|
+
if hasattr(mod, cls_name):
|
|
33
|
+
cls = getattr(mod, cls_name)
|
|
34
|
+
if isinstance(cls, type):
|
|
35
|
+
return cls
|
|
36
|
+
|
|
37
|
+
# Try whole path as module, where module has class with the trailing name
|
|
38
|
+
with contextlib.suppress(Exception):
|
|
39
|
+
mod = importlib.import_module(model_str)
|
|
40
|
+
target_name = model_str.split(".")[-1]
|
|
41
|
+
if hasattr(mod, target_name):
|
|
42
|
+
cls = getattr(mod, target_name)
|
|
43
|
+
if isinstance(cls, type):
|
|
44
|
+
return cls
|
|
45
|
+
|
|
46
|
+
# 2. Convention-based candidate paths
|
|
47
|
+
clean_name = model_str.split(".")[-1]
|
|
48
|
+
candidates = [
|
|
49
|
+
f"app.models.{clean_name}.{clean_name}",
|
|
50
|
+
f"app.models.{clean_name.lower()}.{clean_name}",
|
|
51
|
+
f"app.models.{clean_name}",
|
|
52
|
+
f"app.models.{clean_name.lower()}",
|
|
53
|
+
"app.models.User.User",
|
|
54
|
+
"app.models.user.User",
|
|
55
|
+
"app.models.User",
|
|
56
|
+
"app.models.user",
|
|
57
|
+
]
|
|
58
|
+
for cand in candidates:
|
|
59
|
+
with contextlib.suppress(Exception):
|
|
60
|
+
if "." in cand:
|
|
61
|
+
m_name, c_name = cand.rsplit(".", 1)
|
|
62
|
+
mod = importlib.import_module(m_name)
|
|
63
|
+
if hasattr(mod, c_name):
|
|
64
|
+
cls = getattr(mod, c_name)
|
|
65
|
+
if isinstance(cls, type):
|
|
66
|
+
return cls
|
|
67
|
+
else:
|
|
68
|
+
mod = importlib.import_module(cand)
|
|
69
|
+
if hasattr(mod, clean_name):
|
|
70
|
+
cls = getattr(mod, clean_name)
|
|
71
|
+
if isinstance(cls, type):
|
|
72
|
+
return cls
|
|
73
|
+
|
|
74
|
+
raise ValueError(f"Could not resolve model class from reference [{model_str}].")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class UserProvider(ABC):
|
|
78
|
+
"""Abstract Base Class for user credential resolution."""
|
|
79
|
+
|
|
80
|
+
@abstractmethod
|
|
81
|
+
def retrieve_by_id(self, identifier: Any) -> Authenticatable | None:
|
|
82
|
+
"""Retrieve a user by their unique primary identifier."""
|
|
83
|
+
raise NotImplementedError
|
|
84
|
+
|
|
85
|
+
@abstractmethod
|
|
86
|
+
def retrieve_by_credentials(self, credentials: dict[str, Any]) -> Authenticatable | None:
|
|
87
|
+
"""Retrieve a user by the given credentials (e.g. email/username)."""
|
|
88
|
+
raise NotImplementedError
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def validate_credentials(self, user: Authenticatable, credentials: dict[str, Any]) -> bool:
|
|
92
|
+
"""Validate a user against the given credentials (e.g. password check)."""
|
|
93
|
+
raise NotImplementedError
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class EloquentUserProvider(UserProvider):
|
|
97
|
+
"""User provider backed by an Eloquent Model."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, model_class: type[Model] | str, hasher: Hasher) -> None:
|
|
100
|
+
self._model_class = model_class
|
|
101
|
+
self.hasher = hasher
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def model_class(self) -> type[Model]:
|
|
105
|
+
"""Dynamically resolve the model class if configured as a string."""
|
|
106
|
+
if isinstance(self._model_class, type):
|
|
107
|
+
return self._model_class
|
|
108
|
+
resolved = resolve_model_class(self._model_class)
|
|
109
|
+
self._model_class = resolved
|
|
110
|
+
return resolved
|
|
111
|
+
|
|
112
|
+
@model_class.setter
|
|
113
|
+
def model_class(self, value: type[Model] | str) -> None:
|
|
114
|
+
self._model_class = value
|
|
115
|
+
|
|
116
|
+
def retrieve_by_id(self, identifier: Any) -> Authenticatable | None:
|
|
117
|
+
"""Find model instance by primary key."""
|
|
118
|
+
user = self.model_class.find(identifier)
|
|
119
|
+
return user if isinstance(user, Authenticatable) or user is not None else None # type: ignore[return-value]
|
|
120
|
+
|
|
121
|
+
def retrieve_by_credentials(self, credentials: dict[str, Any]) -> Authenticatable | None:
|
|
122
|
+
"""Query user model by non-password credentials."""
|
|
123
|
+
if not credentials:
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
query = self.model_class.query()
|
|
127
|
+
for key, value in credentials.items():
|
|
128
|
+
if key == "password":
|
|
129
|
+
continue
|
|
130
|
+
query.where(key, value)
|
|
131
|
+
|
|
132
|
+
user = query.first()
|
|
133
|
+
return user # type: ignore[return-value]
|
|
134
|
+
|
|
135
|
+
def validate_credentials(self, user: Authenticatable | Any, credentials: dict[str, Any]) -> bool:
|
|
136
|
+
"""Check password against user's hashed password."""
|
|
137
|
+
plain_password = credentials.get("password")
|
|
138
|
+
if not plain_password or not isinstance(plain_password, str):
|
|
139
|
+
return False
|
|
140
|
+
|
|
141
|
+
if hasattr(user, "get_auth_password"):
|
|
142
|
+
hashed_password = user.get_auth_password()
|
|
143
|
+
else:
|
|
144
|
+
hashed_password = str(getattr(user, "password", ""))
|
|
145
|
+
|
|
146
|
+
return self.hasher.check(plain_password, hashed_password)
|