2024-11-15 01:18:23 +00:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2024-11-13 02:49:43 +00:00
|
|
|
from database import db_connection
|
2024-11-12 01:33:31 +00:00
|
|
|
|
2024-11-13 02:49:43 +00:00
|
|
|
|
|
|
|
class User(db_connection.Model):
|
2024-11-12 01:33:31 +00:00
|
|
|
__tablename__ = 'users'
|
|
|
|
|
2024-11-13 02:49:43 +00:00
|
|
|
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)
|
2024-11-15 01:18:23 +00:00
|
|
|
public_keys = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
|
2024-11-13 02:49:43 +00:00
|
|
|
orgs = db_connection.relationship('Organization', back_populates='owner')
|
|
|
|
files = db_connection.relationship('File', back_populates='creator')
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
return {
|
|
|
|
"id": self.id,
|
|
|
|
"username": self.username,
|
|
|
|
"full_name": self.full_name,
|
|
|
|
"email": self.email,
|
2024-11-15 01:18:23 +00:00
|
|
|
"public_keys": [{"org_id": org_id, "key": public_key} for org_id, public_key in self.public_keys.items()],
|
2024-11-13 02:49:43 +00:00
|
|
|
"orgs": [{"id": org.id, "name": org.name} for org in self.orgs],
|
|
|
|
"files": [{"id": file.id, "name": file.name, "file_handle": file.file_handle} for file in self.files]
|
|
|
|
}
|