<commit_before>#! /usr/bin/env python3

import barcode
import config

import collections
import datetime
import os

from odie import app, sqla
from api_utils import document_path, save_file
from db.documents import Document, Lecture, Examinant, Deposit
from .fields import ViewButton, UnvalidatedList

from flask import redirect, url_for
from flask_admin import Admin, BaseView, AdminIndexView, expose
from flask_admin.form import FileUploadField
from flask_admin.contrib.sqla import ModelView
from flask.ext.login import current_user
from sqlalchemy.inspection import inspect
from sqlalchemy.orm.properties import RelationshipProperty
from wtforms.validators import Optional

def _dateFormatter(attr_name):
    def f(v, c, m, n):
        d = getattr(m, attr_name)
        return d.date() if d else ''
    return f

class AuthViewMixin(BaseView):
    allowed_roles = config.ADMIN_PANEL_ALLOWED_GROUPS

    def is_accessible(self):
        return current_user.is_authenticated() \
                and any(True for perm in self.allowed_roles if current_user.has_permission(perm))

    def _handle_view(self, name, **kwargs):
        if not self.is_accessible():<commit_msg>admin: Use User.has_permission varargs<commit_after>#! /usr/bin/env python3

import barcode
import config

import collections
import datetime
import os

from odie import app, sqla
from api_utils import document_path, save_file
from db.documents import Document, Lecture, Examinant, Deposit
from .fields import ViewButton, UnvalidatedList

from flask import redirect, url_for
from flask_admin import Admin, BaseView, AdminIndexView, expose
from flask_admin.form import FileUploadField
from flask_admin.contrib.sqla import ModelView
from flask.ext.login import current_user
from sqlalchemy.inspection import inspect
from sqlalchemy.orm.properties import RelationshipProperty
from wtforms.validators import Optional

def _dateFormatter(attr_name):
    def f(v, c, m, n):
        d = getattr(m, attr_name)
        return d.date() if d else ''
    return f

class AuthViewMixin(BaseView):
    allowed_roles = config.ADMIN_PANEL_ALLOWED_GROUPS

    def is_accessible(self):
        return current_user.is_authenticated() and current_user.has_permission(*self.allowed_roles)

    def _handle_view(self, name, **kwargs):
        if not self.is_accessible():
{'fraction_non_alphanumeric': 0.06551724137931035, 'fraction_numerical': 0.0008620689655172414, 'mean_word_length': 4.759305210918114, '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': '2523089', 'n_tokens_mistral': 710, 'n_tokens_neox': 672, 'n_words': 218}