def test_copy(self, db_session, root): from kotti.resources import LocalGroup node, principal_name, group_name = root, 'p', 'g' lg = LocalGroup(node, principal_name, group_name) lg2 = lg.copy() assert lg2 is not lg assert lg.node is lg2.node assert lg.principal_name == lg2.principal_name assert lg.group_name == lg2.group_name
def test_copy(self): from kotti.resources import get_root from kotti.resources import LocalGroup node, principal_name, group_name = get_root(), 'p', 'g' lg = LocalGroup(node, principal_name, group_name) lg2 = lg.copy() assert lg2 is not lg assert lg.node is lg2.node assert lg.principal_name == lg2.principal_name assert lg.group_name == lg2.group_name
def test_node_copy_with_local_groups(self, db_session, root): from kotti.resources import Node from kotti.resources import LocalGroup child1 = root['child1'] = Node() local_group1 = LocalGroup(child1, u'joe', u'role:admin') db_session.add(local_group1) db_session.flush() child2 = root['child2'] = child1.copy() db_session.flush() assert child2.local_groups == []
def set_groups(name, context, groups_to_set=()): """Set the list of groups for principal with given ``name`` and in given ``context``. """ name = unicode(name) from kotti.resources import LocalGroup DBSession.query(LocalGroup).filter( LocalGroup.node_id == context.id).filter( LocalGroup.principal_name == name).delete() for group_name in groups_to_set: DBSession.add(LocalGroup(context, name, unicode(group_name)))
def test_node_copy_with_local_groups(self): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Node from kotti.resources import LocalGroup root = get_root() child1 = root['child1'] = Node() local_group1 = LocalGroup(child1, u'joe', u'role:admin') DBSession.add(local_group1) DBSession.flush() child2 = root['child2'] = child1.copy() DBSession.flush() assert child2.local_groups == []
def set_groups(name: str, context: "Node", groups_to_set: Iterable[str] = ()) -> None: """Set the list of groups for principal with given ``name`` and in given ``context``. """ from kotti.resources import LocalGroup context.local_groups = [ # keep groups for "other" principals lg for lg in context.local_groups if lg.principal_name != name ] + [ # reset groups for given principal LocalGroup(context, name, group_name) for group_name in groups_to_set ]
def set_groups(name, context, groups_to_set=()): """Set the list of groups for principal with given ``name`` and in given ``context``. """ from kotti.resources import LocalGroup name = unicode(name) context.local_groups = [ # keep groups for "other" principals lg for lg in context.local_groups if lg.principal_name != name ] + [ # reset groups for given principal LocalGroup(context, name, unicode(group_name)) for group_name in groups_to_set ]