# Path: partify/database.py
# def init_db():
# def reinit_db():
# 
# Path: partify/models.py
# class User(db.Model):
#     """Represents a :class:`User` account.
# 
#     * **id**: The :class:`User`'s unique ID
#     * **name**: The :class:`User`'s display name
#     * **username**: The username of the user
#     * **password**: The user's password. Stored as a pass generated by
#         Werkzeug's generate_password_hash function, which computes an HMAC'd SHA1 hash
#         of the input.
#     * **privs**: A bitfield of the user's privileges. See :mod:`priv` for definitions
#     """
#     __tablename__ = "user"
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
#     name = db.Column(db.String(64))
#     username = db.Column(db.String(36), unique=True)
#     password = db.Column(db.String(256))
#     privs = db.Column(db.Integer)
# 
#     def __init__(self, name=None, username=None, password=None):
#         self.name = name
#         self.username = username
#         self.password = generate_password_hash(password)
#         self.privs = 0
# 
#     def __repr__(self):
#         return "<User %r with id %d>" % (self.name, self.id)


from partify.database import db
from partify.models import User

"""Data and functions for giving, revoking, and obtaining user privileges."""


privs = {
    "ADMIN_CONFIG": 0x01,
    "ADMIN_PLAYBACK": 0x02,
    "ADMIN_ADMIN": 0x04,
    "ADMIN_INTERFACE": 0x08
}

privs_in_english = {
    "ADMIN_CONFIG": "Modify configuration settings",
    "ADMIN_PLAYBACK": "Access playback controls",
    "ADMIN_ADMIN": "Modify user privileges",
    "ADMIN_INTERFACE": "View administration interface"
}

def give_user_privilege(user, priv):
    """Given a user (either a :class:`User` type or an ID), set the given privilege (identified by string) in the user's privilege list.

    :param user: The user to whom to give the privilege
    :type user: :class:`User` or a user ID
    :param priv: The privilege to give to the user.
    :type priv: string
    """
    if not isinstance(user, User):
        user = User.query.get(user)
    # Set the appropriate bit in the user's privileges bitfield
    user.privs |= privs[priv]

# Path: partify/database.py
# def init_db():
# def reinit_db():
# 
# Path: partify/models.py
# class User(db.Model):
#     """Represents a :class:`User` account.
# 
#     * **id**: The :class:`User`'s unique ID
#     * **name**: The :class:`User`'s display name
#     * **username**: The username of the user
#     * **password**: The user's password. Stored as a pass generated by
#         Werkzeug's generate_password_hash function, which computes an HMAC'd SHA1 hash
#         of the input.
#     * **privs**: A bitfield of the user's privileges. See :mod:`priv` for definitions
#     """
#     __tablename__ = "user"
#     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
#     name = db.Column(db.String(64))
#     username = db.Column(db.String(36), unique=True)
#     password = db.Column(db.String(256))
#     privs = db.Column(db.Integer)
# 
#     def __init__(self, name=None, username=None, password=None):
#         self.name = name
#         self.username = username
#         self.password = generate_password_hash(password)
#         self.privs = 0
# 
#     def __repr__(self):
#         return "<User %r with id %d>" % (self.name, self.id)


# Path: partify/priv.py
from partify.database import db
from partify.models import User


"""Data and functions for giving, revoking, and obtaining user privileges."""


privs = {
    "ADMIN_CONFIG": 0x01,
    "ADMIN_PLAYBACK": 0x02,
    "ADMIN_ADMIN": 0x04,
    "ADMIN_INTERFACE": 0x08
}

privs_in_english = {
    "ADMIN_CONFIG": "Modify configuration settings",
    "ADMIN_PLAYBACK": "Access playback controls",
    "ADMIN_ADMIN": "Modify user privileges",
    "ADMIN_INTERFACE": "View administration interface"
}

def give_user_privilege(user, priv):
    """Given a user (either a :class:`User` type or an ID), set the given privilege (identified by string) in the user's privilege list.

    :param user: The user to whom to give the privilege
    :type user: :class:`User` or a user ID
    :param priv: The privilege to give to the user.
    :type priv: string
    """
    if not isinstance(user, User):
        user = User.query.get(user)
    # Set the appropriate bit in the user's privileges bitfield
    user.privs |= privs[priv]

    db.session.add(user)