diff --git a/renovation_core/fixtures/custom_field.json b/renovation_core/fixtures/custom_field.json index fb69287..42d0ed5 100644 --- a/renovation_core/fixtures/custom_field.json +++ b/renovation_core/fixtures/custom_field.json @@ -4,19 +4,19 @@ "allow_on_submit": 0, "app_name": "renovation_core", "bold": 0, - "collapsible": 0, + "collapsible": 1, "collapsible_depends_on": null, "columns": 0, "default": null, "depends_on": null, - "description": null, + "description": "Renovation Logging Settings", "docstatus": 0, "doctype": "Custom Field", - "dt": "Website Slideshow Item", + "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "alt", - "fieldtype": "Data", + "fieldname": "logging_sb", + "fieldtype": "Section Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -24,15 +24,15 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, - "in_list_view": 1, + "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "image", - "label": "Alt", + "insert_after": "use_socketio_to_upload_file", + "label": "Logging", "length": 0, "mandatory_depends_on": null, - "modified": "2019-02-26 16:04:16.518198", - "name": "Website Slideshow Item-alt", + "modified": "2019-12-20 20:27:55.184309", + "name": "System Settings-logging_sb", "no_copy": 0, "non_negative": 0, "options": null, @@ -69,7 +69,7 @@ "dt": "Website Slideshow Item", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "button_label", + "fieldname": "alt", "fieldtype": "Data", "hidden": 0, "hide_border": 0, @@ -81,12 +81,12 @@ "in_list_view": 1, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "alt", - "label": "Button Label", + "insert_after": "image", + "label": "Alt", "length": 0, "mandatory_depends_on": null, - "modified": "2019-02-26 16:04:17.397187", - "name": "Website Slideshow Item-button_label", + "modified": "2019-02-26 16:04:16.518198", + "name": "Website Slideshow Item-alt", "no_copy": 0, "non_negative": 0, "options": null, @@ -386,15 +386,15 @@ "collapsible_depends_on": null, "columns": 0, "default": null, - "depends_on": null, + "depends_on": "", "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Address", + "dt": "Notification", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "latitude", - "fieldtype": "Data", + "fieldname": "sms_providers", + "fieldtype": "Table", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -405,15 +405,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "disabled", - "label": "Latitude", + "insert_after": "sender", + "label": "SMS Providers", "length": 0, "mandatory_depends_on": null, - "modified": "2020-01-03 12:48:24.486067", - "name": "Address-latitude", + "modified": "2020-11-30 19:12:43.456509", + "name": "Notification-sms_providers", "no_copy": 0, "non_negative": 0, - "options": null, + "options": "Country Wise SMS Provider", "parent": null, "parentfield": null, "parenttype": null, @@ -440,15 +440,15 @@ "collapsible_depends_on": null, "columns": 0, "default": null, - "depends_on": "", + "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Notification", + "dt": "Address", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "sms_providers", - "fieldtype": "Table", + "fieldname": "latitude", + "fieldtype": "Data", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -459,15 +459,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "sender", - "label": "SMS Providers", + "insert_after": "disabled", + "label": "Latitude", "length": 0, "mandatory_depends_on": null, - "modified": "2020-11-30 19:12:43.456509", - "name": "Notification-sms_providers", + "modified": "2020-01-03 12:48:24.486067", + "name": "Address-latitude", "no_copy": 0, "non_negative": 0, - "options": "Country Wise SMS Provider", + "options": null, "parent": null, "parentfield": null, "parenttype": null, @@ -493,16 +493,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": null, + "default": "0", "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Address", + "dt": "Communication", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "longitude", - "fieldtype": "Data", + "fieldname": "disable", + "fieldtype": "Check", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -513,12 +513,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "latitude", - "label": "Longitude", + "insert_after": "sent_or_received", + "label": "Disable", "length": 0, "mandatory_depends_on": null, - "modified": "2020-01-03 12:48:16.174472", - "name": "Address-longitude", + "modified": "2020-06-28 19:29:43.738007", + "name": "Communication-disable", "no_copy": 0, "non_negative": 0, "options": null, @@ -535,7 +535,7 @@ "report_hide": 0, "reqd": 0, "search_index": 0, - "translatable": 1, + "translatable": 0, "unique": 0, "width": null }, @@ -547,16 +547,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": "0", + "default": null, "depends_on": null, "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "Communication", + "dt": "Address", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "disable", - "fieldtype": "Check", + "fieldname": "longitude", + "fieldtype": "Data", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -567,12 +567,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "sent_or_received", - "label": "Disable", + "insert_after": "latitude", + "label": "Longitude", "length": 0, "mandatory_depends_on": null, - "modified": "2020-06-28 19:29:43.738007", - "name": "Communication-disable", + "modified": "2020-01-03 12:48:16.174472", + "name": "Address-longitude", "no_copy": 0, "non_negative": 0, "options": null, @@ -589,7 +589,7 @@ "report_hide": 0, "reqd": 0, "search_index": 0, - "translatable": 0, + "translatable": 1, "unique": 0, "width": null }, @@ -601,16 +601,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": "15", - "depends_on": null, - "description": "In minutes", + "default": null, + "depends_on": "eval:doc.channel === \"FCM\"", + "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "System Settings", + "dt": "Notification", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "verification_otp_validity", - "fieldtype": "Int", + "fieldname": "fcm_recipients_sb", + "fieldtype": "Section Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -621,12 +621,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "session_expiry_mobile", - "label": "Verification OTP Validity", + "insert_after": "property_value", + "label": "FCM Recipients", "length": 0, "mandatory_depends_on": null, - "modified": "2020-07-14 14:50:49.175289", - "name": "System Settings-verification_otp_validity", + "modified": "2019-07-12 08:45:54.331926", + "name": "Notification-fcm_recipients_sb", "no_copy": 0, "non_negative": 0, "options": null, @@ -656,15 +656,15 @@ "collapsible_depends_on": null, "columns": 0, "default": null, - "depends_on": "eval:doc.channel === \"FCM\"", + "depends_on": "", "description": null, "docstatus": 0, "doctype": "Custom Field", "dt": "Notification", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "fcm_recipients_sb", - "fieldtype": "Section Break", + "fieldname": "fcm_recipients", + "fieldtype": "Table", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -675,15 +675,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "property_value", + "insert_after": "fcm_recipients_sb", "label": "FCM Recipients", "length": 0, "mandatory_depends_on": null, - "modified": "2019-07-12 08:45:54.331926", - "name": "Notification-fcm_recipients_sb", + "modified": "2019-07-12 08:45:59.033702", + "name": "Notification-fcm_recipients", "no_copy": 0, "non_negative": 0, - "options": null, + "options": "Notification FCM Target", "parent": null, "parentfield": null, "parenttype": null, @@ -709,16 +709,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": "6", - "depends_on": null, - "description": "In hours", + "default": null, + "depends_on": "eval:doc.channel === \"SMS\"", + "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "System Settings", + "dt": "Notification", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "quick_login_window", - "fieldtype": "Int", + "fieldname": "sms_recipients_sec", + "fieldtype": "Section Break", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -729,12 +729,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "verification_otp_validity", - "label": "Quick Login Window", + "insert_after": "fcm_recipients", + "label": "SMS Recipients Sec", "length": 0, "mandatory_depends_on": null, - "modified": "2020-07-14 09:36:21.007724", - "name": "System Settings-quick_login_window", + "modified": "2020-11-11 20:14:59.988111", + "name": "Notification-sms_recipients_sec", "no_copy": 0, "non_negative": 0, "options": null, @@ -763,16 +763,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": null, - "depends_on": "", - "description": null, + "default": "15", + "depends_on": null, + "description": "Otp expiration In minutes.
\nNote: If no value is specified otp validation will not work.", "docstatus": 0, "doctype": "Custom Field", - "dt": "Notification", + "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "fcm_recipients", - "fieldtype": "Table", + "fieldname": "verification_otp_validity", + "fieldtype": "Int", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -783,15 +783,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "fcm_recipients_sb", - "label": "FCM Recipients", + "insert_after": "session_expiry_mobile", + "label": "Verification OTP Validity", "length": 0, "mandatory_depends_on": null, - "modified": "2019-07-12 08:45:59.033702", - "name": "Notification-fcm_recipients", + "modified": "2022-07-24 14:33:22.058669", + "name": "System Settings-verification_otp_validity", "no_copy": 0, "non_negative": 0, - "options": "Notification FCM Target", + "options": null, "parent": null, "parentfield": null, "parenttype": null, @@ -817,16 +817,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": null, - "depends_on": "eval:doc.channel === \"SMS\"", - "description": null, + "default": "6", + "depends_on": null, + "description": "In hours", "docstatus": 0, "doctype": "Custom Field", - "dt": "Notification", + "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "sms_recipients_sec", - "fieldtype": "Section Break", + "fieldname": "quick_login_window", + "fieldtype": "Int", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -837,12 +837,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "fcm_recipients", - "label": "SMS Recipients Sec", + "insert_after": "verification_otp_validity", + "label": "Quick Login Window", "length": 0, "mandatory_depends_on": null, - "modified": "2020-11-11 20:14:59.988111", - "name": "Notification-sms_recipients_sec", + "modified": "2020-07-14 09:36:21.007724", + "name": "System Settings-quick_login_window", "no_copy": 0, "non_negative": 0, "options": null, @@ -1035,14 +1035,14 @@ "columns": 0, "default": null, "depends_on": null, - "description": null, + "description": "Check this if you would like to allow Guest socketio connections", "docstatus": 0, "doctype": "Custom Field", - "dt": "User", + "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "quick_login_pin", - "fieldtype": "Data", + "fieldname": "socketio_allow_guest", + "fieldtype": "Check", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1053,12 +1053,12 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "new_password", - "label": "Set New Quick Login Pin", + "insert_after": "allow_error_traceback", + "label": "Allow Guests to connect via Socket IO", "length": 0, "mandatory_depends_on": null, - "modified": "2020-07-14 19:12:49.614935", - "name": "User-quick_login_pin", + "modified": "2019-08-05 09:36:21.007724", + "name": "System Settings-socketio_allow_guest", "no_copy": 0, "non_negative": 0, "options": null, @@ -1087,16 +1087,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": null, + "default": "", "depends_on": null, - "description": "Check this if you would like to allow Guest socketio connections", + "description": "This template will be used to send email OTPs", "docstatus": 0, "doctype": "Custom Field", "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "socketio_allow_guest", - "fieldtype": "Check", + "fieldname": "email_otp_template", + "fieldtype": "Link", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1107,15 +1107,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "allow_error_traceback", - "label": "Allow Guests to connect via Socket IO", + "insert_after": "socketio_allow_guest", + "label": "Email OTP Template", "length": 0, "mandatory_depends_on": null, - "modified": "2019-08-05 09:36:21.007724", - "name": "System Settings-socketio_allow_guest", + "modified": "2020-07-14 15:50:49.175289", + "name": "System Settings-email_otp_template", "no_copy": 0, "non_negative": 0, - "options": null, + "options": "Email Template", "parent": null, "parentfield": null, "parenttype": null, @@ -1141,16 +1141,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": "", + "default": null, "depends_on": null, - "description": "This template will be used to send email OTPs", + "description": null, "docstatus": 0, "doctype": "Custom Field", - "dt": "System Settings", + "dt": "User", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "email_otp_template", - "fieldtype": "Link", + "fieldname": "quick_login_pin", + "fieldtype": "Data", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1161,15 +1161,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "socketio_allow_guest", - "label": "Email OTP Template", + "insert_after": "new_password", + "label": "Set New Quick Login Pin", "length": 0, "mandatory_depends_on": null, - "modified": "2020-07-14 15:50:49.175289", - "name": "System Settings-email_otp_template", + "modified": "2020-07-14 19:12:49.614935", + "name": "User-quick_login_pin", "no_copy": 0, "non_negative": 0, - "options": "Email Template", + "options": null, "parent": null, "parentfield": null, "parenttype": null, @@ -1249,16 +1249,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": "", - "depends_on": null, - "description": "This template will be used to send SMS OTPs", + "default": null, + "depends_on": "eval:doc.channel === \"FCM\"", + "description": "This can be used to send a data object along with the notification if required.\n\nPlease provide a python dictionary which can be given as a template optionally. eg: { \"name\": \"{{ doc.name }}\" }. Please note the quotes which is necessary for a well formed py.dict", "docstatus": 0, "doctype": "Custom Field", - "dt": "System Settings", + "dt": "Notification", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "sms_otp_template", - "fieldtype": "Link", + "fieldname": "fcm_data", + "fieldtype": "Code", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1269,15 +1269,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "sms_providers", - "label": "SMS OTP Template", + "insert_after": "message", + "label": "FCM Data", "length": 0, "mandatory_depends_on": null, - "modified": "2020-11-30 19:24:15.052897", - "name": "System Settings-sms_otp_template", + "modified": "2019-07-12 08:45:48.505087", + "name": "Notification-fcm_data", "no_copy": 0, "non_negative": 0, - "options": "SMS Template", + "options": null, "parent": null, "parentfield": null, "parenttype": null, @@ -1303,16 +1303,16 @@ "collapsible": 0, "collapsible_depends_on": null, "columns": 0, - "default": null, - "depends_on": "eval:doc.channel === \"FCM\"", - "description": "This can be used to send a data object along with the notification if required.\n\nPlease provide a python dictionary which can be given as a template optionally. eg: { \"name\": \"{{ doc.name }}\" }. Please note the quotes which is necessary for a well formed py.dict", + "default": "", + "depends_on": null, + "description": "This template will be used to send SMS OTPs", "docstatus": 0, "doctype": "Custom Field", - "dt": "Notification", + "dt": "System Settings", "fetch_from": null, "fetch_if_empty": 0, - "fieldname": "fcm_data", - "fieldtype": "Code", + "fieldname": "sms_otp_template", + "fieldtype": "Link", "hidden": 0, "hide_border": 0, "hide_days": 0, @@ -1323,15 +1323,15 @@ "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, - "insert_after": "message", - "label": "FCM Data", + "insert_after": "sms_providers", + "label": "SMS OTP Template", "length": 0, "mandatory_depends_on": null, - "modified": "2019-07-12 08:45:48.505087", - "name": "Notification-fcm_data", + "modified": "2020-11-30 19:24:15.052897", + "name": "System Settings-sms_otp_template", "no_copy": 0, "non_negative": 0, - "options": null, + "options": "SMS Template", "parent": null, "parentfield": null, "parenttype": null, @@ -1565,60 +1565,6 @@ "unique": 0, "width": null }, - { - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "app_name": "renovation_core", - "bold": 0, - "collapsible": 1, - "collapsible_depends_on": null, - "columns": 0, - "default": null, - "depends_on": null, - "description": "Renovation Logging Settings", - "docstatus": 0, - "doctype": "Custom Field", - "dt": "System Settings", - "fetch_from": null, - "fetch_if_empty": 0, - "fieldname": "logging_sb", - "fieldtype": "Section Break", - "hidden": 0, - "hide_border": 0, - "hide_days": 0, - "hide_seconds": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_preview": 0, - "in_standard_filter": 0, - "insert_after": "use_socketio_to_upload_file", - "label": "Logging", - "length": 0, - "mandatory_depends_on": null, - "modified": "2019-12-20 20:27:55.184309", - "name": "System Settings-logging_sb", - "no_copy": 0, - "non_negative": 0, - "options": null, - "parent": null, - "parentfield": null, - "parenttype": null, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "print_width": null, - "read_only": 0, - "read_only_depends_on": null, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "translatable": 0, - "unique": 0, - "width": null - }, { "allow_in_quick_entry": 0, "allow_on_submit": 0, diff --git a/renovation_core/hooks.py b/renovation_core/hooks.py index 5c63eef..80ea599 100644 --- a/renovation_core/hooks.py +++ b/renovation_core/hooks.py @@ -96,6 +96,7 @@ # before_install = "renovation_core.install.before_install" after_install = "renovation_core.install.after_install.after_install" after_migrate = "renovation_core.install.after_migrate.after_migrate" +after_sync = "renovation_core.install.after_sync.after_sync" # Desk Notifications # ------------------ diff --git a/renovation_core/install/after_sync.py b/renovation_core/install/after_sync.py new file mode 100644 index 0000000..56ca266 --- /dev/null +++ b/renovation_core/install/after_sync.py @@ -0,0 +1,13 @@ +import frappe +from frappe.utils import cint + + +def after_sync(): + set_default_system_settings_default_values() + + +def set_default_system_settings_default_values(): + meta = frappe.get_meta("System Settings") + df = meta.get_field("verification_otp_validity") + frappe.db.set_value("System Settings", "System Settings", "verification_otp_validity", + cint(df.default)) diff --git a/renovation_core/patches.txt b/renovation_core/patches.txt index 4a1c8c9..bafd5c3 100644 --- a/renovation_core/patches.txt +++ b/renovation_core/patches.txt @@ -2,3 +2,4 @@ renovation_core.patches.v1_1.detete_renovation_sms_pin_custom_field renovation_core.patches.v1_1.migrate_fcm_tokens_to_new_doctype renovation_core.patches.v1_1.delete_duplicate_fcm_tokens renovation_core.patches.v1_2.make_sms_provider_from_sms_setting +renovation_core.patches.v1_2.set_verification_otp_validity diff --git a/renovation_core/patches/v1_2/set_verification_otp_validity.py b/renovation_core/patches/v1_2/set_verification_otp_validity.py new file mode 100644 index 0000000..842d578 --- /dev/null +++ b/renovation_core/patches/v1_2/set_verification_otp_validity.py @@ -0,0 +1,8 @@ +import frappe +from frappe.utils import cint +from renovation_core.install.after_sync import set_default_system_settings_default_values + + +def execute(): + if not cint(frappe.db.get_value("System Settings", fieldname="verification_otp_validity")): + set_default_system_settings_default_values() diff --git a/renovation_core/utils/auth.py b/renovation_core/utils/auth.py index 6f5a396..6b3ea6b 100644 --- a/renovation_core/utils/auth.py +++ b/renovation_core/utils/auth.py @@ -61,8 +61,11 @@ def generate_otp(medium="sms", medium_id=None, sms_hash=None, purpose="login", l # saving the hashed pin, not the pin as is hashed_pin = passlibctx.hash(otp) - expires_in_sec = (cint(frappe.db.get_value( - "System Settings", None, "verification_otp_validity")) or 15) * 60 + verification_otp_validity = frappe.db.get_value( + "System Settings", None, "verification_otp_validity") + expires_in_sec = cint(verification_otp_validity) * 60 if verification_otp_validity else None + if not expires_in_sec: + return frappe._dict({"status": "fail", medium: medium_id}) frappe.cache().set_value( get_otp_redis_key(