Skip to content

Commit

Permalink
migration for existing saml users
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Oct 25, 2023
1 parent c8c986b commit 3c442c2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions backend/users/migrations/0004_saml_user_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import migrations
from users.saml import saml_user_group

def add_saml_users_to_group(apps, schema_editor):
CustomUser = apps.get_model('users', 'CustomUser')

saml_users = CustomUser.objects.filter(saml = True)
saml_group = saml_user_group()

if saml_group:
for user in saml_users:
user.groups.add(saml_group)
user.save()

class Migration(migrations.Migration):

dependencies = [
('users', '0003_sitedomain'),
]

operations = [
migrations.RunPython(
add_saml_users_to_group,
reverse_code=migrations.RunPython.noop
)
]

0 comments on commit 3c442c2

Please sign in to comment.