From 4a8884849777b928ae7f40d75be3534fa94d476c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 30 Sep 2020 14:03:12 +0530 Subject: [PATCH] feat: set default provider icons --- .../doctype/social_login_key/social_login_key.json | 6 +++++- .../doctype/social_login_key/social_login_key.py | 14 ++++++++++++++ frappe/patches.txt | 1 + frappe/patches/v13_0/set_social_icons.py | 9 +++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 frappe/patches/v13_0/set_social_icons.py diff --git a/frappe/integrations/doctype/social_login_key/social_login_key.json b/frappe/integrations/doctype/social_login_key/social_login_key.json index 6c0fbdb26c..33c8ca873d 100644 --- a/frappe/integrations/doctype/social_login_key/social_login_key.json +++ b/frappe/integrations/doctype/social_login_key/social_login_key.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_import": 1, "creation": "2017-11-18 15:36:09.676722", "doctype": "DocType", @@ -82,6 +83,7 @@ "label": "Identity Details" }, { + "depends_on": "eval:!['Facebook', 'Frappe', 'Github', 'Google', 'Office 365'].includes(doc.social_login_provider)", "fieldname": "icon", "fieldtype": "Data", "label": "Icon" @@ -157,7 +159,9 @@ "label": "User ID Property" } ], - "modified": "2019-12-03 13:13:46.989099", + "index_web_pages_for_search": 1, + "links": [], + "modified": "2020-09-30 13:40:57.597276", "modified_by": "Administrator", "module": "Integrations", "name": "Social Login Key", diff --git a/frappe/integrations/doctype/social_login_key/social_login_key.py b/frappe/integrations/doctype/social_login_key/social_login_key.py index 81df3cca97..92d245bffb 100644 --- a/frappe/integrations/doctype/social_login_key/social_login_key.py +++ b/frappe/integrations/doctype/social_login_key/social_login_key.py @@ -20,6 +20,7 @@ class SocialLoginKey(Document): self.name = frappe.scrub(self.provider_name) def validate(self): + self.set_icon() if self.custom_base_url and not self.base_url: frappe.throw(_("Please enter Base URL"), exc=BaseUrlNotSetError) if not self.authorize_url: @@ -33,6 +34,19 @@ class SocialLoginKey(Document): if self.enable_social_login and not self.client_secret: frappe.throw(_("Please enter Client Secret before social login is enabled"), exc=ClientSecretNotSetError) + def set_icon(self): + icon_map = { + "Google": "google.svg", + "Frappe": "frappe.svg", + "Facebook": "facebook.svg", + "Office 365": "office_365.svg", + "GitHub": "github.svg" + } + + if self.provider_name in icon_map: + icon_file = icon_map[self.provider_name] + self.icon = '/assets/frappe/icons/social/{0}'.format(icon_file) + def get_social_login_provider(self, provider, initialize=False): providers = {} diff --git a/frappe/patches.txt b/frappe/patches.txt index 985911314e..acbfb7b4aa 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -304,3 +304,4 @@ frappe.patches.v13_0.increase_password_length frappe.patches.v13_0.add_toggle_width_in_navbar_settings frappe.patches.v13_0.rename_notification_fields frappe.patches.v13_0.remove_duplicate_navbar_items +frappe.patches.v13_0.set_social_icons \ No newline at end of file diff --git a/frappe/patches/v13_0/set_social_icons.py b/frappe/patches/v13_0/set_social_icons.py new file mode 100644 index 0000000000..b1c63b48e0 --- /dev/null +++ b/frappe/patches/v13_0/set_social_icons.py @@ -0,0 +1,9 @@ +import frappe + +def execute(): + providers = frappe.get_all("Social Login Key") + + for provider in providers: + doc = frappe.get_doc("Social Login Key", provider) + doc.set_icon() + doc.save() \ No newline at end of file