mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
So far, we've used the BitField .authentication_methods on Realm for tracking which backends are enabled for an organization. This however made it a pain to add new backends (requiring altering the column and a migration - particularly troublesome if someone wanted to create their own custom auth backend for their server). Instead this will be tracked through the existence of the appropriate rows in the RealmAuthenticationMethods table.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
# Generated by Django 4.2 on 2023-04-13 23:45
|
|
|
|
import django.db.models.deletion
|
|
from django.db import migrations, models
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
def fill_RealmAuthenticationMethod_data(
|
|
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
|
|
) -> None:
|
|
Realm = apps.get_model("zerver", "Realm")
|
|
RealmAuthenticationMethod = apps.get_model("zerver", "RealmAuthenticationMethod")
|
|
for realm in Realm.objects.order_by("id"):
|
|
rows_to_create = []
|
|
for key, value in realm.authentication_methods.iteritems():
|
|
if value:
|
|
rows_to_create.append(RealmAuthenticationMethod(name=key, realm_id=realm.id))
|
|
RealmAuthenticationMethod.objects.bulk_create(rows_to_create)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
atomic = False
|
|
|
|
dependencies = [
|
|
("zerver", "0435_scheduledmessage_rendered_content"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name="RealmAuthenticationMethod",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.AutoField(
|
|
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
|
),
|
|
),
|
|
("name", models.CharField(max_length=80)),
|
|
(
|
|
"realm",
|
|
models.ForeignKey(
|
|
on_delete=django.db.models.deletion.CASCADE, to="zerver.realm"
|
|
),
|
|
),
|
|
],
|
|
options={
|
|
"unique_together": {("realm", "name")},
|
|
},
|
|
),
|
|
migrations.RunPython(fill_RealmAuthenticationMethod_data),
|
|
]
|