refactor: use frappe.get_system_settings
because it's cached and doesn't hit frappe.db at all.
This commit is contained in:
parent
dd839e4d50
commit
7487df22c9
9 changed files with 20 additions and 30 deletions
|
|
@ -274,9 +274,7 @@ class LoginManager:
|
|||
if self.user in frappe.STANDARD_USERS:
|
||||
return False
|
||||
|
||||
reset_pwd_after_days = cint(
|
||||
frappe.db.get_single_value("System Settings", "force_user_to_reset_password")
|
||||
)
|
||||
reset_pwd_after_days = cint(frappe.get_system_settings("force_user_to_reset_password"))
|
||||
|
||||
if reset_pwd_after_days:
|
||||
last_password_reset_date = (
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class AddressTemplate(Document):
|
|||
|
||||
if not self.is_default and not self._get_previous_default():
|
||||
self.is_default = 1
|
||||
if frappe.db.get_single_value("System Settings", "setup_complete"):
|
||||
if frappe.get_system_settings("setup_complete"):
|
||||
frappe.msgprint(_("Setting this Address Template as default as there is no other default"))
|
||||
|
||||
def on_update(self):
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class CommunicationEmailMixin:
|
|||
return get_formatted_email(self.mail_sender_fullname(), mail=self.mail_sender())
|
||||
|
||||
def get_content(self, print_format=None):
|
||||
if print_format and frappe.db.get_single_value("System Settings", "attach_view_link"):
|
||||
if print_format and frappe.get_system_settings("attach_view_link"):
|
||||
return self.content + self.get_attach_link(print_format)
|
||||
return self.content
|
||||
|
||||
|
|
|
|||
|
|
@ -725,12 +725,8 @@ class User(Document):
|
|||
3. If allow_login_using_user_name is set, you can use username while finding the user.
|
||||
"""
|
||||
|
||||
login_with_mobile = cint(
|
||||
frappe.db.get_single_value("System Settings", "allow_login_using_mobile_number")
|
||||
)
|
||||
login_with_username = cint(
|
||||
frappe.db.get_single_value("System Settings", "allow_login_using_user_name")
|
||||
)
|
||||
login_with_mobile = cint(frappe.get_system_settings("allow_login_using_mobile_number"))
|
||||
login_with_username = cint(frappe.get_system_settings("allow_login_using_user_name"))
|
||||
|
||||
or_filters = [{"name": user_name}]
|
||||
if login_with_mobile:
|
||||
|
|
@ -840,8 +836,8 @@ def update_password(
|
|||
else:
|
||||
user = res["user"]
|
||||
|
||||
logout_all_sessions = cint(logout_all_sessions) or frappe.db.get_single_value(
|
||||
"System Settings", "logout_on_password_reset"
|
||||
logout_all_sessions = cint(logout_all_sessions) or frappe.get_system_settings(
|
||||
"logout_on_password_reset"
|
||||
)
|
||||
_update_password(user, new_password, logout_all_sessions=cint(logout_all_sessions))
|
||||
|
||||
|
|
@ -933,7 +929,7 @@ def _get_user_for_update_password(key, old_password):
|
|||
result.user, last_reset_password_key_generated_on = user or (None, None)
|
||||
if result.user:
|
||||
reset_password_link_expiry = cint(
|
||||
frappe.db.get_single_value("System Settings", "reset_password_link_expiry_duration")
|
||||
frappe.get_system_settings("reset_password_link_expiry_duration")
|
||||
)
|
||||
if (
|
||||
reset_password_link_expiry
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def get_notifications():
|
|||
"open_count_doctype": {},
|
||||
"targets": {},
|
||||
}
|
||||
if frappe.flags.in_install or not frappe.db.get_single_value("System Settings", "setup_complete"):
|
||||
if frappe.flags.in_install or not frappe.get_system_settings("setup_complete"):
|
||||
return out
|
||||
|
||||
config = get_notification_config()
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class AutoEmailReport(Document):
|
|||
|
||||
max_reports_per_user = (
|
||||
cint(frappe.local.conf.max_reports_per_user) # kept for backward compatibilty
|
||||
or cint(frappe.db.get_single_value("System Settings", "max_auto_email_report_per_user"))
|
||||
or cint(frappe.get_system_settings("max_auto_email_report_per_user"))
|
||||
or 20
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ def check_google_calendar(account, google_calendar):
|
|||
# If no Calendar ID create a new Calendar
|
||||
calendar = {
|
||||
"summary": account.calendar_name,
|
||||
"timeZone": frappe.db.get_single_value("System Settings", "time_zone"),
|
||||
"timeZone": frappe.get_system_settings("time_zone"),
|
||||
}
|
||||
created_calendar = google_calendar.calendars().insert(body=calendar).execute()
|
||||
frappe.db.set_value(
|
||||
|
|
|
|||
|
|
@ -43,11 +43,9 @@ def toggle_two_factor_auth(state, roles=None):
|
|||
|
||||
def two_factor_is_enabled(user=None):
|
||||
"""Return True if 2FA is enabled."""
|
||||
enabled = cint(frappe.db.get_single_value("System Settings", "enable_two_factor_auth"))
|
||||
enabled = cint(frappe.get_system_settings("enable_two_factor_auth"))
|
||||
if enabled:
|
||||
bypass_two_factor_auth = cint(
|
||||
frappe.db.get_single_value("System Settings", "bypass_2fa_for_retricted_ip_users")
|
||||
)
|
||||
bypass_two_factor_auth = cint(frappe.get_system_settings("bypass_2fa_for_retricted_ip_users"))
|
||||
if bypass_two_factor_auth and user:
|
||||
user_doc = frappe.get_doc("User", user)
|
||||
restrict_ip_list = (
|
||||
|
|
@ -144,7 +142,7 @@ def get_otpsecret_for_(user):
|
|||
|
||||
|
||||
def get_verification_method():
|
||||
return frappe.db.get_single_value("System Settings", "two_factor_method")
|
||||
return frappe.get_system_settings("two_factor_method")
|
||||
|
||||
|
||||
def confirm_otp_token(login_manager, otp=None, tmp_id=None):
|
||||
|
|
@ -190,7 +188,7 @@ def confirm_otp_token(login_manager, otp=None, tmp_id=None):
|
|||
|
||||
|
||||
def get_verification_obj(user, token, otp_secret):
|
||||
otp_issuer = frappe.db.get_single_value("System Settings", "otp_issuer_name")
|
||||
otp_issuer = frappe.get_system_settings("otp_issuer_name")
|
||||
verification_method = get_verification_method()
|
||||
verification_obj = None
|
||||
if verification_method == "SMS":
|
||||
|
|
@ -263,7 +261,7 @@ def process_2fa_for_email(user, token, otp_secret, otp_issuer, method="Email"):
|
|||
def get_email_subject_for_2fa(kwargs_dict):
|
||||
"""Get email subject for 2fa."""
|
||||
subject_template = _("Login Verification Code from {}").format(
|
||||
frappe.db.get_single_value("System Settings", "otp_issuer_name")
|
||||
frappe.get_system_settings("otp_issuer_name")
|
||||
)
|
||||
return frappe.render_template(subject_template, kwargs_dict)
|
||||
|
||||
|
|
@ -281,7 +279,7 @@ def get_email_body_for_2fa(kwargs_dict):
|
|||
def get_email_subject_for_qr_code(kwargs_dict):
|
||||
"""Get QRCode email subject."""
|
||||
subject_template = _("One Time Password (OTP) Registration Code from {}").format(
|
||||
frappe.db.get_single_value("System Settings", "otp_issuer_name")
|
||||
frappe.get_system_settings("otp_issuer_name")
|
||||
)
|
||||
return frappe.render_template(subject_template, kwargs_dict)
|
||||
|
||||
|
|
@ -299,7 +297,7 @@ def get_link_for_qrcode(user, totp_uri):
|
|||
key = frappe.generate_hash(length=20)
|
||||
key_user = f"{key}_user"
|
||||
key_uri = f"{key}_uri"
|
||||
lifespan = int(frappe.db.get_single_value("System Settings", "lifespan_qrcode_image")) or 240
|
||||
lifespan = int(frappe.get_system_settings("lifespan_qrcode_image")) or 240
|
||||
frappe.cache.set_value(key_uri, totp_uri, expires_in_sec=lifespan)
|
||||
frappe.cache.set_value(key_user, user, expires_in_sec=lifespan)
|
||||
return get_url(f"/qrcode?k={key}")
|
||||
|
|
@ -433,7 +431,7 @@ def should_remove_barcode_image(barcode):
|
|||
"""Check if it's time to delete barcode image from server."""
|
||||
if isinstance(barcode, str):
|
||||
barcode = frappe.get_doc("File", barcode)
|
||||
lifespan = frappe.db.get_single_value("System Settings", "lifespan_qrcode_image") or 240
|
||||
lifespan = frappe.get_system_settings("lifespan_qrcode_image") or 240
|
||||
if time_diff_in_seconds(get_datetime(), barcode.creation) > int(lifespan):
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ default_feedback: "PasswordStrengthFeedback" = {
|
|||
def get_feedback(score: int, sequence: list) -> "PasswordStrengthFeedback":
|
||||
"""Return the feedback dictionary consisting of ("warning","suggestions") for the given sequences."""
|
||||
global default_feedback
|
||||
minimum_password_score = int(
|
||||
frappe.db.get_single_value("System Settings", "minimum_password_score") or 2
|
||||
)
|
||||
minimum_password_score = int(frappe.get_system_settings("minimum_password_score") or 2)
|
||||
|
||||
# Starting feedback
|
||||
if len(sequence) == 0:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue