<commit_before># -*- coding: utf-8 -*-

"""
byceps.services.authorization.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2016 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from sqlalchemy.ext.associationproxy import association_proxy

from ...blueprints.user.models.user import User
from ...database import db
from ...util.instances import ReprBuilder


class Permission(db.Model):
    """A permission for a specific task.

    Can be assigned to one or more roles.
    """
    __tablename__ = 'authz_permissions'

    id = db.Column(db.Unicode(40), primary_key=True)
    title = db.deferred(db.Column(db.Unicode(80), unique=True))

    roles = association_proxy('role_permissions', 'role')

    def __init__(self, id, title=None):
        self.id = id
        self.title = title

    def __repr__(self):
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .build()


class Role(db.Model):
    """A role.

    Combines one or more permissions.
<commit_msg>Require title on permission creation<commit_after># -*- coding: utf-8 -*-

"""
byceps.services.authorization.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2016 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from sqlalchemy.ext.associationproxy import association_proxy

from ...blueprints.user.models.user import User
from ...database import db
from ...util.instances import ReprBuilder


class Permission(db.Model):
    """A permission for a specific task.

    Can be assigned to one or more roles.
    """
    __tablename__ = 'authz_permissions'

    id = db.Column(db.Unicode(40), primary_key=True)
    title = db.deferred(db.Column(db.Unicode(80), unique=True, nullable=False))

    roles = association_proxy('role_permissions', 'role')

    def __init__(self, id, title):
        self.id = id
        self.title = title

    def __repr__(self):
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .build()


class Role(db.Model):
    """A role.

    Combines one or more permissions.

{'fraction_non_alphanumeric': 0.15410628019323672, 'fraction_numerical': 0.012560386473429951, 'mean_word_length': 3.226530612244898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1444076', 'n_tokens_mistral': 656, 'n_tokens_neox': 617, 'n_words': 165}