Browse Source

Add study code to LDAP info

Joshua Rubingh 2 months ago
  1. 19


@ -278,7 +278,7 @@ class VRWLDAP():
logger.debug(f'Research group {name} does not exist.')
return False
def create_research_group(self, name, subgroups=False):
def create_research_group(self, name, code, subgroups=False):
"""Create a new research group in the LDAP server based on the name.
The name will be changed to strip if from special characters and spaces. The name will bug slugified.
@ -327,7 +327,7 @@ class VRWLDAP():
'ndsLoginProperties', 'organizationalUnit', 'Top'],
{'description': f'{name} Researchgroup',
'hsrGroupOrganisation': 'RUG',
'hsrGroupProjectCode': 'Support'})
'hsrGroupProjectCode': code})
if add_ok:
if subgroups:
@ -626,7 +626,7 @@ class VRWLDAP():
studies = {}
logger.debug(f'Exporting all studies in DN "{self.__RESOURCE_GROUPS_BASE}"')
# We are missing Faculty information here....
if, f'(ou=*)', attributes=['ou', 'description', ]):
if, f'(ou=*)', attributes=['ou', 'description', 'hsrGroupProjectCode']):
entries = copy.deepcopy(self.connection.entries)
for entry in entries:
# Skip starting point... not sure why it is found in the list...
@ -639,6 +639,7 @@ class VRWLDAP():
studies[dn] = {
'dn': dn,
'name': study_name,
'code': None if not entry.hsrGroupProjectCode else entry.hsrGroupProjectCode.value.strip(),
'description': None if not entry.description else entry.description.value.strip(),
'contributors': {}
@ -652,7 +653,7 @@ class VRWLDAP():
studies (dict): A dict of all the studies generated by `export_studies`
tuple: Returns a tuple with two values. First is a list with all the researchers, the second is a list with all the studies
tuple: Returns a tuple with two values. First is a dict with all the researchers, the second is a dict with all the studies
researchers = []
logger.debug(f'Exporting all researchers in DN "{self.__RESOURCE_MEMBERS_BASE}"')
@ -689,12 +690,7 @@ class VRWLDAP():
elif group[1].lower() == 'role' and len(group) == 3:
studies[group_id]['contributors'][uid]['role'] = 'Administrator' if 'datamanager' == group[2].lower() else 'Contributor'
# convert study dict to list. Is less data and easier for the import later on.
studies_list = []
for study_data in studies.values():
return (researchers, studies_list)
return (researchers, studies)
def export(self):
return self.export_researchers(self.export_studies())
@ -765,6 +761,7 @@ class VRE_API_CLient():
'study_id': workspace['study']['id'],
'study_name': workspace['study']['name'],
'study_code': None if 'code' not in workspace['study'] else workspace['study']['code'],
'study_dn': None if workspace['cloud_id'] is None else workspace['cloud_id'][workspace['cloud_id'].index(',') + 1:],
@ -930,7 +927,7 @@ if __name__ == "__main__":
workspace['study_name'], workspace['study_dn'])
if not study_dn:
study_dn = ldap_client.create_research_group(workspace['study_name'], config['LDAP_MANUAL_GROUPS'])
study_dn = ldap_client.create_research_group(workspace['study_name'], workspace['study_code'], config['LDAP_MANUAL_GROUPS'])
except DuplicateResearchGroup as ex: