def create_role(self, rolename, permissions=[]): r = Role(rolename=rolename) r.last_changed_by = "Unknown" r.last_change_date = datetime.now() for permission in permissions: r.permissions.append(Permission(rolename=r.rolename, permission=permission)) self.session.add(r) self.session.commit() return r
def update_role(self, role, permissions): r = self.session.query(Role).filter(Role.rolename == role.rolename)\ .filter(Role.valid_until == ModelUtility.NullTimeStamp).first() # 1. Aktuellen Stand der Rolle als Version sichern r_version = Role(rolename=r.rolename, valid_until=datetime.now()) r_version.last_change_date = r.last_change_date r_version.last_changed_by = r.last_changed_by r_version.permissions = [] for permission in r.permissions: r_version.permissions.append(Permission(role=r, permission=permission.permission)) self.session.add(r_version) # 2. Rolle aktualisieren r.permissions = [] for permission in permissions: r.permissions.append(Permission(role=r, permission=permission)) r.last_change_date = datetime.now() r.last_changed_by = 'blub' self.session.add(r) self.session.commit()