Skip to content
Snippets Groups Projects

Greg 95 cerebrum sponsor import

Merged Sivert Kronen Hatteberg requested to merge GREG-95-cerebrum-sponsor-import into master
All threads resolved!
1 file
+ 12
16
Compare changes
  • Side-by-side
  • Inline
@@ -46,23 +46,19 @@ class Command(BaseCommand):
def _upsert_sponsor_unit_link(self, sponsor: Sponsor, unit: OrganizationalUnit):
"""Ensure a link between sponsor and unit."""
try:
sunit = SponsorOrganizationalUnit.objects.get(
sponsor=sponsor,
organizational_unit=unit,
source=self.CEREBRUM_SOURCE,
automatic=True,
)
logger.info("sponsor_ou_link_found", sponsor=sponsor.id, sunit=sunit.id)
except SponsorOrganizationalUnit.DoesNotExist:
sunit = SponsorOrganizationalUnit.objects.create(
sponsor=sponsor,
organizational_unit=unit,
hierarchical_access=settings.CEREBRUM_HIERARCHICAL_ACCESS,
automatic=True,
source=self.CEREBRUM_SOURCE,
)
sunit, created = SponsorOrganizationalUnit.objects.get_or_create(
sponsor=sponsor,
organizational_unit=unit,
source=self.CEREBRUM_SOURCE,
automatic=True,
)
if created:
logger.info("sponsor_ou_link_create", sponsor=sponsor.id, sunit=sunit.id)
else:
logger.info("sponsor_ou_link_found", sponsor=sponsor.id, sunit=sunit.id)
sunit.hierarchical_access = settings.CEREBRUM_HIERARCHICAL_ACCESS
sunit.save()
return SponsorOrganizationalUnit.objects.get(id=sunit.id)
def _remove_sponsor_unit_link(self, sunit: SponsorOrganizationalUnit):
Loading