当前位置: 首页>>代码示例>>Python>>正文


Python IPrincipalRoleMap.assignRoleToPrincipal方法代码示例

本文整理汇总了Python中zope.securitypolicy.interfaces.IPrincipalRoleMap.assignRoleToPrincipal方法的典型用法代码示例。如果您正苦于以下问题:Python IPrincipalRoleMap.assignRoleToPrincipal方法的具体用法?Python IPrincipalRoleMap.assignRoleToPrincipal怎么用?Python IPrincipalRoleMap.assignRoleToPrincipal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.securitypolicy.interfaces.IPrincipalRoleMap的用法示例。


在下文中一共展示了IPrincipalRoleMap.assignRoleToPrincipal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _set_group_local_role

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import assignRoleToPrincipal [as 别名]
def _set_group_local_role(context, unset=False):
    def get_group_local_role(group):
        if interfaces.IParliament.providedBy(group):
            return "bungeni.MP"
        elif interfaces.IMinistry.providedBy(group):
            return "bungeni.Minister"
        elif interfaces.ICommittee.providedBy(group): 
            return "bungeni.CommitteeMember"
        elif interfaces.IPoliticalGroup.providedBy(group):
            return "bungeni.PartyMember"
        elif interfaces.IGovernment.providedBy(group):
            return "bungeni.Government"
        elif interfaces.IOffice.providedBy(group):
            return group.office_role
        else:
            return "bungeni.GroupMember"
    def get_group_context(context):
        if interfaces.IOffice.providedBy(context):
            return BungeniApp() #get_parliament(context)
        else:
            return removeSecurityProxy(context)
    role = get_group_local_role(context)
    group = removeSecurityProxy(context)
    ctx = get_group_context(context)
    prm = IPrincipalRoleMap(ctx)
    if not unset:
        prm.assignRoleToPrincipal(role, group.group_principal_id)
    else:
        prm.unsetRoleForPrincipal(role, group.group_principal_id)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:31,代码来源:utils.py

示例2: _set_group_local_role

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import assignRoleToPrincipal [as 别名]
def _set_group_local_role(context, unset=False):
    group = context
    role = get_group_local_role(group)
    prm = IPrincipalRoleMap(get_group_context(group))
    if not unset:
        prm.assignRoleToPrincipal(role, group.group_principal_id)
    else:
        prm.unsetRoleForPrincipal(role, group.group_principal_id)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:10,代码来源:utils.py

示例3: title_created

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import assignRoleToPrincipal [as 别名]
def title_created(title, event):
    prm = IPrincipalRoleMap(get_group_context(title.title_type.group))
    prm.assignRoleToPrincipal(title.title_type.role_id, title.member.user.login)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:5,代码来源:roles.py

示例4: UserAssignmentView

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import assignRoleToPrincipal [as 别名]

#.........这里部分代码省略.........
            else:
                for c_assignable_role in config_assignable_roles:
                    if (c_assignable_role in assigner_role_annt.sub_roles):
                        assignable_roles.append(c_assignable_role)
        self._assignable_roles = assignable_roles
        return self._assignable_roles

    def can_edit(self, action=None):
        return checkPermission("bungeni.user_assignment.Edit", self.context)

    @property
    def columns(self):
        return [
            column.GetterColumn(
                title=_("user name"),
                getter=lambda i, f: i.get("title")
            ),
            column.GetterColumn(
                title=_("assigned"),
                getter=lambda i, f: i,
                cell_formatter=lambda g, i, f: \
                    '<input type="checkbox" name="%s" %s %s/>' % (
                        i["name"],
                        i["is_assigned"] and ' checked="checked"' or "",
                        not i["editable"] and ' disabled="disabled"' or "")
                )
            ]

    @property
    def checkbox_prefix(self):
        return "assignment_users"

    def make_id(self, role_id, user_login_id):
        return ".".join(
            (self.checkbox_prefix, role_id, user_login_id))

    def user_is_assigned(self, user_login, role_id):
        if self.prm.getSetting(role_id, user_login) == Allow:
            return True
        return False

    def role_listing(self, role_id, editable):
        listing = []
        users = common.get_users(role_id)
        if not users:
            return _("No users available for this role.")
        for user in users:
            data = {}
            data["title"] = IDCDescriptiveProperties(user).title
            data["name"] = self.make_id(user.login, role_id)
            data["is_assigned"] = self.user_is_assigned(user.login, role_id)
            data["editable"] = editable
            listing.append(data)
        formatter = TableFormatter(
            self.context, self.request, listing, prefix="assignment",
            columns=self.columns)
        formatter.updateBatching()
        return formatter()

    def update(self):
        self.tables = []
        assignable_roles = self.assignable_roles()
        for role_id in assignable_roles:
            if role_id in assignable_roles:
                editable = True
            else:
                editable = False
            self.tables.append(
                {"title": getUtility(IRole, role_id).title,
                 "table": self.role_listing(role_id, editable)})
        forms.common.BaseForm.update(self)

    def get_selected(self):
        selected = [
            (k[len(self.checkbox_prefix) + 1:].split(".")[0].decode("base64"),
            k[len(self.checkbox_prefix) + 1:].split(".")[1].decode("base64"))
            for k in self.request.form.keys()
            if k.startswith(self.checkbox_prefix) and self.request.form.get(k)
        ]
        return selected

    def process_assignment(self):
        for role_id in self.assignable_roles():
            for user in common.get_users(role_id):
                key = self.make_id(user.login, role_id)
                if key in self.request.form.keys():
                    self.prm.assignRoleToPrincipal(role_id, user.login)
                else:
                    self.prm.unsetRoleForPrincipal(role_id, user.login)

    @formlib.form.action(label=_("Save"), name="save", condition=can_edit)
    def handle_save(self, action, data):
        self.process_assignment()
        next_url = url.absoluteURL(self.context, self.request)
        self.request.response.redirect(next_url)

    @formlib.form.action(label=_("Cancel"), name="", condition=can_edit)
    def handle_cancel(self, action, data):
        next_url = url.absoluteURL(self.context, self.request)
        self.request.response.redirect(next_url)
开发者ID:gelie,项目名称:bungeni_src,代码行数:104,代码来源:assignment.py

示例5: group_membership_role_added

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import assignRoleToPrincipal [as 别名]
def group_membership_role_added(group_membership_role, event):
    if group_membership_role.is_global:
        prm = IPrincipalRoleMap(get_group_context(group_membership_role.member.group))
        prm.assignRoleToPrincipal(group_membership_role.role_id, group_membership_role.member.user.login)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:6,代码来源:roles.py


注:本文中的zope.securitypolicy.interfaces.IPrincipalRoleMap.assignRoleToPrincipal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。