<commit_before>from paste.deploy.converters import asbool
from pylons import tmpl_context as c

from adhocracy import config
from adhocracy.lib.auth.authorization import has
from adhocracy.lib.auth.authorization import NOT_LOGGED_IN


def is_not_demo(check, u):
    if u is not None:
        demo_users = config.get_list('adhocracy.demo_users')
        check.other('demo_user', u.user_name in demo_users)


def index(check):
    check.perm('user.view')


def show(check, u):
    check.perm('user.view')
    check.other('user_deleted', u.is_deleted())


def create(check):
    check.readonly()
    check.other('user_logged_in', c.user is not None)


def edit(check, u):
    check.readonly()
    if has('user.manage'):
        return
    show(check, u)
    check.other('user_not_self', u != c.user)
    check.other(NOT_LOGGED_IN, not c.user)
    is_not_demo(check, c.user)


def manage(check, u=None):
    """ Manage users on installation level """
    check.readonly()
    check.perm('user.manage')


def message(check, u):
    check.readonly()
    check.perm('user.message')
    check.other('user_is_self', u == c.user)
    if c.instance is not None:
        check.other('no_member_in_instance', not u.is_member(c.instance))


def badge(check, u):
    check.readonly()
    check.perm('user.badge')


def supervise(check, u):
    """ Supervise users on instance level """
    check.readonly()
    check.other('not_in_instance', not c.instance)
    check.other('no_member_in_instance', not u.is_member(c.instance))
    check.other('not_user.manage_or_instance.admin',
                not (has('user.manage') or has('instance.admin')))

<commit_msg>fixup "allow to change badge group only if can.user.supervise"<commit_after>from paste.deploy.converters import asbool
from pylons import tmpl_context as c

from adhocracy import config
from adhocracy.lib.auth.authorization import has
from adhocracy.lib.auth.authorization import NOT_LOGGED_IN


def is_not_demo(check, u):
    if u is not None:
        demo_users = config.get_list('adhocracy.demo_users')
        check.other('demo_user', u.user_name in demo_users)


def index(check):
    check.perm('user.view')


def show(check, u):
    check.perm('user.view')
    check.other('user_deleted', u.is_deleted())


def create(check):
    check.readonly()
    check.other('user_logged_in', c.user is not None)


def edit(check, u):
    check.readonly()
    if has('user.manage'):
        return
    show(check, u)
    check.other('user_not_self', u != c.user)
    check.other(NOT_LOGGED_IN, not c.user)
    is_not_demo(check, c.user)


def manage(check, u=None):
    """ Manage users on installation level """
    check.readonly()
    check.perm('user.manage')


def message(check, u):
    check.readonly()
    check.perm('user.message')
    check.other('user_is_self', u == c.user)
    if c.instance is not None:
        check.other('no_member_in_instance', not u.is_member(c.instance))


def badge(check, u):
    check.readonly()
    check.perm('user.badge')


def supervise(check, u=None):
    """ Supervise users on instance level """
    check.readonly()
    check.other('not_in_instance', not c.instance)
    if u is not None:
        check.other('no_member_in_instance', not u.is_member(c.instance))
    check.other('not_user.manage_or_instance.admin',
                not (has('user.manage') or has('instance.admin')))


{'fraction_non_alphanumeric': 0.13345195729537365, 'fraction_numerical': 0.0, 'mean_word_length': 3.6079234972677594, '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': '5371449', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1132, 'n_words': 255}