<commit_before>"""Role module

Role data lives in the `roles` table, populated via:
    `python manage.py seed`

To restrict access to a given role, use the ROLE object:
    @roles_required(ROLE.ADMIN)

To extend the list of roles, add name: description pairs to the
STATIC_ROLES dict within.

"""
from ..extensions import db
from UserDict import IterableUserDict


class Role(db.Model):
    """SQLAlchemy class for `roles` table"""
    __tablename__ = 'roles'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(50), unique=True)
    description = db.Column(db.Text)

    def __str__(self):
        return "Role {}".format(self.name)

#Source definition for roles, as dictionary {name: description,}
STATIC_ROLES = IterableUserDict({
    'admin':
        'Administrator privledges, i.e. carte blanche',
    'anon':
        'Anonymous role - exclusive to accounts generated prior to '
        'user authentication',
    'application_developer':
        'Gives users permission to add/view/edit TrueNTH applications',
    'content_manager':
        'Gives user permission to add/view/edit associated content '
        'managment systems',
    'partner':
        "An intimate partner, use the partner relationship to define "
        "whom the patient's partner is",
    'patient':
        'Default role for all patients, may only view their own '
        'patient data',
    'provider':
        'Health care provider at a TrueNTH-collaborating clinic',
    'service':
        'Reserved for automated service accounts needing API access',
    'test':
        'Designates a testing user',
})


def enum(**items):
    """Convert dictionary to Enumeration for direct access"""
    return type('Enum', (), items)

ROLE = enum(**{unicode(r).upper():r for r in STATIC_ROLES})


def add_static_roles():
    """Seed database with default static roles

    Idempotent - run anytime to pick up any new roles in existing dbs

    """
    for r in STATIC_ROLES:
        if not Role.query.filter_by(name=r).first():
            db.session.add(Role(name=r, description=STATIC_ROLES[r]))
<commit_msg>Adding WRITE_ONLY role for new account, weak auth access.<commit_after>"""Role module

Role data lives in the `roles` table, populated via:
    `python manage.py seed`

To restrict access to a given role, use the ROLE object:
    @roles_required(ROLE.ADMIN)

To extend the list of roles, add name: description pairs to the
STATIC_ROLES dict within.

"""
from ..extensions import db
from UserDict import IterableUserDict


class Role(db.Model):
    """SQLAlchemy class for `roles` table"""
    __tablename__ = 'roles'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(50), unique=True)
    description = db.Column(db.Text)

    def __str__(self):
        return "Role {}".format(self.name)

#Source definition for roles, as dictionary {name: description,}
STATIC_ROLES = IterableUserDict({
    'admin':
        'Administrator privledges, i.e. <NAME>',
    'anon':
        'Anonymous role - exclusive to accounts generated prior to '
        'user authentication',
    'application_developer':
        'Gives users permission to add/view/edit TrueNTH applications',
    'content_manager':
        'Gives user permission to add/view/edit associated content '
        'managment systems',
    'partner':
        "An intimate partner, use the partner relationship to define "
        "whom the patient's partner is",
    'patient':
        'Default role for all patients, may only view their own '
        'patient data',
    'provider':
        'Health care provider at a TrueNTH-collaborating clinic',
    'service':
        'Reserved for automated service accounts needing API access',
    'test':
        'Designates a testing user',
    'write_only':
        'Limited access account, write only, cannot view data from '
        'previous sessions',
})


def enum(**items):
    """Convert dictionary to Enumeration for direct access"""
    return type('Enum', (), items)

ROLE = enum(**{unicode(r).upper():r for r in STATIC_ROLES})


def add_static_roles():
    """Seed database with default static roles

    Idempotent - run anytime to pick up any new roles in existing dbs

    """
    for r in STATIC_ROLES:
        if not Role.query.filter_by(name=r).first():
            db.session.add(Role(name=r, description=STATIC_ROLES[r]))

{'fraction_non_alphanumeric': 0.10550353962091802, 'fraction_numerical': 0.0009134505594884677, 'mean_word_length': 3.227799227799228, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2059251', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1250, 'n_words': 446}