<commit_before>from radar.models.groups import GROUP_TYPE
from radar.roles import PERMISSION


def has_permission_for_patient(user, patient, permission):
    """Check that the the user has a permission on any of the groups
    they share with the patient."""

    if user.is_admin:
        grant = True
    else:
        # Groups in common with the patient
        group_users = intersect_groups_with_patient(user, patient, user_membership=True)

        # Check the user has the required permission
        grant = any(x.has_permission(permission) for x in group_users)

    return grant


def has_permission_for_user(user, other_user, permission, explicit=False):
    """Check that the the user has a permission on any of the groups
    they share with the user."""

    if user.is_admin:
        grant = True
    elif not explicit and user == other_user and permission in (PERMISSION.VIEW_USER, PERMISSION.EDIT_USER):
        # Users can view and edit themselves<commit_msg>Prevent users from editing frozen patients<commit_after>from radar.models.groups import GROUP_TYPE
from radar.roles import PERMISSION


def has_permission_for_patient(user, patient, permission):
    """Check that the the user has a permission on any of the groups
    they share with the patient."""

    if user.is_admin:
        grant = True
    elif permission == PERMISSION.EDIT_PATIENT and patient.frozen:
        # Can't edit frozen patients
        grant = False
    else:
        # Groups in common with the patient
        group_users = intersect_groups_with_patient(user, patient, user_membership=True)

        # Check the user has the required permission
        grant = any(x.has_permission(permission) for x in group_users)

    return grant


def has_permission_for_user(user, other_user, permission, explicit=False):
    """Check that the the user has a permission on any of the groups
    they share with the user."""

    if user.is_admin:
        grant = True
    elif not explicit and user == other_user and permission in (PERMISSION.VIEW_USER, PERMISSION.EDIT_USER):
        # Users can view and edit themselves
{'fraction_non_alphanumeric': 0.06258890469416785, 'fraction_numerical': 0.0, 'mean_word_length': 3.3595041322314048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7517224', 'n_tokens_mistral': 576, 'n_tokens_neox': 552, 'n_words': 223}