Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@rules.predicate
def is_any_tenant_admin(user):
return Membership.objects.filter(user=user, level=PermissionLevels.ADMIN).exists()
@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
@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
@rules.predicate
def is_owner(user, obj):
if obj is None:
return True
return obj.owner == user
@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()
@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
@rules.predicate
def is_own_writeup(user, writeup):
return writeup.id in [writeup.id for writeup in user.UserProfile.writeup_set.all()]
@rules.predicate
def has_solved_challenge(user, challenge):
solves = user.UserProfile.solves
return challenge.id in [solve.challenge.id for solve in solves]
@rules.predicate
def is_org_admin_for_object(user, obj):
return is_org_whatever_for_object(user, obj, OrganizationAdministrator)
@rules.predicate
def can_create_events(user, obj):
return user.is_administrator or user.teams.filter(can_create_events=True).exists()