La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB

# Planète Casio v5
# models.privs: Database models for groups and privilege management
from app import db
from config import V5Config
# Privileges are represented by strings (slugs), for instance "post-news" or
# "delete-own-posts". Belonging to a group automatically grants a user the
# privileges of that group; additionally, administrators (or any people with
# the "grant-special-privileges" privilege) can grant privileges on a per-user
# basis.
# SpecialPrivilege: Privilege manually granted to a user
class SpecialPrivilege(db.Model):
__tablename__ = 'special_privilege'
id = db.Column(db.Integer, primary_key=True)
# Member that is granted the privilege
mid = db.Column(db.Integer, db.ForeignKey(''), index=True)
# Privilege name
priv = db.Column(db.String(V5Config.PRIVS_MAXLEN))
def __init__(self, member, priv):
self.mid =
self.priv = priv
def __repr__(self):
return f'<Privilege "{self.priv}" of member #{mid}>'
# Group: User group, corresponds to a community role and a set of privileges
class Group(db.Model):
__tablename__ = 'group'
# Unique group ID
id = db.Column(db.Integer, primary_key=True)
# Full name, such as "Administrateur" or "Membre d'honneur".
name = db.Column(db.Unicode(50), unique=True)
# The CSS code should not assume any specific layout and typically applies
# to a text node. Use attributes like color, font-style, font-weight, etc.
css = db.Column(db.UnicodeText)
# Textual description
description = db.Column(db.UnicodeText)
# List of members (lambda delays evaluation)
members = db.relationship('Member', secondary=lambda:GroupMember,
def __init__(self, name, css, descr): = name
self.css = css
self.description = descr
self.members = []
def delete(self):
Deletes the group and the associated information:
* Group privileges
for gp in GroupPrivilege.query.filter_by(
def privs(self):
gps = GroupPrivilege.query.filter_by(
return sorted(gp.priv for gp in gps)
def __repr__(self):
return f'<Group "{}">'
# Many-to-many relation for users belonging to groups
GroupMember = db.Table('group_member', db.Model.metadata,
db.Column('gid', db.Integer, db.ForeignKey('')),
db.Column('uid', db.Integer, db.ForeignKey('')))
# Meny-to-many relationship for privileges granted to groups
class GroupPrivilege(db.Model):
__tablename__ = 'group_privilege'
id = db.Column(db.Integer, primary_key=True)
gid = db.Column(db.Integer, db.ForeignKey(''))
priv = db.Column(db.String(V5Config.PRIVS_MAXLEN))
def __init__(self, group, priv):
self.gid =
self.priv = priv