Marwan Alwali 84c1fb798e update
2025-09-08 19:52:52 +03:00

746 lines
27 KiB
Python

# Generated by Django 5.2.6 on 2025-09-08 07:28
import django.contrib.auth.models
import django.contrib.auth.validators
import django.core.validators
import django.db.models.deletion
import django.utils.timezone
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]
operations = [
migrations.CreateModel(
name="PasswordHistory",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"password_hash",
models.CharField(help_text="Hashed password", max_length=128),
),
("created_at", models.DateTimeField(auto_now_add=True)),
],
options={
"verbose_name": "Password History",
"verbose_name_plural": "Password History",
"db_table": "accounts_password_history",
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="SocialAccount",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"provider",
models.CharField(
choices=[
("GOOGLE", "Google"),
("MICROSOFT", "Microsoft"),
("APPLE", "Apple"),
("FACEBOOK", "Facebook"),
("LINKEDIN", "LinkedIn"),
("GITHUB", "GitHub"),
("OKTA", "Okta"),
("SAML", "SAML"),
("LDAP", "LDAP"),
],
max_length=50,
),
),
(
"provider_id",
models.CharField(help_text="Provider user ID", max_length=200),
),
(
"provider_email",
models.EmailField(
blank=True,
help_text="Email from provider",
max_length=254,
null=True,
),
),
(
"display_name",
models.CharField(
blank=True,
help_text="Display name from provider",
max_length=200,
null=True,
),
),
(
"profile_url",
models.URLField(
blank=True, help_text="Profile URL from provider", null=True
),
),
(
"avatar_url",
models.URLField(
blank=True, help_text="Avatar URL from provider", null=True
),
),
(
"access_token",
models.TextField(
blank=True, help_text="Access token from provider", null=True
),
),
(
"refresh_token",
models.TextField(
blank=True, help_text="Refresh token from provider", null=True
),
),
(
"token_expires_at",
models.DateTimeField(
blank=True, help_text="Token expiration date", null=True
),
),
(
"is_active",
models.BooleanField(
default=True, help_text="Social account is active"
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"last_login_at",
models.DateTimeField(
blank=True,
help_text="Last login using this social account",
null=True,
),
),
],
options={
"verbose_name": "Social Account",
"verbose_name_plural": "Social Accounts",
"db_table": "accounts_social_account",
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="TwoFactorDevice",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"device_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="Unique device identifier",
unique=True,
),
),
("name", models.CharField(help_text="Device name", max_length=100)),
(
"device_type",
models.CharField(
choices=[
("TOTP", "Time-based OTP (Authenticator App)"),
("SMS", "SMS"),
("EMAIL", "Email"),
("HARDWARE", "Hardware Token"),
("BACKUP", "Backup Codes"),
],
max_length=20,
),
),
(
"secret_key",
models.CharField(
blank=True,
help_text="Secret key for TOTP devices",
max_length=200,
null=True,
),
),
(
"phone_number",
models.CharField(
blank=True,
help_text="Phone number for SMS devices",
max_length=20,
null=True,
),
),
(
"email_address",
models.EmailField(
blank=True,
help_text="Email address for email devices",
max_length=254,
null=True,
),
),
(
"is_active",
models.BooleanField(default=True, help_text="Device is active"),
),
(
"is_verified",
models.BooleanField(default=False, help_text="Device is verified"),
),
(
"verified_at",
models.DateTimeField(
blank=True, help_text="Device verification date", null=True
),
),
(
"last_used_at",
models.DateTimeField(
blank=True, help_text="Last time device was used", null=True
),
),
(
"usage_count",
models.PositiveIntegerField(
default=0, help_text="Number of times device was used"
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
"verbose_name": "Two Factor Device",
"verbose_name_plural": "Two Factor Devices",
"db_table": "accounts_two_factor_device",
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="UserSession",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"session_key",
models.CharField(
help_text="Django session key", max_length=40, unique=True
),
),
(
"session_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="Unique session identifier",
unique=True,
),
),
("ip_address", models.GenericIPAddressField(help_text="IP address")),
("user_agent", models.TextField(help_text="User agent string")),
(
"device_type",
models.CharField(
choices=[
("DESKTOP", "Desktop"),
("MOBILE", "Mobile"),
("TABLET", "Tablet"),
("UNKNOWN", "Unknown"),
],
default="UNKNOWN",
max_length=20,
),
),
(
"browser",
models.CharField(
blank=True,
help_text="Browser name and version",
max_length=100,
null=True,
),
),
(
"operating_system",
models.CharField(
blank=True,
help_text="Operating system",
max_length=100,
null=True,
),
),
(
"country",
models.CharField(
blank=True, help_text="Country", max_length=100, null=True
),
),
(
"region",
models.CharField(
blank=True, help_text="Region/State", max_length=100, null=True
),
),
(
"city",
models.CharField(
blank=True, help_text="City", max_length=100, null=True
),
),
(
"is_active",
models.BooleanField(default=True, help_text="Session is active"),
),
(
"login_method",
models.CharField(
choices=[
("PASSWORD", "Password"),
("TWO_FACTOR", "Two Factor"),
("SOCIAL", "Social Login"),
("SSO", "Single Sign-On"),
("API_KEY", "API Key"),
],
default="PASSWORD",
max_length=20,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("last_activity_at", models.DateTimeField(auto_now=True)),
(
"expires_at",
models.DateTimeField(help_text="Session expiration time"),
),
(
"ended_at",
models.DateTimeField(
blank=True, help_text="Session end time", null=True
),
),
],
options={
"verbose_name": "User Session",
"verbose_name_plural": "User Sessions",
"db_table": "accounts_user_session",
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="User",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"user_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="Unique user identifier",
unique=True,
),
),
(
"middle_name",
models.CharField(
blank=True, help_text="Middle name", max_length=150, null=True
),
),
(
"preferred_name",
models.CharField(
blank=True,
help_text="Preferred name",
max_length=150,
null=True,
),
),
(
"phone_number",
models.CharField(
blank=True,
help_text="Primary phone number",
max_length=20,
null=True,
validators=[
django.core.validators.RegexValidator(
message='Phone number must be entered in the format: "+999999999". Up to 15 digits allowed.',
regex="^\\+?1?\\d{9,15}$",
)
],
),
),
(
"mobile_number",
models.CharField(
blank=True,
help_text="Mobile phone number",
max_length=20,
null=True,
validators=[
django.core.validators.RegexValidator(
message='Phone number must be entered in the format: "+999999999". Up to 15 digits allowed.',
regex="^\\+?1?\\d{9,15}$",
)
],
),
),
(
"employee_id",
models.CharField(
blank=True, help_text="Employee ID", max_length=50, null=True
),
),
(
"department",
models.CharField(
blank=True, help_text="Department", max_length=100, null=True
),
),
(
"job_title",
models.CharField(
blank=True, help_text="Job title", max_length=100, null=True
),
),
(
"role",
models.CharField(
choices=[
("SUPER_ADMIN", "Super Administrator"),
("ADMIN", "Administrator"),
("PHYSICIAN", "Physician"),
("NURSE", "Nurse"),
("NURSE_PRACTITIONER", "Nurse Practitioner"),
("PHYSICIAN_ASSISTANT", "Physician Assistant"),
("PHARMACIST", "Pharmacist"),
("PHARMACY_TECH", "Pharmacy Technician"),
("LAB_TECH", "Laboratory Technician"),
("RADIOLOGIST", "Radiologist"),
("RAD_TECH", "Radiology Technician"),
("THERAPIST", "Therapist"),
("SOCIAL_WORKER", "Social Worker"),
("CASE_MANAGER", "Case Manager"),
("BILLING_SPECIALIST", "Billing Specialist"),
("REGISTRATION", "Registration Staff"),
("SCHEDULER", "Scheduler"),
("MEDICAL_ASSISTANT", "Medical Assistant"),
("CLERICAL", "Clerical Staff"),
("IT_SUPPORT", "IT Support"),
("QUALITY_ASSURANCE", "Quality Assurance"),
("COMPLIANCE", "Compliance Officer"),
("SECURITY", "Security"),
("MAINTENANCE", "Maintenance"),
("VOLUNTEER", "Volunteer"),
("STUDENT", "Student"),
("RESEARCHER", "Researcher"),
("CONSULTANT", "Consultant"),
("VENDOR", "Vendor"),
("GUEST", "Guest"),
],
default="CLERICAL",
max_length=50,
),
),
(
"license_number",
models.CharField(
blank=True,
help_text="Professional license number",
max_length=100,
null=True,
),
),
(
"license_state",
models.CharField(
blank=True,
help_text="License issuing state",
max_length=50,
null=True,
),
),
(
"license_expiry",
models.DateField(
blank=True, help_text="License expiry date", null=True
),
),
(
"dea_number",
models.CharField(
blank=True,
help_text="DEA number for prescribing",
max_length=20,
null=True,
),
),
(
"npi_number",
models.CharField(
blank=True,
help_text="National Provider Identifier",
max_length=10,
null=True,
),
),
(
"force_password_change",
models.BooleanField(
default=False,
help_text="User must change password on next login",
),
),
(
"password_expires_at",
models.DateTimeField(
blank=True, help_text="Password expiration date", null=True
),
),
(
"failed_login_attempts",
models.PositiveIntegerField(
default=0, help_text="Number of failed login attempts"
),
),
(
"locked_until",
models.DateTimeField(
blank=True,
help_text="Account locked until this time",
null=True,
),
),
(
"two_factor_enabled",
models.BooleanField(
default=False, help_text="Two-factor authentication enabled"
),
),
(
"max_concurrent_sessions",
models.PositiveIntegerField(
default=3, help_text="Maximum concurrent sessions allowed"
),
),
(
"session_timeout_minutes",
models.PositiveIntegerField(
default=30, help_text="Session timeout in minutes"
),
),
(
"user_timezone",
models.CharField(
default="UTC", help_text="User timezone", max_length=50
),
),
(
"language",
models.CharField(
default="en", help_text="Preferred language", max_length=10
),
),
(
"theme",
models.CharField(
choices=[
("LIGHT", "Light"),
("DARK", "Dark"),
("AUTO", "Auto"),
],
default="LIGHT",
max_length=20,
),
),
(
"profile_picture",
models.ImageField(
blank=True,
help_text="Profile picture",
null=True,
upload_to="profile_pictures/",
),
),
(
"bio",
models.TextField(
blank=True, help_text="Professional bio", null=True
),
),
(
"is_verified",
models.BooleanField(
default=False, help_text="User account is verified"
),
),
(
"is_approved",
models.BooleanField(
default=False, help_text="User account is approved"
),
),
(
"approval_date",
models.DateTimeField(
blank=True, help_text="Account approval date", null=True
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"last_password_change",
models.DateTimeField(
default=django.utils.timezone.now,
help_text="Last password change date",
),
),
(
"approved_by",
models.ForeignKey(
blank=True,
help_text="User who approved this account",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="approved_users",
to=settings.AUTH_USER_MODEL,
),
),
(
"groups",
models.ManyToManyField(
blank=True,
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
related_name="user_set",
related_query_name="user",
to="auth.group",
verbose_name="groups",
),
),
],
options={
"verbose_name": "User",
"verbose_name_plural": "Users",
"db_table": "accounts_user",
"ordering": ["last_name", "first_name"],
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
]