Skip to content

Commit

Permalink
refactored migrate, still need to add supervisors checked.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo authored Oct 4, 2023
1 parent 94026fb commit e3e694e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions scripts/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,57 @@
def migrate_groups():
owner_group, _ = Group.objects.get_or_create(name="Org Owners")
execs_group, _ = Group.objects.get_or_create(name="Execs")
count_exec = {"added": 0, "removed": 0}
count_leading = {"added": 0, "removed": 0}
staffs = {"added": 0, "removed": 0}
supervisor_group, _ = Group.objects.get_or_create(name="Supervisors")
count = {'exec': {"added": 0, "removed": 0},
'supervisor': {"added": 0, "removed": 0},
'owner': {"added": 0, "removed": 0},
'staff': {"added": 0, "removed": 0}}
for user in User.objects.all():
if user.is_teacher and not user.is_staff:
user.is_staff = True
user.save()
staffs["added"] += 1
count['staff']["added"] += 1
if user.organizations_leading.count() >= 1:
if not user.is_staff:
user.is_staff = True
user.save()
staffs["added"] += 1
count['staff']["added"] += 1
if not user.groups.filter(name="Execs").exists():
user.groups.add(execs_group)
count_exec["added"] += 1
count['exec']["added"] += 1
else:
if all([user.is_staff, not user.is_superuser, not user.is_teacher]):
user.is_staff = False
user.save()
staffs["removed"] += 1
count['staff']["removed"] += 1
if user.groups.filter(name="Execs").exists():
user.groups.remove(execs_group)
count_exec["removed"] += 1
count['exec']["removed"] += 1
if user.organizations_owning.count() >= 1:
if not user.is_staff:
user.is_staff = True
user.save()
staffs["added"] += 1
count['staff']["added"] += 1
if not user.groups.filter(name="Org Owners").exists():
user.groups.add(owner_group)
count_leading["added"] += 1
count['owner']["added"] += 1
else:
if user.organizations_leading.count() == 0:
if all([user.is_staff, not user.is_superuser, not user.is_teacher]):
user.is_staff = False
user.save()
staffs["removed"] += 1
count['staff']["removed"] += 1
if user.groups.filter(name="Org Owners").exists():
user.groups.remove(owner_group)
count_leading["removed"] += 1
print(f"Added {count_exec['added']} users to execs group")
print(f"Removed {count_exec['removed']} users from execs group")
print(f"Added {count_leading['added']} users to owners group")
print(f"Removed {count_leading['removed']} users from owners group")
print(f"Added {staffs['added']} users to staff")
print(f"Removed {staffs['removed']} users from staff")
count['owner']["removed"] += 1
print(f"Added {count['exec']['added']} users to execs group")
print(f"Removed {count['exec']['removed']} users from execs group")
print(f"Added {count['owner']['added']} users to owners group")
print(f"Removed {count['owner']['removed']} users from owners group")
print(f"Added {count['staff']['added']} users to staff")
print(f"Removed {count['staff']['removed']} users from staff")

print("total in execs group: " + str(execs_group.user_set.count()))
print("total in owners group: " + str(owner_group.user_set.count()))
print("total in supervisors group: " + str(supervisor_group.user_set.count()))
print("total staff: " + str(User.objects.filter(is_staff=True).count()) + "\n")

0 comments on commit e3e694e

Please sign in to comment.