Skip to content


Browse files Browse the repository at this point in the history
fix(groups): make groups optional (DEV-138) (#135)
* fix error in test-data.xml

* optionalize groups in ontology creation

* refactor group handling

* Update documentation
  • Loading branch information
irinaschubert committed Dec 14, 2021
1 parent 605dc2f commit 6aa1aa7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 0 additions & 2 deletions docs/
Expand Up @@ -383,8 +383,6 @@ Example:

The `groups` element is optional. If not used, it should be omitted. It is currently not recommended using it.

### Users

Expand Down
20 changes: 11 additions & 9 deletions knora/dsplib/utils/
Expand Up @@ -131,22 +131,24 @@ def create_ontology(input_file: str,

new_groups = {}
groups = data_model["project"].get('groups')
if groups is not None:
if groups:
for group in groups:
new_group = Group(con=con,
status=group["status"] if group.get("status") is not None else True,
selfjoin=group["selfjoin"] if group.get("selfjoin") is not None else False).create()
status=group["status"] if group.get("status") else True,
selfjoin=group["selfjoin"] if group.get("selfjoin") else False).create()
new_groups[] = new_group
if verbose:
print("Created group:")
new_group.print() # project.set_default_permissions(

except BaseError as err:
print("Creating group has failed: ", err.message)
return False
new_groups[] = new_group
if verbose:
new_group.print() # project.set_default_permissions(
print(f"ERROR while trying to create group '{}'. The error message was: {err.message}")
except Exception as exception:
print(f"ERROR while trying to create group '{}'. The error message was: {exception}")

# create the user(s)
if verbose:
Expand Down
14 changes: 10 additions & 4 deletions knora/dsplib/utils/
Expand Up @@ -36,8 +36,8 @@ class ProjectContext:
_projects: list[Project]
_project_map: Dict[str, str] # dictionary of (project name:project IRI) pairs
_inv_project_map: Dict[str, str] # dictionary of (project IRI:project name) pairs
_groups: list[Group]
_group_map: Dict[str, str]
_groups: Optional[list[Group]]
_group_map: Optional[Dict[str, str]]
_shortcode: Optional[str]
_project_name: Optional[str]

Expand All @@ -46,8 +46,14 @@ def __init__(self, con: Connection, shortcode: Optional[str] = None):
self._projects = Project.getAllProjects(con=con)
self._project_map: Dict[str, str] = {x.shortname: for x in self._projects}
self._inv_project_map: Dict[str, str] = { x.shortname for x in self._projects}
self._groups = Group.getAllGroups(con=con)
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + for x in self._groups}
self._groups = Group.getAllGroups(con=con)
except BaseError:
self._groups = None
if self._groups:
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + for x in self._groups}
self._group_map = None
self._project_name = None
# get the project name from the shortcode
if self._shortcode:
Expand Down
1 change: 0 additions & 1 deletion testdata/test-data.xml
Expand Up @@ -96,7 +96,6 @@
<list-prop list="testlist" name=":hasListItem">
<list permissions="prop-default">b2</list>
<list permissions="prop-default">b2</list>
<resptr-prop name=":hasTestThing2">
<resptr permissions="prop-default">obj_0000</resptr>
Expand Down

0 comments on commit 6aa1aa7

Please sign in to comment.