fixed issued with role enum

This commit is contained in:
Peter Yefi 2023-01-10 20:30:55 -05:00
parent db9f286992
commit c434b5593f
4 changed files with 9 additions and 8 deletions

View File

@ -31,6 +31,6 @@ class DBSetup:
if type(user) is dict:
logger.info(user)
else:
print(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin}')
logger.info(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin}')
print(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin.value}')
logger.info(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin.value}')
print('Remember to change the admin default password and email address with the UserFactory')

View File

@ -16,8 +16,8 @@ from sqlalchemy.orm import relationship
class UserRoles(enum.Enum):
Admin = 'ADMIN'
HubReader = 'HUB_READER'
Admin = 'Admin'
Hub_Reader = 'HUB_READER'
class User(Base):
@ -28,7 +28,7 @@ class User(Base):
name = Column(String, nullable=False)
email = Column(String, nullable=False, unique=True)
password = Column(String, nullable=False)
role = Column(Enum(UserRoles), nullable=False, default=UserRoles.HubReader)
role = Column(Enum(UserRoles), nullable=False, default=UserRoles.Hub_Reader)
cities = relationship("City", back_populates="user")
created = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow)

View File

@ -108,7 +108,7 @@ class CityRepo(BaseRepo):
'name': city.name, 'srs_name': city.srs_name, 'country_code': city.country_code, 'longitude': city.longitude,
'latitude': city.latitude, 'time_zone': city.time_zone, 'lower_corner': city.lower_corner.tolist(),
'upper_corner': city.upper_corner.tolist(), 'climate_reference_city': city.climate_reference_city,
'updated': datetime.datetime.utcnow
'updated': datetime.datetime.utcnow()
})
self.session.commit()

View File

@ -45,7 +45,7 @@ class UserRepo(BaseRepo):
else:
return {'message': f'user with {email} email already exists'}
def update(self, user_id: int, name: str, email: str, password: str, role: UserRoles):
def update(self, user_id: int, name: str, email: str, password: str, role: UserRoles) -> Union[Dict, None]:
"""
Updates a user
:param user_id: the id of the user to be updated
@ -59,10 +59,11 @@ class UserRepo(BaseRepo):
if Auth.validate_password(password):
self.session.query(User).filter(User.id == user_id) \
.update({'name': name, 'email': email, 'password': Auth.hash_password(password), 'role': role,
'updated': datetime.datetime.utcnow})
'updated': datetime.datetime.utcnow()})
self.session.commit()
except SQLAlchemyError as err:
logger.error(f'Error while updating user: {err}')
return {'err_msg': 'Error occured while updated user'}
def get_by_email(self, email: str) -> [User]:
"""