How to use the rules.predicate function in rules

To help you get started, we’ve selected a few rules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Uberspace / dino / src / dino / tenants / rules.py View on Github external
@rules.predicate
def is_any_tenant_admin(user):
    return Membership.objects.filter(user=user, level=PermissionLevels.ADMIN).exists()
github rdmorganiser / rdmo / rdmo / projects / rules.py View on Github external
@rules.predicate
def is_site_manager(user, project):
    if user.is_authenticated:
        return user.role.manager.filter(pk=project.site.pk).exists()
    else:
        return False
github letsmeet-click / letsmeet.click / letsmeet / communities / models.py View on Github external
@rules.predicate
def can_edit_community(user, community):
    if not user or not community:
        return False

    try:
        return community.community_subscriptions.get(user=user).role == CommunitySubscription.ROLE_OWNER
    except CommunitySubscription.DoesNotExist:
        return False
github paidem / guacozy / guacozy_server / backend / rules.py View on Github external
@rules.predicate
def is_owner(user, obj):
    if obj is None:
        return True
    return obj.owner == user
github pretalx / pretalx / src / pretalx / person / permissions.py View on Github external
@rules.predicate
def person_can_view_information(user, obj):
    event = obj.event
    submissions = event.submissions.filter(speakers__in=[user])
    if obj.include_submitters:
        return submissions.exists()
    if obj.exclude_unconfirmed:
        return submissions.filter(state=SubmissionStates.CONFIRMED).exists()
    return submissions.filter(
        state__in=[SubmissionStates.CONFIRMED, SubmissionStates.ACCEPTED]
    ).exists()
github paidem / guacozy / guacozy_server / backend / rules.py View on Github external
@rules.predicate
def has_inherited_permission(user, node):
    # check if user / group specified directly on this node
    if has_direct_permission(user, node):
        return True

    # check if user / group is specified on any ancestor
    for n in node.get_ancestors(ascending=True):
        if has_direct_permission(user, n):
            return True
github OpenToAllCTF / OTA-University / ctf_framework / rules.py View on Github external
@rules.predicate
def is_own_writeup(user, writeup):
    return writeup.id in [writeup.id for writeup in user.UserProfile.writeup_set.all()]
github OpenToAllCTF / OTA-University / ctf_framework / rules.py View on Github external
@rules.predicate
def has_solved_challenge(user, challenge):
    solves = user.UserProfile.solves
    return challenge.id in [solve.challenge.id for solve in solves]
github AtelierSoude / OpenRepairPlatform / plateformeweb / rules.py View on Github external
@rules.predicate
def is_org_admin_for_object(user, obj):
    return is_org_whatever_for_object(user, obj, OrganizationAdministrator)
github pretalx / pretalx / src / pretalx / orga / permissions.py View on Github external
@rules.predicate
def can_create_events(user, obj):
    return user.is_administrator or user.teams.filter(can_create_events=True).exists()