Repository: frappe/frappe

Issue:
Removed the form_dict object and created a wrapper for cgiFieldRequest class.
It was pointless to send a form_dict dictionary instead of writing a wrapper to cgiField. So here it goes.



Discussion:

Resolving patch:
diff --git a/frappe/patches/v10_0/refactor_social_login_keys.py b/frappe/patches/v10_0/refactor_social_login_keys.py
--- a/frappe/patches/v10_0/refactor_social_login_keys.py
+++ b/frappe/patches/v10_0/refactor_social_login_keys.py
@@ -1,45 +1,10 @@
+
 import frappe
+from frappe.utils import cstr
 
 def execute():
-	frappe.reload_doc("core", "doctype", "user", force=True)
-	frappe.reload_doc("core", "doctype", "user_social_login", force=True)
-	users = frappe.get_all("User", filters=[["username", "not in", ["Guest","Administrator"]]])
-	for u in users:
-		user = frappe.get_doc("User", u.get("name"))
-		save = False
-
-		if user.get("fb_userid") and user.get("fb_username"):
-			user.append("social_logins", {
-				"provider": "facebook",
-				"userid": user.get("fb_userid"),
-				"username": user.get("fb_username")
-			})
-			save = True
-
-		if user.get("frappe_userid"):
-			user.append("social_logins", {
-				"provider": "frappe",
-				"userid": user.get("frappe_userid")
-			})
-			save = True
-
-		if user.get("github_userid") and user.get("github_username"):
-			user.append("social_logins", {
-				"provider": "github",
-				"userid": user.get("github_userid"),
-				"username": user.get("github_username"),
-			})
-			save = True
-
-		if user.get("google_userid"):
-			user.append("social_logins", {
-				"provider": "google",
-				"userid": user.get("google_userid"),
-			})
-			save = True
-
-		if save:
-			user.save()
+	# Update Social Logins in User
+	run_patch()
 
 	# Create Social Login Key(s) from Social Login Keys
 	frappe.reload_doc("integrations", "doctype", "social_login_key", force=True)
@@ -90,3 +55,79 @@ def execute():
 		google_login_key.save()
 
 	frappe.delete_doc("DocType", "Social Login Keys")
+
+def run_patch():
+	frappe.reload_doc("core", "doctype", "user", force=True)
+	frappe.reload_doc("core", "doctype", "user_social_login", force=True)
+
+	users = frappe.get_all("User",
+		fields=["name", "frappe_userid", "fb_userid", "fb_username", "github_userid", "github_username", "google_userid", "modified_by"],
+		filters={"name":("not in", ["Administrator", "Guest"])})
+
+	for user in users:
+		idx = 0
+		if user.frappe_userid:
+			insert_user_social_login(user.name, user.modified_by, 'frappe', idx, userid=user.frappe_userid)
+			idx += 1
+
+		if user.fb_userid or user.fb_username:
+			insert_user_social_login(user.name, user.modified_by, 'facebook', idx, userid=user.fb_userid, username=user.fb_username)
+			idx += 1
+
+		if user.github_userid or user.github_username:
+			insert_user_social_login(user.name, user.modified_by, 'github', idx, userid=user.github_userid, username=user.github_username)
+			idx += 1
+
+		if user.google_userid:
+			insert_user_social_login(user.name, user.modified_by, 'google', idx, userid=user.google_userid)
+			idx += 1
+
+
+def insert_user_social_login(user, modified_by, provider, idx, userid=None, username=None):
+	source_cols = get_standard_cols()
+
+	creation_time = frappe.utils.get_datetime_str(frappe.utils.get_datetime())
+	values = [
+		frappe.generate_hash(length=10),
+		creation_time,
+		creation_time,
+		user,
+		modified_by,
+		user,
+		"User",
+		"social_logins",
+		cstr(idx),
+		provider
+	]
+
+	if userid:
+		source_cols.append("userid")
+		values.append(userid)
+
+	if username:
+		source_cols.append("username")
+		values.append(username)
+
+
+	query = """INSERT INTO `tabUser Social Login` ({source_cols})
+		VALUES ({values})
+	""".format(
+		source_cols = "`" + "`, `".join(source_cols) + "`",
+		values= "'" + "', '".join(values) + "'"
+	)
+
+	frappe.db.sql(query)
+
+def get_provider_field_map():
+	return frappe._dict({
+		"frappe": ["frappe_userid"],
+		"facebook": ["fb_userid", "fb_username"],
+		"github": ["github_userid", "github_username"],
+		"google": ["google_userid"],
+	})
+
+def get_provider_fields(provider):
+		return get_provider_field_map().get(provider)
+
+def get_standard_cols():
+	return ["name", "creation", "modified", "owner", "modified_by", "parent", "parenttype", "parentfield", "idx", "provider"]


Test patch: