Skip to content

Commit

Permalink
fix: use upper case for user constants
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed May 31, 2024
1 parent 5b479c1 commit f6e4dfa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/server/operandi_server/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from operandi_server.exceptions import AuthenticationError, RegistrationError


async def create_user_if_not_available(
username: str, password: str, account_type: str, approved_user: bool = False
):
async def create_user_if_not_available(username: str, password: str, account_type: str, approved_user: bool = False):
# If the account is not available in the DB, create it
try:
await authenticate_user(username, password)
Expand Down Expand Up @@ -40,9 +38,7 @@ async def authenticate_user(email: str, password: str) -> str:
return db_user.account_type


async def register_user(
email: str, password: str, account_type: str, approved_user: bool = False
):
async def register_user(email: str, password: str, account_type: str, approved_user: bool = False):
salt, encrypted_password = encrypt_password(password)
try:
db_user = await db_get_user_account(email)
Expand Down
6 changes: 3 additions & 3 deletions src/server/operandi_server/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ async def user_register(self, email: str, password: str, account_type: str = "US
"""
Used for registration.
There are 3 account types:
1) Administrator
2) User
3) Harvester
1) ADMIN
2) USER
3) HARVESTER
Please contact the Operandi team to get your account verified.
Otherwise, the account will be non-functional.
Expand Down
6 changes: 3 additions & 3 deletions src/server/operandi_server/routers/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,20 @@ async def submit_to_rabbitmq_queue(
encoded_workflow_message = dumps(workflow_processing_message)

# Send the message to a queue based on the user_id
if user_account_type == "harvester":
if user_account_type == "HARVESTER":
self.logger.info(f"Pushing to the RabbitMQ queue for the harvester: {RABBITMQ_QUEUE_HARVESTER}")
self.rmq_publisher.publish_to_queue(
queue_name=RABBITMQ_QUEUE_HARVESTER,
message=encoded_workflow_message
)
elif user_account_type == "administrator" or user_account_type == "user":
elif user_account_type == "ADMIN" or user_account_type == "USER":
self.logger.info(f"Pushing to the RabbitMQ queue for the users: {RABBITMQ_QUEUE_USERS}")
self.rmq_publisher.publish_to_queue(
queue_name=RABBITMQ_QUEUE_USERS,
message=encoded_workflow_message
)
else:
account_types = ["user", "harvester", "admin"]
account_types = ["USER", "HARVESTER", "ADMIN"]
message = f"The user account type is not valid: {user_account_type}. Must be one of: {account_types}"
self.logger.error(f"{message}")
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=message)
Expand Down
4 changes: 2 additions & 2 deletions src/server/operandi_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ async def insert_default_accounts(self):
if default_admin_user and default_admin_pass:
await create_user_if_not_available(
username=default_admin_user, password=default_admin_pass,
account_type="administrator", approved_user=True
account_type="ADMIN", approved_user=True
)
self.log.info(f"Configured default server admin account")

self.log.info(f"Configuring default harvester account")
if default_harvester_user and default_harvester_pass:
await create_user_if_not_available(
username=default_harvester_user, password=default_harvester_pass,
account_type="harvester", approved_user=True
account_type="HARVESTER", approved_user=True
)
self.log.info(f"Configured default harvester account")

0 comments on commit f6e4dfa

Please sign in to comment.