Adds a new group object to the repository
| Parameters: |
-
group
(Group)
–
-
identity
(Identity | None, default:
None
)
–
The identity of the user making the changes, by default None. If
provided, the created_by attribute of the group will be updated
with the username from the identity.
|
Source code in src/alpha/mixins/group_lifecycle.py
| def add_group(
self, group: Group, identity: Identity | None = None
) -> Group:
"""Adds a new group object to the repository
Parameters
----------
group
New group object
identity
The identity of the user making the changes, by default None. If
provided, the `created_by` attribute of the group will be updated
with the username from the identity.
Returns
-------
Group
Created group object
"""
group = self._group_model(**group.to_dict())
if identity:
group.created_by = identity.username
with self.uow:
groups: SqlRepository[Group] = getattr(
self.uow, self._groups_repository_name
)
group = groups.add(group, raise_if_exists=True)
self.uow.commit()
return group
|