class Notification(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), index=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) timestamp = db.Column(db.Float(precision=15), index=True, default=time) payload_json = db.Column(db.Text) def get_data(self): return json.loads(str(self.payload_json))
class WildapricotGroup(BaseModel): """ Group information pulled from Wildapricot """ __tablename__ = 'wildapricot_group' wildapricot_group_id = db.Column(db.Integer, nullable=True) mcp_group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True)
class Log(BaseModel): """ Basic log template. """ log_level = db.Column(db.Enum(LogLevel), nullable=False) log_type = db.Column(db.String(20), nullable=False) event_type = db.Column(db.String(20), nullable=False) source_user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) target_user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) details = db.Column(db.String(1024), nullable=True) key_id = db.Column(db.String(20), nullable=True) # action = db.Column() def __repr__(self): return (f"Log('{self.log_type}')")
class WildapricotUser(BaseModel): """ User information pulled from Wildapricot """ __tablename__ = 'wildapricot_user' wildapricot_user_id = db.Column(db.Integer, nullable=True) mcp_user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) last_sync_time = db.Column(db.DateTime, nullable=True) def url(self): sub = settings.get('wildapricot', 'subdomain') url = f"https://{sub}.wildapricot.org/admin/contacts/details/?contactId={self.wildapricot_user_id}" return url
class Task(db.Model): id = db.Column(db.String(36), primary_key=True) name = db.Column(db.String(128), index=True) description = db.Column(db.String(128)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) complete = db.Column(db.Boolean, default=False) def get_rq_job(self): try: rq_job = rq.job.Job.fetch(self.id, connection=current_app.redis) except (redis.exceptions.RedisError, rq.exceptions.NoSuchJobError): return None return rq_job def get_progress(self): job = self.get_rq_job() return job.meta.get('progress', 0) if job is not None else 100
return json.loads(str(self.payload_json)) class Role(db.Model): """ Roles for granting granular access to users. """ __tablename__ = 'roles' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True) users_roles = db.Table( 'user_roles', db.Column('user_id', db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE')), db.Column('role_id', db.Integer(), db.ForeignKey('roles.id', ondelete='CASCADE')), ) # class UserRoles(db.Model): # """ # Links users to their roles. # """ # __tablename__ = 'user_roles' # __table_args__ = {'extend_existing': True} # id = db.Column(db.Integer(), primary_key=True) # user_id = db.Column(db.Integer(), db.ForeignKey('user.id', # ondelete='CASCADE')) # role_id = db.Column(db.Integer(), db.ForeignKey('roles.id',
from flask import current_app from mcp import db from mcp.main.models import BaseModel group_client = db.Table('group_client', db.Column('client_id', db.Integer, db.ForeignKey('client.id'), primary_key=True), db.Column('group_id', db.Integer, db.ForeignKey('group.id'), primary_key=True), extend_existing=True) class Client(BaseModel): """ Clients are client endpoints. Access is determined by group membership. """ __tablename__ = 'client' client_id = db.Column(db.Integer, unique=True) name = db.Column(db.String(32), unique=True, nullable=False) description = db.Column(db.String(500), nullable=True) # Relationships groups = db.relationship('Group', secondary=group_client, lazy='subquery',
from datetime import datetime from flask import current_app from mcp import db, ma from mcp.main.models import BaseModel user_group = db.Table( 'user_group', db.Column('group_id', db.Integer, db.ForeignKey('group.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True), extend_existing=True ) class Group(BaseModel): """ Basic user groups. """ __tablename__ = 'group' name = db.Column(db.String(100), unique=True, nullable=False) description = db.Column(db.String(500), nullable=True) # Relationships users = db.relationship('User', secondary=user_group, lazy='subquery', backref=db.backref('groups', lazy=True)) def __repr__(self): return(f"Group('{self.name}')")