class UserModel(db.Model, UserMixin): __tablename__ = dbtableprefix + 'user' id = db.Column(db.Integer, primary_key=True, unique=True) social_id = db.Column(db.String(255), nullable=False, unique=True) nickname = db.Column(db.String(255), nullable=False) email = db.Column(db.String(255), nullable=True, unique=True, index=True) confirmed_at = db.Column(db.DateTime()) active = db.Column('active', db.Boolean(), nullable=False, server_default='0') first_name = db.Column(db.String(255), nullable=False, server_default='') last_name = db.Column(db.String(255), nullable=False, server_default='') country = db.Column(db.String(3)) subdivisionfirst = db.Column(db.String(255)) subdivisionsecond = db.Column(db.String(255)) subdivisionthird = db.Column(db.String(255)) organization = db.Column(db.String(255)) timezone = db.Column(db.String(64)) language = db.Column(db.String(64)) user_auth = db.relationship('UserAuthModel', uselist=False, primaryjoin="UserAuthModel.user_id==UserModel.id", back_populates="user") roles = db.relationship('Role', secondary=dbtableprefix + 'user_roles', backref=db.backref(dbtableprefix + 'user', lazy='dynamic')) password = db.Column(db.String(255), nullable=False, server_default='') # work around a bug otp_secret = db.Column(db.String(255), nullable=True) pypi_username = db.Column(db.String(255), nullable=True) pypi_password = db.Column(db.String(255), nullable=True) modified_at = db.Column(db.DateTime()) last_login = db.Column(db.DateTime()) #email_is_phone_number = db.Column(db.Boolean(), nullable=True, server_default='0') limited_api = False def same_as(self, user_id): if self.limited_api: return False return self.id == user_id def has_role_or_permission(self, *specified_role_names, permissions=None): if self.limited_api: if isinstance(permissions, list): for task in permissions: if self.can_do(task): return True return False role_result = super().has_role(*specified_role_names) if not role_result and isinstance(permissions, list): for task in permissions: if self.can_do(task): return True return role_result def can_do(self, task): if self.is_anonymous: return False if self.limited_api: return bool(task in self.limits) if hasattr(self, 'roles'): roles = self.roles else: if hasattr(self, 'user_profile') and hasattr(self.user_profile, 'roles'): roles = self.user_profile.roles else: roles = None for role in roles: if role.name in allowed and task in allowed[role.name]: return True return False
class UserModel(db.Model, UserMixin): __tablename__ = dbtableprefix + 'user' id = db.Column(db.Integer, primary_key=True) social_id = db.Column(db.String(255), nullable=False, unique=True) nickname = db.Column(db.String(255), nullable=False) email = db.Column(db.String(255), nullable=True, unique=True) confirmed_at = db.Column(db.DateTime()) active = db.Column('active', db.Boolean(), nullable=False, server_default='0') first_name = db.Column(db.String(255), nullable=False, server_default='') last_name = db.Column(db.String(255), nullable=False, server_default='') country = db.Column(db.String(3)) subdivisionfirst = db.Column(db.String(255)) subdivisionsecond = db.Column(db.String(255)) subdivisionthird = db.Column(db.String(255)) organization = db.Column(db.String(255)) timezone = db.Column(db.String(64)) language = db.Column(db.String(64)) user_auth = db.relationship( 'UserAuthModel', uselist=False, primaryjoin="UserAuthModel.user_id==UserModel.id") roles = db.relationship('Role', secondary=dbtableprefix + 'user_roles', backref=db.backref(dbtableprefix + 'user', lazy='dynamic')) password = db.Column(db.String(255), nullable=False, server_default='') # work around a bug otp_secret = db.Column(db.String(255), nullable=True) pypi_username = db.Column(db.String(255), nullable=True) pypi_password = db.Column(db.String(255), nullable=True) modified_at = db.Column(db.DateTime())
class MachineLearning(db.Model): __tablename__ = dbtableprefix + "machinelearning" id = db.Column(db.Integer(), primary_key=True) group_id = db.Column(db.Text()) key = db.Column(db.Text()) independent = db.Column(db.Text()) dependent = db.Column(db.Text()) create_time = db.Column(db.DateTime()) modtime = db.Column(db.DateTime()) active = db.Column(db.Boolean(), nullable=False, server_default='0')
class Email(db.Model): __tablename__ = dbtableprefix + "email" id = db.Column(db.Integer(), primary_key=True, unique=True) short = db.Column(db.String(250), db.ForeignKey(dbtableprefix + 'shortener.short', ondelete='CASCADE')) all_addr = db.Column(db.Text()) to_addr = db.Column(db.Text()) cc_addr = db.Column(db.Text()) from_addr = db.Column(db.Text()) reply_to_addr = db.Column(db.Text()) return_path_addr = db.Column(db.Text()) subject = db.Column(db.Text()) datetime_message = db.Column(db.DateTime()) datetime_received = db.Column(db.DateTime())
class Supervisors(db.Model): __tablename__ = dbtableprefix + "supervisors" id = db.Column(db.Integer(), primary_key=True) hostname = db.Column(db.Text()) url = db.Column(db.Text()) start_time = db.Column(db.DateTime(), server_default=db.func.now()) role = db.Column(db.Text())
class UserDict(db.Model): __tablename__ = dbtableprefix + "userdict" indexno = db.Column(db.Integer(), primary_key=True) filename = db.Column(db.String(255), index=True) key = db.Column(db.String(250), index=True) dictionary = db.Column(db.Text()) user_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'user.id', ondelete='CASCADE')) encrypted = db.Column(db.Boolean(), nullable=False, server_default='1') modtime = db.Column(db.DateTime())
class Shortener(db.Model): __tablename__ = dbtableprefix + "shortener" id = db.Column(db.Integer(), primary_key=True, unique=True) short = db.Column(db.String(250), nullable=False, unique=True) filename = db.Column(db.String(255), index=True) uid = db.Column(db.String(250)) user_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'user.id', ondelete='CASCADE')) temp_user_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'tempuser.id', ondelete='CASCADE')) key = db.Column(db.String(255), index=True) index = db.Column(db.Integer()) modtime = db.Column(db.DateTime(), server_default=db.func.now())
class JsonStorage(db.Model): __tablename__ = dbtableprefix + "jsonstorage" id = db.Column(db.Integer(), primary_key=True, unique=True) filename = db.Column(db.String(255), index=True) key = db.Column(db.String(250), index=True) if dbprefix.startswith('postgresql'): data = db.Column(JSONB) else: data = db.Column(db.Text()) tags = db.Column(db.Text()) modtime = db.Column(db.DateTime(), server_default=db.func.now()) persistent = db.Column(db.Boolean(), nullable=False, server_default=false())
class ChatLog(db.Model): __tablename__ = dbtableprefix + "chatlog" id = db.Column(db.Integer(), primary_key=True, unique=True) filename = db.Column(db.String(255), index=True) key = db.Column(db.String(250), index=True) message = db.Column(db.Text()) user_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'user.id', ondelete='CASCADE')) temp_user_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'tempuser.id', ondelete='CASCADE')) owner_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'user.id', ondelete='CASCADE')) temp_owner_id = db.Column(db.Integer(), db.ForeignKey(dbtableprefix + 'tempuser.id', ondelete='CASCADE')) open_to_peer = db.Column(db.Boolean(), nullable=False, server_default='0') encrypted = db.Column(db.Boolean(), nullable=False, server_default='1') modtime = db.Column(db.DateTime())