Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: disallow migrations on ldap connection and models #201

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion ldapdb/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# This software is distributed under the two-clause BSD license.
# Copyright (c) The django-ldapdb project

from django.apps import apps

from ldapdb.models import Model


def is_ldap_model(model):
# FIXME: there is probably a better check than testing 'base_dn'
Expand All @@ -27,8 +31,15 @@ def __init__(self):
break

def allow_migrate(self, db, app_label, model_name=None, **hints):
if 'model' in hints and is_ldap_model(hints['model']):
# disallow any migration operation on ldap engine
if db == self.ldap_alias:
return False

# avoid any migration operation on ldap models
if model_name:
model = apps.get_model(app_label, model_name)
if issubclass(model, Model):
return False
return None

def db_for_read(self, model, **hints):
Expand Down