Skip to content

Core updates#13

Open
akash1mgs wants to merge 19 commits intomainfrom
core-updates
Open

Core updates#13
akash1mgs wants to merge 19 commits intomainfrom
core-updates

Conversation

@akash1mgs
Copy link
Copy Markdown
Collaborator

@akash1mgs akash1mgs commented Jul 9, 2025


DeputyDev generated PR summary:


Size XL: This PR changes include 635 lines and should take approximately 3-6 hours to review


The pull request titled "Core updates" involves several significant changes to the codebase:

  1. Dependency Updates:

    • Updated several dependencies in the Pipfile, changing version numbers and switching the Git protocol from HTTPS to SSH for accessing certain repositories.
  2. Constants and Configurations:

    • Added and modified various constants across the application, such as URL patterns, device limits, and message templates.
    • Introduced new classes and enums to manage event priorities and types.
  3. Code Enhancements:

    • Refactored functions to improve modularity and maintainability, such as separating the logic for updating triggers and actions.
    • Added new functionalities like previewing email templates and subtemplates, fetching, and updating event data.
  4. Database and Model Changes:

    • Modified existing models by adding new fields like type for push notifications and content_length for logs.
    • Added several new migration scripts to accommodate these model changes.
  5. Service and Client Integration:

    • Introduced service clients for authentication and AWS Lambda invocation, facilitating operations like URL shortening and user authentication.
    • Implemented new service layers and controllers to handle webhooks and callbacks more effectively.
  6. Logging and Error Handling:

    • Enhanced logging with more detailed information for incoming requests and actions taken.
    • Improved error and exception handling throughout the services, including custom exception handlers for event loops.
  7. Utilities and Helpers:

    • Added utility functions to aid in tasks like URL shortening, string truncation, and list operations.
  8. Template and Styling Updates:

    • Updated email templates, styles, and added new design elements to the footer.

Overall, the pull request introduces significant enhancements and updates to dependencies, configurations, service clients, database models, utilities, and templates.


DeputyDev generated PR summary until 3aed402

@deputydev-agent
Copy link
Copy Markdown

DeputyDev has started reviewing your pull request.

Comment thread app/constants/providers.py Outdated
"verification": "PHARMACY"
},
"AUTHORIZATION": {
"CORPORATE": "Basic VkN6SjkxZVQ3SkV6R2sxdmtMblZkb092M1dHUVR2RXZ2ekVUVlJBNHZsTTo=",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SECURITY: Hardcoded Base64 encoded authorization tokens found in the WhatsApp provider configuration. These appear to be Basic Authentication credentials which contain encoded username:password pairs.
Hardcoded credentials in source code present a significant security risk as they could be extracted by anyone with access to the codebase. These credentials could potentially be used to gain unauthorized access to the WhatsApp API. Base64 encoding is easily reversible and does not provide security. Credentials should be stored in environment variables or a secure credential management system rather than in code.

AUTHORIZATION = {
  "CORPORATE": "${CORPORATE_AUTH_TOKEN}",
  "DEFAULT": "${DEFAULT_AUTH_TOKEN}",
  "DIAGNOSTICS": "${DIAGNOSTICS_AUTH_TOKEN}",
  "PHARMACY": "${PHARMACY_AUTH_TOKEN}"
}

Comment thread app/routes/middleware/authentication.py Outdated
request.ctx.user = user_result.get("email")

@classmethod
def validate_roles(cls, user_object, roles):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SECURITY: The role validation logic has a flaw where it first checks if the user has any app role but then doesn't verify the permissions within those specific apps.
The current implementation has a potential authorization bypass issue. It first checks if the user has roles for any of the apps, but then proceeds to check roles across all apps even if the user doesn't have roles for that specific app. This could allow a user with some app role but incorrect permissions to gain access. The validation should first confirm the user has roles for the specific apps and then check the permissions within those specific apps.

async def validate_roles(cls, user_object, roles):
    if user_object is None:
        raise UnAuthorizeException("user is not authorized")
        
    # Check if user has any of the required app roles
    app_roles_found = [app for app in [cls.APP_NAME, cls.LARA_APP] if app in user_object["roles"]]
    if not app_roles_found:
        raise UnAuthorizeException("user is not authorized")
        
    # Check if user has any of the required roles
    authenticated = False
    for app in app_roles_found:
        for user_role in user_object["roles"].get(app, []):
            if user_role in roles:
                authenticated = True
                break
        if authenticated:
            break
            
    if not authenticated:
        raise ForbiddenException("user is not permitted")

Comment thread config_template.json Outdated
},
"TEST_ENVIRONMENT": false,
"TEST_ALLOWED_EMAILS": [],
"TEST_ENVIRONMENT": true,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SECURITY: The configuration template sets TEST_ENVIRONMENT to true and contains a specific email in TEST_ALLOWED_EMAILS which could lead to security bypasses in production.
Setting TEST_ENVIRONMENT to true in the configuration template creates a risk that production environments could accidentally run with test settings enabled. This could bypass security controls designed for production use. Additionally, including specific test email addresses in the template could lead to unintended access in production environments if the template is not properly customized. Default configurations should always use the most secure settings, requiring explicit relaxation for test environments.

"TEST_ENVIRONMENT": false,
"TEST_ALLOWED_EMAILS": [],

@deputydev-agent
Copy link
Copy Markdown

DeputyDev has completed a review of your pull request for commit 3aed402.

Comment thread app/constants/event.py
from commonutils.utils import CustomEnum


class EventPriority(CustomEnum):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilise the existing one

Comment thread app/listeners/listener.py
:return: None
"""
message = context.get("message")
if message not in ["Unclosed connector", "Unclosed client session"]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check if this for excluding these only.

return request_body["source_identifier"]
def get_source_identifier_for_event(cls, event_name, request_body):
# TODO add more logic for other apps of needed
source_identifier = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discuss?

APNS = {
"name": "Apple Push Notification Service",
"code": "APNS",
"logo": "https://raw.githubusercontent.com/tata1mg/notifyone-core/refs/heads/notifyone/issues/14/media/logo/apns.png",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

"CAPACITY": 0,
"AUTHORIZATION_TOKEN": ""
"APP_AUTHORIZATIONS": {
"corporate-service": "CORPORATE",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in config and not part of code.

Comment thread app/routes/email.py
@email_blueprint.route("/email/subtemplate/<id:int>", methods=["PUT"], name="update_email_subtemplate")
async def update_email_subtemplate(request: Request, id: int):
payload = request.custom_json()
user_email = "admin@ns.com"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Comment thread app/routes/event.py
@event_blueprint.route("/event/<event_id:int>", methods=["PUT"], name="update_event")
async def update_event(request: Request, event_id: int):
data = request.custom_json()
data["user_email"] = "temp@ns.com"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Comment thread app/routes/push.py

push_apis = Blueprint("PushAPIs")


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove please.

Comment thread app/routes/sms.py

sms_apis = Blueprint("SmsAPIs")


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove please.

Comment thread app/service.py
from redis_wrapper import RegisterRedis


from redis_wrapper import RegisterRedis
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecesary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants