44 lines
2.8 KiB
Python
44 lines
2.8 KiB
Python
# Generated by Django 5.1.1 on 2026-10-13 09:53
|
|
|
|
import django.db.models.deletion
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
|
|
|
|
def preserve_used_response_controls(apps, schema_editor):
|
|
from django.db.migrations.exceptions import IrreversibleError
|
|
if apps.get_model('tickets', 'DispatchResponseControl').objects.using(schema_editor.connection.alias).exists():
|
|
raise IrreversibleError('Response controls are in use; refusing to delete confidentiality and opening history.')
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('tickets', '0017_ticketaccessgrant_first_viewed_at_and_more'),
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='DispatchResponseControl',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('mode', models.CharField(choices=[('SEALED', 'بازگشایی یکجا'), ('INDIVIDUAL', 'مشاهده جداگانه')], default='SEALED', max_length=12)),
|
|
('notify_sms', models.BooleanField(default=True)),
|
|
('recipient_count_snapshot', models.PositiveIntegerField()),
|
|
('opened_at', models.DateTimeField(blank=True, null=True)),
|
|
('sms_body_snapshot', models.TextField(blank=True)),
|
|
('respondents_snapshot', models.JSONField(blank=True, default=list)),
|
|
('dispatch', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='response_control', to='tickets.groupdispatch')),
|
|
('opened_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
|
],
|
|
options={
|
|
'verbose_name': 'تنظیمات و سابقه بازگشایی ارسال',
|
|
'verbose_name_plural': 'تنظیمات و سوابق بازگشایی ارسالها',
|
|
'permissions': [('open_all_dispatch_responses', 'Can open responses of all authorized dispatches')],
|
|
'constraints': [models.CheckConstraint(condition=models.Q(('notify_sms', False), models.Q(('mode', 'SEALED'), ('recipient_count_snapshot__lte', 15)), _connector='OR'), name='dispatch_opening_sms_limit'), models.CheckConstraint(condition=models.Q(('mode__in', ['SEALED', 'INDIVIDUAL'])), name='dispatch_response_mode_valid'), models.CheckConstraint(condition=models.Q(models.Q(('opened_at__isnull', True), ('opened_by__isnull', True)), models.Q(('mode', 'SEALED'), ('opened_at__isnull', False), ('opened_by__isnull', False)), _connector='OR'), name='dispatch_opening_audit_complete')],
|
|
},
|
|
),
|
|
migrations.RunPython(migrations.RunPython.noop, preserve_used_response_controls),
|
|
]
|