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
"""
Fetch all OUs from OrgReg and add the complete tree to Greg.
Fetch sponsors for all units in GREG.
Ignores OrganizationalUnits without identifiers with source and name matching global
variables ORGREG_SOURCE and ORGREG_NAME
Uses the members of the adm-leder-<legacy_stedkode> groups to
populate Sponsors and SponsorOrganizationalUnits.
Assumes that the header used for authentication is of the type
'X-Gravitee-Api-Key': 'token'.
If the path to the endpoint of the OUs is oregreg/v3/ou/ you want to give
orgreg/v3/ as the url argument (note the trailing slash).
This script does only remove the SponsorOrganizationalUnit.
The Sponsor objects are kept, even with no units
"""
from typing import Optional, Tuple
import cerebrum_client
@@ -28,7 +26,6 @@ class Command(BaseCommand):
help = __doc__
CEREBRUM_SOURCE = "cerebrum"
CEREBRUM_VALID_SOURCE_SYSTEM = ["DFO_SAP"]
CEREBRUM_FEIDE_INST = "uio.no"
CEREBRUM_NAME_SOURCE_PRIORITY = ["Cached", "Override", "DFO_SAP", "FS", "Manual"]
@@ -170,7 +167,7 @@ class Command(BaseCommand):
cerebrum_group=group_name,
)
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
if group.expire_date:
@@ -181,17 +178,17 @@ class Command(BaseCommand):
cerebrum_group=group_name,
)
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
group_members = list(self.client.list_group_members(group.id))
group_members = list(self.client.list_group_members(group_name))
if not group_members:
# No members in group, remove sponsors
logger.info(
"cerebrum_group_empty", unit_id=unit.id, cerebrum_group=group_name
)
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
cerebrum_sponsors = set()
@@ -204,7 +201,7 @@ class Command(BaseCommand):
)
cerebrum_sponsors.add(sponsor_link)
for non_cerebrum_sponsor in set(current_sponsors) - cerebrum_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
for sponsor in set(current_sponsors) - cerebrum_sponsors:
self._remove_sponsor_unit_link(sponsor)
logger.info("import_end")
Loading