Skip to content

Commit

Permalink
fix: sms_settings attribute error on system settings (#83)
Browse files Browse the repository at this point in the history
* fix: sms_settings attribute error on system settings

* refactor: import send_sms for generate otp

Co-Authored-By: Assem Marwan <assem905@gmail.com>

* refactor: use hasattr for backward compatibility

Co-authored-by: Assem Marwan <assem905@gmail.com>
  • Loading branch information
e-lobo and assemmarwan authored Jan 26, 2022
1 parent 24a62e5 commit b11d59e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions renovation_core/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from frappe.utils.password import check_password, passlibctx, update_password
from renovation_core.utils import update_http_response

from .sms_setting import send_sms


@frappe.whitelist(allow_guest=True)
def generate_otp(medium="sms", medium_id=None, sms_hash=None, purpose="login", lang=None):
Expand All @@ -35,7 +33,7 @@ def generate_otp(medium="sms", medium_id=None, sms_hash=None, purpose="login", l
2. Accept-Language header or from frappe.session.user (done by frappe )
3. is user exists from medium_id (email or mobile) ie user.lang (ie Guest Users)
"""

from .sms_setting import send_sms
if medium not in ("sms", "email"):
frappe.throw(_("medium can only be 'sms' or 'email'"))

Expand Down
6 changes: 4 additions & 2 deletions renovation_core/utils/sms_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def send_sms(receiver_list, msg, sender_name='', success_msg=True, provider=None


def get_default_sms_providers():
system_settings = frappe.get_single("System Settings")
return system_settings.sms_providers or [frappe._dict(provider=system_settings.sms_settings)]
system_settings = frappe.get_single("System Settings")
return system_settings.sms_providers or (
[frappe._dict(provider=system_settings.sms_settings)] if hasattr(system_settings,
"sms_settings") else [])


def send_via_gateway(arg, providers):
Expand Down

0 comments on commit b11d59e

Please sign in to comment.