• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python permissions.get_object_owner函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中modoboa.lib.permissions.get_object_owner函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_owner函数的具体用法?Python get_object_owner怎么用?Python get_object_owner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_management_command_with_dry_run

 def test_management_command_with_dry_run(self):
     """Check that command works fine."""
     ObjectAccess.objects.all().delete()
     mbox = models.Mailbox.objects.all()[0]
     # assert mbox has no owner
     self.assertIs(get_object_owner(mbox), None)
     # show problems. run in quiet mode because we dont want output in tests
     management.call_command("modo", "repair", "--quiet", "--dry-run")
     # assert its not fixed
     self.assertIs(get_object_owner(mbox), None)
开发者ID:whyscream,项目名称:modoboa,代码行数:10,代码来源:test_repair.py


示例2: test_management_command

 def test_management_command(self):
     """Check that command works fine."""
     ObjectAccess.objects.all().delete()
     mbox = models.Mailbox.objects.first()
     alias = models.Alias.objects.first()
     # assert mbox has no owner
     self.assertIs(get_object_owner(mbox), None)
     # fix it. run in quiet mode because we dont want output in tests
     ret = management.call_command("modo", "repair", "--quiet")
     assert ret is None
     # assert it's fixed
     self.assertIsNot(get_object_owner(mbox), None)
     self.assertIsNot(get_object_owner(alias), None)
开发者ID:mvb9,项目名称:modoboa,代码行数:13,代码来源:test_repair.py


示例3: update_permissions

def update_permissions(sender, instance, **kwargs):
    """Permissions cleanup."""
    request = get_request()
    # request migth be None (management command context)
    if request:
        from_user = request.user
        if from_user == instance:
            raise exceptions.PermDeniedException(
                _("You can't delete your own account")
            )

        if not from_user.can_access(instance):
            raise exceptions.PermDeniedException

    # We send an additional signal before permissions are removed
    core_signals.account_deleted.send(
        sender="update_permissions", user=instance)
    owner = permissions.get_object_owner(instance)
    if owner == instance:
        # The default admin is being removed...
        owner = from_user
    # Change ownership of existing objects
    for ooentry in instance.objectaccess_set.filter(is_owner=True):
        if ooentry.content_object is not None:
            permissions.grant_access_to_object(
                owner, ooentry.content_object, True)
            permissions.ungrant_access_to_object(
                ooentry.content_object, instance)
    # Remove existing permissions on this user
    permissions.ungrant_access_to_object(instance)
开发者ID:brucewu16899,项目名称:modoboa,代码行数:30,代码来源:handlers.py


示例4: fix_owner

 def fix_owner(self, model, dry_run=False, **options):
     for obj in model.objects.all():
         kw = dict(
             cls=model.__name__,
             obj=obj
         )
         if get_object_owner(obj) is None:
             if dry_run:
                 self.log(
                     "  {cls} {obj} has no owner".format(**kw),
                     **options)
             else:
                 if isinstance(obj, User):
                     admin = User.objects.filter(is_superuser=True,
                                                 is_active=True).first()
                 elif isinstance(obj, models.Domain):
                     admin = obj.admins.first()
                 elif isinstance(obj, models.DomainAlias):
                     admin = obj.target.admins.first()
                 else:
                     admin = obj.domain.admins.first()
                 if not admin:
                     # domain has no admin. use the first superuser found
                     admin = User.objects.filter(is_superuser=True,
                                                 is_active=True).first()
                 grant_access_to_object(admin, obj, is_owner=True)
                 kw['admin'] = admin
                 self.log(
                     "  {cls} {obj} is now owned by {admin}".format(**kw),
                     **options)
开发者ID:whyscream,项目名称:modoboa,代码行数:30,代码来源:_repair.py


示例5: fix_owner

def fix_owner(qs, dry_run=False, **options):
    """Fix ownership for orphan objects."""
    model = qs.model
    for obj in qs:
        kw = {"cls": model.__name__, "obj": obj}
        if get_object_owner(obj) is not None:
            continue
        if dry_run:
            log("  {cls} {obj} has no owner".format(**kw), **options)
            continue
        if isinstance(obj, User):
            admin = User.objects.filter(
                is_superuser=True, is_active=True).first()
        elif isinstance(obj, models.Domain):
            admin = obj.admins.first()
        elif isinstance(obj, models.DomainAlias):
            admin = obj.target.admins.first()
        else:
            admin = obj.domain.admins.first()
        if not admin:
            # Fallback: use the first superuser found
            admin = User.objects.filter(
                is_superuser=True, is_active=True).first()
        grant_access_to_object(admin, obj, is_owner=True)
        kw["admin"] = admin
        log("  {cls} {obj} is now owned by {admin}".format(**kw),
            **options)
开发者ID:bearstech,项目名称:modoboa,代码行数:27,代码来源:_repair.py


示例6: on_account_modified

def on_account_modified(old, new):
    """Update limits when roles are updated"""
    owner = get_object_owner(old)
    if owner.group not in ["SuperAdmins", "Resellers"]:
        # Domain admins can't change the role so nothing to check.
        return

    if new.group != "SuperAdmins":
        # Check if account needs a pool (case: a superadmin is
        # downgraded)
        try:
            pool = new.limitspool
        except LimitsPool.DoesNotExist:
            p = LimitsPool(user=new)
            p.save()
            p.create_limits(owner)

    if new.group not in ["DomainAdmins", "Resellers"]:
        move_pool_resource(owner, new)

    if old.oldgroup == "DomainAdmins":
        if new.group != "DomainAdmins":
            dec_limit_usage(owner, 'domain_admins_limit')
        return

    if new.group == "DomainAdmins":
        check_limit(owner, 'domain_admins_limit')
        inc_limit_usage(owner, 'domain_admins_limit')
开发者ID:bearstech,项目名称:modoboa-admin-limits,代码行数:28,代码来源:controls.py


示例7: delete

    def delete(self, fromuser, *args, **kwargs):
        """Custom delete method

        To check permissions properly, we need to make a distinction
        between 2 cases:

        * If the user owns a mailbox, the check is made on that object
          (useful for domain admins)

        * Otherwise, the check is made on the user
        """
        from modoboa.lib.permissions import \
            get_object_owner, grant_access_to_object, ungrant_access_to_object

        if fromuser == self:
            raise PermDeniedException(
                _("You can't delete your own account")
            )

        if not fromuser.can_access(self):
            raise PermDeniedException

        owner = get_object_owner(self)
        for ooentry in self.objectaccess_set.filter(is_owner=True):
            if ooentry.content_object is not None:
                grant_access_to_object(owner, ooentry.content_object, True)

        events.raiseEvent("AccountDeleted", self, fromuser, **kwargs)
        ungrant_access_to_object(self)
        super(User, self).delete()
开发者ID:JHei,项目名称:modoboa,代码行数:30,代码来源:models.py


示例8: dec_nb_mailboxes

def dec_nb_mailboxes(mailboxes):
    from modoboa.extensions.admin.models import Mailbox

    if isinstance(mailboxes, Mailbox):
        mailboxes = [mailboxes]
    for mailbox in mailboxes:
        owner = get_object_owner(mailbox)
        dec_limit_usage(owner, 'mailboxes_limit')
开发者ID:JHei,项目名称:modoboa,代码行数:8,代码来源:controls.py


示例9: dec_nb_mbaliases

def dec_nb_mbaliases(mailboxaliases):
    from modoboa.extensions.admin.models import Alias

    if isinstance(mailboxaliases, Alias):
        mailboxaliases = [mailboxaliases]
    for alias in mailboxaliases:
        owner = get_object_owner(alias)
        dec_limit_usage(owner, 'mailbox_aliases_limit')
开发者ID:JHei,项目名称:modoboa,代码行数:8,代码来源:controls.py


示例10: dec_nb_domaliases

def dec_nb_domaliases(domainaliases):
    from modoboa.extensions.admin.models import DomainAlias

    if isinstance(domainaliases, DomainAlias):
        domainaliases = [domainaliases]
    for domainalias in domainaliases:
        owner = get_object_owner(domainalias)
        dec_limit_usage(owner, 'domain_aliases_limit')
开发者ID:JHei,项目名称:modoboa,代码行数:8,代码来源:controls.py


示例11: on_account_deleted

def on_account_deleted(account, byuser, **kwargs):
    owner = get_object_owner(account)
    if owner.group not in ["SuperAdmins", "Resellers"]:
        return

    move_pool_resource(owner, account)

    if account.group == "DomainAdmins":
        dec_limit_usage(owner, 'domain_admins_limit')
开发者ID:bearstech,项目名称:modoboa-admin-limits,代码行数:9,代码来源:controls.py


示例12: on_account_deleted

def on_account_deleted(account):
    owner = get_object_owner(account)
    if not owner.group in ["SuperAdmins", "Resellers"]:
        return

    move_pool_resource(owner, account)

    if account.group == "DomainAdmins":
        dec_limit(owner, 'domain_admins_limit')
开发者ID:juju2013,项目名称:modoboa,代码行数:9,代码来源:controls.py


示例13: move_pool_resource

def move_pool_resource(sender, account, role, **kwargs):
    """Move remaining resource to owner if needed."""
    owner = permissions.get_object_owner(account)
    if not owner or owner.is_superuser or owner.role != "Resellers":
        # Domain admins can't change the role so nothing to check.
        return

    if role not in ["DomainAdmins", "Resellers"]:
        utils.move_pool_resource(owner, account)
开发者ID:mvb9,项目名称:modoboa,代码行数:9,代码来源:handlers.py


示例14: on_account_modified

def on_account_modified(old, new):
    """Update limits when roles are updated"""
    owner = get_object_owner(old)
    if owner.group not in ["SuperAdmins", "Resellers"]:
        # Domain admins can't change the role so nothing to check.
        return

    if new.group not in ["DomainAdmins", "Resellers"]:
        move_pool_resource(owner, new)
开发者ID:mvb9,项目名称:modoboa,代码行数:9,代码来源:controls.py


示例15: dec_nb_domains

def dec_nb_domains(domain):
    owner = get_object_owner(domain)
    dec_limit(owner, 'domains_limit')
    for domalias in domain.domainalias_set.all():
        dec_nb_domaliases(domalias)
    for mailbox in domain.mailbox_set.all():
        dec_nb_mailboxes(mailbox)
    for mbalias in domain.alias_set.all():
        dec_nb_mbaliases(mbalias)
开发者ID:juju2013,项目名称:modoboa,代码行数:9,代码来源:controls.py


示例16: dec_nb_domains

def dec_nb_domains(domain, owner=None):
    if owner is None:
        owner = get_object_owner(domain)
    dec_limit_usage(owner, 'domains_limit')
    for domalias in domain.domainalias_set.all():
        dec_nb_domaliases(domalias)
    for mailbox in domain.mailbox_set.all():
        dec_nb_mailboxes(mailbox)
    for mbalias in domain.alias_set.all():
        dec_nb_mbaliases(mbalias)
开发者ID:bearstech,项目名称:modoboa-admin-limits,代码行数:10,代码来源:controls.py


示例17: save

 def save(self):
     owner = get_object_owner(self.account)
     for ltpl in LimitTemplates().templates:
         if ltpl[0] not in self.cleaned_data:
             continue
         l = self.account.limitspool.limit_set.get(name=ltpl[0])
         if not owner.is_superuser:
             self.allocate_from_pool(l, owner.limitspool)
         l.maxvalue = self.cleaned_data[ltpl[0]]
         l.save()
开发者ID:bearstech,项目名称:modoboa-admin-limits,代码行数:10,代码来源:forms.py


示例18: save

 def save(self):
     owner = get_object_owner(self.account)
     for name, ltpl in utils.get_user_limit_templates():
         fieldname = "{}_limit".format(name)
         if fieldname not in self.cleaned_data:
             continue
         l = self.account.userobjectlimit_set.get(name=name)
         if not owner.is_superuser:
             self.allocate_from_user(l, owner)
         l.max_value = self.cleaned_data[fieldname]
         l.save()
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:11,代码来源:forms.py


示例19: create_pool

def create_pool(user):
    owner = get_object_owner(user)
    if owner.group not in ['SuperAdmins', 'Resellers']:
        return
    if user.group == 'DomainAdmins':
        check_limit(owner, 'domain_admins_limit')
        inc_limit_usage(owner, 'domain_admins_limit')

    if user.group in ['DomainAdmins', 'Resellers']:
        p, created = LimitsPool.objects.get_or_create(user=user)
        p.create_limits(owner)
开发者ID:joelfranco,项目名称:modoboa,代码行数:11,代码来源:controls.py


示例20: save

    def save(self):
        from modoboa.lib.permissions import get_object_owner

        owner = get_object_owner(self.account)
        for ltpl in limits_tpl:
            if not ltpl[0] in self.cleaned_data:
                continue
            l = self.account.limitspool.limit_set.get(name=ltpl[0])
            if not owner.is_superuser:
                self.allocate_from_pool(l, owner.limitspool)
            l.maxvalue = self.cleaned_data[ltpl[0]]
            l.save()
开发者ID:Tdey,项目名称:modoboa,代码行数:12,代码来源:forms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python permissions.grant_access_to_object函数代码示例发布时间:2022-05-27
下一篇:
Python parameters.save_admin函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap