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
15
Compare changes
  • Side-by-side
  • Inline
"""
"""
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
Uses the members of the adm-leder-<legacy_stedkode> groups to
variables ORGREG_SOURCE and ORGREG_NAME
populate Sponsors and SponsorOrganizationalUnits.
Assumes that the header used for authentication is of the type
This script does only remove the SponsorOrganizationalUnit.
'X-Gravitee-Api-Key': 'token'.
The Sponsor objects are kept, even with no units
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).
"""
"""
 
from typing import Optional, Tuple
from typing import Optional, Tuple
import cerebrum_client
import cerebrum_client
@@ -28,7 +26,6 @@ class Command(BaseCommand):
@@ -28,7 +26,6 @@ class Command(BaseCommand):
help = __doc__
help = __doc__
CEREBRUM_SOURCE = "cerebrum"
CEREBRUM_SOURCE = "cerebrum"
CEREBRUM_VALID_SOURCE_SYSTEM = ["DFO_SAP"]
CEREBRUM_FEIDE_INST = "uio.no"
CEREBRUM_FEIDE_INST = "uio.no"
CEREBRUM_NAME_SOURCE_PRIORITY = ["Cached", "Override", "DFO_SAP", "FS", "Manual"]
CEREBRUM_NAME_SOURCE_PRIORITY = ["Cached", "Override", "DFO_SAP", "FS", "Manual"]
@@ -170,7 +167,7 @@ class Command(BaseCommand):
@@ -170,7 +167,7 @@ class Command(BaseCommand):
cerebrum_group=group_name,
cerebrum_group=group_name,
)
)
for sponsor in current_sponsors:
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
continue
if group.expire_date:
if group.expire_date:
@@ -181,17 +178,17 @@ class Command(BaseCommand):
@@ -181,17 +178,17 @@ class Command(BaseCommand):
cerebrum_group=group_name,
cerebrum_group=group_name,
)
)
for sponsor in current_sponsors:
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
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:
if not group_members:
# No members in group, remove sponsors
# No members in group, remove sponsors
logger.info(
logger.info(
"cerebrum_group_empty", unit_id=unit.id, cerebrum_group=group_name
"cerebrum_group_empty", unit_id=unit.id, cerebrum_group=group_name
)
)
for sponsor in current_sponsors:
for sponsor in current_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
continue
continue
cerebrum_sponsors = set()
cerebrum_sponsors = set()
@@ -204,7 +201,7 @@ class Command(BaseCommand):
@@ -204,7 +201,7 @@ class Command(BaseCommand):
)
)
cerebrum_sponsors.add(sponsor_link)
cerebrum_sponsors.add(sponsor_link)
for non_cerebrum_sponsor in set(current_sponsors) - cerebrum_sponsors:
for sponsor in set(current_sponsors) - cerebrum_sponsors:
self._remove_sponsor_unit_link(non_cerebrum_sponsor)
self._remove_sponsor_unit_link(sponsor)
logger.info("import_end")
logger.info("import_end")
Loading