fixed issued with role enum
This commit is contained in:
parent
db9f286992
commit
c434b5593f
|
@ -31,6 +31,6 @@ class DBSetup:
|
||||||
if type(user) is dict:
|
if type(user) is dict:
|
||||||
logger.info(user)
|
logger.info(user)
|
||||||
else:
|
else:
|
||||||
print(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}')
|
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')
|
print('Remember to change the admin default password and email address with the UserFactory')
|
||||||
|
|
|
@ -16,8 +16,8 @@ from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
|
||||||
class UserRoles(enum.Enum):
|
class UserRoles(enum.Enum):
|
||||||
Admin = 'ADMIN'
|
Admin = 'Admin'
|
||||||
HubReader = 'HUB_READER'
|
Hub_Reader = 'HUB_READER'
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
|
@ -28,7 +28,7 @@ class User(Base):
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
email = Column(String, nullable=False, unique=True)
|
email = Column(String, nullable=False, unique=True)
|
||||||
password = Column(String, nullable=False)
|
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")
|
cities = relationship("City", back_populates="user")
|
||||||
created = Column(DateTime, default=datetime.datetime.utcnow)
|
created = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
updated = Column(DateTime, default=datetime.datetime.utcnow)
|
updated = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
|
|
|
@ -108,7 +108,7 @@ class CityRepo(BaseRepo):
|
||||||
'name': city.name, 'srs_name': city.srs_name, 'country_code': city.country_code, 'longitude': city.longitude,
|
'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(),
|
'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,
|
'upper_corner': city.upper_corner.tolist(), 'climate_reference_city': city.climate_reference_city,
|
||||||
'updated': datetime.datetime.utcnow
|
'updated': datetime.datetime.utcnow()
|
||||||
})
|
})
|
||||||
|
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
|
|
@ -45,7 +45,7 @@ class UserRepo(BaseRepo):
|
||||||
else:
|
else:
|
||||||
return {'message': f'user with {email} email already exists'}
|
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
|
Updates a user
|
||||||
:param user_id: the id of the user to be updated
|
:param user_id: the id of the user to be updated
|
||||||
|
@ -59,10 +59,11 @@ class UserRepo(BaseRepo):
|
||||||
if Auth.validate_password(password):
|
if Auth.validate_password(password):
|
||||||
self.session.query(User).filter(User.id == user_id) \
|
self.session.query(User).filter(User.id == user_id) \
|
||||||
.update({'name': name, 'email': email, 'password': Auth.hash_password(password), 'role': role,
|
.update({'name': name, 'email': email, 'password': Auth.hash_password(password), 'role': role,
|
||||||
'updated': datetime.datetime.utcnow})
|
'updated': datetime.datetime.utcnow()})
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while updating user: {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]:
|
def get_by_email(self, email: str) -> [User]:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user