本文整理汇总了Python中grouper.models.group.Group.add方法的典型用法代码示例。如果您正苦于以下问题:Python Group.add方法的具体用法?Python Group.add怎么用?Python Group.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grouper.models.group.Group
的用法示例。
在下文中一共展示了Group.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_role_user
# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import add [as 别名]
def create_role_user(session, actor, name, description, canjoin):
# type (Session, User, str, str, str) -> None
"""DEPRECATED: Do not use in production code
Creates a service account with the given name, description, and canjoin status
Args:
session: the database session
actor: the user creating the service account
name: the name of the service account
description: description of the service account
canjoin: the canjoin status for management of the service account
Throws:
IntegrityError: if a user or group with the given name already exists
"""
user = User(username=name, role_user=True)
group = Group(groupname=name, description=description, canjoin=canjoin)
user.add(session)
group.add(session)
group.add_member(actor, actor, "Group Creator", "actioned", None, "np-owner")
group.add_member(actor, user, "Service Account", "actioned", None, "member")
session.commit()
AuditLog.log(
session,
actor.id,
"create_role_user",
"Created new service account.",
on_group_id=group.id,
on_user_id=user.id,
)
示例2: sync_db_command
# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import add [as 别名]
def sync_db_command(args):
# Models not implicitly or explictly imported above are explicitly imported
# here:
from grouper.models.perf_profile import PerfProfile # noqa
db_engine = get_db_engine(get_database_url(settings))
Model.metadata.create_all(db_engine)
# Add some basic database structures we know we will need if they don't exist.
session = make_session()
for name, description in SYSTEM_PERMISSIONS:
test = Permission.get(session, name)
if test:
continue
permission = Permission(name=name, description=description)
try:
permission.add(session)
session.flush()
except IntegrityError:
session.rollback()
raise Exception('Failed to create permission: %s' % (name, ))
session.commit()
# This group is needed to bootstrap a Grouper installation.
admin_group = Group.get(session, name="grouper-administrators")
if not admin_group:
admin_group = Group(
groupname="grouper-administrators",
description="Administrators of the Grouper system.",
canjoin="nobody",
)
try:
admin_group.add(session)
session.flush()
except IntegrityError:
session.rollback()
raise Exception('Failed to create group: grouper-administrators')
for permission_name in (GROUP_ADMIN, PERMISSION_ADMIN, USER_ADMIN):
permission = Permission.get(session, permission_name)
assert permission, "Permission should have been created earlier!"
grant_permission(session, admin_group.id, permission.id)
session.commit()
示例3: post
# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import add [as 别名]
def post(self, *args, **kwargs):
# type: (*Any, **Any) -> None
form = GroupCreateForm(self.request.arguments)
if not form.validate():
return self.render(
"group-create.html", form=form, alerts=self.get_form_alerts(form.errors)
)
group = Group(
groupname=form.data["groupname"],
description=form.data["description"],
canjoin=form.data["canjoin"],
auto_expire=form.data["auto_expire"],
require_clickthru_tojoin=form.data["require_clickthru_tojoin"],
)
try:
group.add(self.session)
self.session.flush()
except IntegrityError:
self.session.rollback()
form.groupname.errors.append("{} already exists".format(form.data["groupname"]))
return self.render(
"group-create.html", form=form, alerts=self.get_form_alerts(form.errors)
)
group.add_member(
self.current_user,
self.current_user,
"Group Creator",
"actioned",
None,
form.data["creatorrole"],
)
self.session.commit()
AuditLog.log(
self.session,
self.current_user.id,
"create_group",
"Created new group.",
on_group_id=group.id,
)
return self.redirect("/groups/{}?refresh=yes".format(group.name))