city_retrofit/hub/persistence/models/user.py

43 lines
1.1 KiB
Python
Raw Permalink Normal View History

"""
Model representation of a User
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com
"""
import datetime
import enum
2023-02-01 06:05:12 -05:00
from sqlalchemy import Column, Integer, String, Sequence
from sqlalchemy import DateTime, Enum
from hub.persistence.configuration import Models
class UserRoles(enum.Enum):
2023-05-18 12:29:28 -04:00
"""
User roles enum
"""
2023-01-10 20:30:55 -05:00
Admin = 'Admin'
2023-01-13 18:42:11 -05:00
Hub_Reader = 'Hub_Reader'
class User(Models):
2023-02-01 06:05:12 -05:00
"""
A model representation of a city
"""
__tablename__ = 'user'
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
name = Column(String, nullable=False)
password = Column(String, nullable=False)
2023-01-10 20:30:55 -05:00
role = Column(Enum(UserRoles), nullable=False, default=UserRoles.Hub_Reader)
2023-01-31 13:11:39 -05:00
application_id = Column(Integer, nullable=False)
created = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow)
2023-01-31 13:11:39 -05:00
def __init__(self, name, password, role, application_id):
self.name = name
self.password = password
self.role = role
2023-01-31 13:11:39 -05:00
self.application_id = application_id