forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path0136_external_headers.py
39 lines (28 loc) · 1.5 KB
/
0136_external_headers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Generated by Django 3.2.8 on 2021-11-01 22:37
from django.db import migrations
def foward(apps, schema_editor): # pragma: no cover
Channel = apps.get_model("channels", "Channel")
for channel in Channel.objects.filter(is_active=True, channel_type="EX"):
if "send_authorization" in channel.config:
send_authorization = channel.config.pop("send_authorization")
channel.config.setdefault("headers", {})
if "Authorization" in channel.config["headers"]:
print(f'Channel "{channel.uuid}"" already have an "Authorization" header, skipping...')
continue
else:
channel.config["headers"]["Authorization"] = send_authorization
channel.save()
def reverse(apps, schema_editor): # pragma: no cover
Channel = apps.get_model("channels", "Channel")
for channel in Channel.objects.filter(is_active=True, channel_type="EX"):
if "headers" in channel.config and "Authorization" in channel.config["headers"]:
authorization_header = channel.config["headers"].pop("Authorization")
if not channel.config["headers"]: # clean if empty
channel.config.pop("headers")
channel.config.update(send_authorization=authorization_header)
channel.save()
class Migration(migrations.Migration):
dependencies = [
("channels", "0135_alter_channellog_created_on"),
]
operations = [migrations.RunPython(foward, reverse, elidable=True)]