24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
from flask_sqlalchemy import SQLAlchemy
|
|
from database import db_connection
|
|
|
|
|
|
class User(db_connection.Model):
|
|
__tablename__ = 'users'
|
|
|
|
id = db_connection.Column(db_connection.Integer, primary_key=True, index=True)
|
|
username = db_connection.Column(db_connection.String, unique=True, index=True, nullable=False)
|
|
full_name = db_connection.Column(db_connection.String, nullable=False)
|
|
email = db_connection.Column(db_connection.String, unique=True, index=True, nullable=False)
|
|
roles = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
|
|
public_keys = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
|
|
orgs = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": self.id,
|
|
"username": self.username,
|
|
"full_name": self.full_name,
|
|
"email": self.email,
|
|
"roles": self.roles,
|
|
"orgs": [{"id": org_id, "name": org_data["name"], "status": org_data["status"]} for org_id, org_data in self.orgs.items()],
|
|
} |