From 56b28d0a0ae7cd27412b87bdad880f05be82e656 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 19 Mar 2019 14:08:35 +0530 Subject: [PATCH 001/171] feat: Init energy points --- frappe/boot.py | 2 +- frappe/core/doctype/user/user.js | 43 +- frappe/core/doctype/user/user.json | 110 ++- frappe/core/doctype/user/user.py | 2 +- .../page/energy_point_history/__init__.py | 0 .../energy_point_history.js | 19 + .../energy_point_history.json | 18 + .../energy_point_transactions.html | 10 + frappe/hooks.py | 5 +- frappe/integrations/github_event_handler.py | 81 +++ frappe/modules.txt | 2 +- frappe/public/build.json | 2 +- frappe/public/js/frappe/misc/user.js | 6 +- .../public/js/frappe/ui/toolbar/navbar.html | 20 +- frappe/public/less/avatar.less | 2 +- frappe/public/less/common.less | 6 +- frappe/public/less/flex.less | 4 + frappe/public/less/social.less | 2 +- frappe/public/less/variables.less | 1 + frappe/social/doctype/badge/__init__.py | 0 frappe/social/doctype/badge/badge.js | 8 + frappe/social/doctype/badge/badge.json | 191 ++++++ frappe/social/doctype/badge/badge.py | 10 + .../doctype/energy_point_log/__init__.py | 0 .../energy_point_log/energy_point_log.js | 8 + .../energy_point_log/energy_point_log.json | 226 +++++++ .../energy_point_log/energy_point_log.py | 79 +++ .../doctype/energy_point_rule/__init__.py | 0 .../energy_point_rule/energy_point_rule.js | 8 + .../energy_point_rule/energy_point_rule.json | 226 +++++++ .../energy_point_rule/energy_point_rule.py | 10 + frappe/social/doctype/post/post.json | 624 +++++++++--------- frappe/social/doctype/post/post.py | 2 +- frappe/social/doctype/user_badge/__init__.py | 0 .../social/doctype/user_badge/user_badge.json | 108 +++ .../social/doctype/user_badge/user_badge.py | 10 + frappe/utils/user.py | 2 +- 37 files changed, 1497 insertions(+), 350 deletions(-) create mode 100644 frappe/core/page/energy_point_history/__init__.py create mode 100644 frappe/core/page/energy_point_history/energy_point_history.js create mode 100644 frappe/core/page/energy_point_history/energy_point_history.json create mode 100644 frappe/core/page/energy_point_history/energy_point_transactions.html create mode 100644 frappe/integrations/github_event_handler.py create mode 100644 frappe/social/doctype/badge/__init__.py create mode 100644 frappe/social/doctype/badge/badge.js create mode 100644 frappe/social/doctype/badge/badge.json create mode 100644 frappe/social/doctype/badge/badge.py create mode 100644 frappe/social/doctype/energy_point_log/__init__.py create mode 100644 frappe/social/doctype/energy_point_log/energy_point_log.js create mode 100644 frappe/social/doctype/energy_point_log/energy_point_log.json create mode 100644 frappe/social/doctype/energy_point_log/energy_point_log.py create mode 100644 frappe/social/doctype/energy_point_rule/__init__.py create mode 100644 frappe/social/doctype/energy_point_rule/energy_point_rule.js create mode 100644 frappe/social/doctype/energy_point_rule/energy_point_rule.json create mode 100644 frappe/social/doctype/energy_point_rule/energy_point_rule.py create mode 100644 frappe/social/doctype/user_badge/__init__.py create mode 100644 frappe/social/doctype/user_badge/user_badge.json create mode 100644 frappe/social/doctype/user_badge/user_badge.py diff --git a/frappe/boot.py b/frappe/boot.py index 05117acb7a..1e99b6bb30 100644 --- a/frappe/boot.py +++ b/frappe/boot.py @@ -195,7 +195,7 @@ def load_translations(bootinfo): def get_fullnames(): """map of user fullnames""" ret = frappe.db.sql("""select `name`, full_name as fullname, - user_image as image, gender, email, username, bio, location, interest, banner_image, allowed_in_mentions + user_image as image, gender, email, username, bio, location, interest, banner_image, allowed_in_mentions, energy_points from tabUser where enabled=1 and user_type!='Website User'""", as_dict=1) d = {} diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index d334731015..d9f87a1db1 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -2,7 +2,7 @@ frappe.ui.form.on('User', { before_load: function(frm) { var update_tz_select = function(user_language) { frm.set_df_property("time_zone", "options", [""].concat(frappe.all_timezones)); - } + }; if(!frappe.all_timezones) { frappe.call({ @@ -25,7 +25,7 @@ frappe.ui.form.on('User', { args: { role_profile: frm.doc.role_profile_name }, - callback: function (data) { + callback: function(data) { frm.set_value("roles", []); $.each(data.message || [], function(i, v){ var d = frm.add_child("roles"); @@ -60,6 +60,15 @@ frappe.ui.form.on('User', { frm.reload_doc(); return; } + if (!frm.points) { + frm.points = frm.sidebar.image_section.append(` + + `); + } if(doc.name===frappe.session.user && !doc.__unsaved && frappe.all_timezones && (doc.language || frappe.boot.user.language) @@ -78,7 +87,7 @@ frappe.ui.form.on('User', { "user": doc.name }; frappe.set_route('List', 'User Permission'); - }, __("Permissions")) + }, __("Permissions")); frm.add_custom_button(__('View Permitted Documents'), () => frappe.set_route('query-report', 'Permitted Documents For User', @@ -93,7 +102,7 @@ frappe.ui.form.on('User', { args: { "user": frm.doc.name } - }) + }); }, __("Password")); frm.add_custom_button(__("Reset OTP Secret"), function() { @@ -102,7 +111,7 @@ frappe.ui.form.on('User', { args: { "user": frm.doc.name } - }) + }); }, __("Password")); frm.trigger('enabled'); @@ -130,8 +139,8 @@ frappe.ui.form.on('User', { } if (!found){ frm.add_custom_button(__("Create User Email"), function() { - frm.events.create_user_email(frm) - }) + frm.events.create_user_email(frm); + }); } } @@ -146,7 +155,7 @@ frappe.ui.form.on('User', { }, validate: function(frm) { if(frm.roles_editor) { - frm.roles_editor.set_roles_in_table() + frm.roles_editor.set_roles_in_table(); } }, enabled: function(frm) { @@ -173,18 +182,18 @@ frappe.ui.form.on('User', { "awaiting_password": 1, "enable_incoming": 1 }; - frappe.model.with_doctype("Email Account", function (doc) { + frappe.model.with_doctype("Email Account", function(doc) { var doc = frappe.model.get_new_doc("Email Account"); frappe.route_flags.linked_user = frm.doc.name; frappe.route_flags.delete_user_from_locals = true; frappe.set_route("Form", "Email Account", doc.name); - }) + }); } else { frappe.route_flags.create_user_account = frm.doc.name; frappe.set_route("Form", "Email Account", r.message[0]["name"]); } } - }) + }); }, generate_keys: function(frm){ frappe.call({ @@ -197,9 +206,9 @@ frappe.ui.form.on('User', { frappe.msgprint(__("Save API Secret: ") + r.message.api_secret); } } - }) + }); } -}) +}); function has_access_to_edit_user() { return has_common(frappe.user_roles, get_roles_for_editing_user()); @@ -239,10 +248,14 @@ frappe.ModuleEditor = Class.extend({ var module = $(this).attr('data-module'); if($(this).prop("checked")) { // remove from block_modules - me.frm.doc.block_modules = $.map(me.frm.doc.block_modules || [], function(d) { if(d.module != module){ return d } }); + me.frm.doc.block_modules = $.map(me.frm.doc.block_modules || [], function(d) { + if(d.module != module){ + return d; + } + }); } else { me.frm.add_child("block_modules", {"module": module}); } }); } -}) +}); diff --git a/frappe/core/doctype/user/user.json b/frappe/core/doctype/user/user.json index e96cdf6f36..c565aa562a 100644 --- a/frappe/core/doctype/user/user.json +++ b/frappe/core/doctype/user/user.json @@ -21,6 +21,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "sb0_5", "fieldtype": "Section Break", "hidden": 0, @@ -53,6 +54,7 @@ "collapsible": 0, "columns": 0, "default": "1", + "fetch_if_empty": 0, "fieldname": "enabled", "fieldtype": "Check", "hidden": 0, @@ -87,6 +89,7 @@ "collapsible": 0, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "section_break_3", "fieldtype": "Section Break", "hidden": 0, @@ -118,6 +121,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "email", "fieldtype": "Data", "hidden": 0, @@ -152,6 +156,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "first_name", "fieldtype": "Data", "hidden": 0, @@ -185,6 +190,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "middle_name", "fieldtype": "Data", "hidden": 0, @@ -218,6 +224,7 @@ "bold": 1, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "last_name", "fieldtype": "Data", "hidden": 0, @@ -251,6 +258,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "full_name", "fieldtype": "Data", "hidden": 0, @@ -285,6 +293,7 @@ "columns": 0, "default": "1", "depends_on": "eval:doc.__islocal", + "fetch_if_empty": 0, "fieldname": "send_welcome_email", "fieldtype": "Check", "hidden": 0, @@ -317,6 +326,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "unsubscribed", "fieldtype": "Check", "hidden": 1, @@ -348,6 +358,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break0", "fieldtype": "Column Break", "hidden": 0, @@ -381,6 +392,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "username", "fieldtype": "Data", "hidden": 0, @@ -414,6 +426,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "language", "fieldtype": "Link", "hidden": 0, @@ -447,6 +460,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "time_zone", "fieldtype": "Select", "hidden": 0, @@ -479,6 +493,7 @@ "collapsible": 0, "columns": 0, "description": "Get your globally recognized avatar from Gravatar.com", + "fetch_if_empty": 0, "fieldname": "user_image", "fieldtype": "Attach Image", "hidden": 1, @@ -512,6 +527,7 @@ "columns": 0, "depends_on": "enabled", "description": "", + "fetch_if_empty": 0, "fieldname": "sb1", "fieldtype": "Section Break", "hidden": 0, @@ -543,6 +559,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "role_profile_name", "fieldtype": "Link", "hidden": 0, @@ -576,6 +593,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "roles_html", "fieldtype": "HTML", "hidden": 0, @@ -607,6 +625,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "roles", "fieldtype": "Table", "hidden": 1, @@ -641,6 +660,7 @@ "collapsible": 1, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "short_bio", "fieldtype": "Section Break", "hidden": 0, @@ -672,6 +692,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "gender", "fieldtype": "Link", "hidden": 0, @@ -706,6 +727,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "phone", "fieldtype": "Data", "hidden": 0, @@ -738,6 +760,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "mobile_no", "fieldtype": "Data", "hidden": 0, @@ -770,6 +793,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "birth_date", "fieldtype": "Date", "hidden": 0, @@ -803,6 +827,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "location", "fieldtype": "Data", "hidden": 0, @@ -834,6 +859,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "banner_image", "fieldtype": "Attach Image", "hidden": 0, @@ -866,6 +892,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_22", "fieldtype": "Column Break", "hidden": 0, @@ -896,6 +923,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "interest", "fieldtype": "Small Text", "hidden": 0, @@ -928,6 +956,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "bio", "fieldtype": "Small Text", "hidden": 0, @@ -959,6 +988,40 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, + "fieldname": "energy_points", + "fieldtype": "Int", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Energy Points", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, "fieldname": "mute_sounds", "fieldtype": "Check", "hidden": 0, @@ -992,6 +1055,7 @@ "collapsible": 1, "columns": 0, "depends_on": "eval:doc.enabled && (!doc.__islocal || !cint(doc.send_welcome_email))", + "fetch_if_empty": 0, "fieldname": "change_password", "fieldtype": "Section Break", "hidden": 0, @@ -1023,6 +1087,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "new_password", "fieldtype": "Password", "hidden": 0, @@ -1055,6 +1120,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:!doc.__islocal", + "fetch_if_empty": 0, "fieldname": "send_password_update_notification", "fieldtype": "Check", "hidden": 0, @@ -1088,6 +1154,7 @@ "collapsible": 0, "columns": 0, "default": "0", + "fetch_if_empty": 0, "fieldname": "logout_all_sessions", "fieldtype": "Check", "hidden": 0, @@ -1120,6 +1187,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "reset_password_key", "fieldtype": "Data", "hidden": 1, @@ -1151,6 +1219,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "redirect_url", "fieldtype": "Small Text", "hidden": 1, @@ -1184,6 +1253,7 @@ "collapsible": 1, "columns": 0, "depends_on": "", + "fetch_if_empty": 0, "fieldname": "document_follow_notifications_section", "fieldtype": "Section Break", "hidden": 0, @@ -1216,6 +1286,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "document_follow_notify", "fieldtype": "Check", "hidden": 0, @@ -1251,6 +1322,7 @@ "columns": 0, "default": "Daily", "depends_on": "eval:(doc.document_follow_notify== 1)", + "fetch_if_empty": 0, "fieldname": "document_follow_frequency", "fieldtype": "Select", "hidden": 0, @@ -1285,6 +1357,7 @@ "collapsible": 1, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "email_settings", "fieldtype": "Section Break", "hidden": 0, @@ -1318,6 +1391,7 @@ "collapsible": 0, "columns": 0, "default": "1", + "fetch_if_empty": 0, "fieldname": "thread_notify", "fieldtype": "Check", "hidden": 0, @@ -1350,6 +1424,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "send_me_a_copy", "fieldtype": "Check", "hidden": 0, @@ -1383,6 +1458,7 @@ "collapsible": 0, "columns": 0, "default": "1", + "fetch_if_empty": 0, "fieldname": "allowed_in_mentions", "fieldtype": "Check", "hidden": 0, @@ -1415,6 +1491,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "email_signature", "fieldtype": "Small Text", "hidden": 0, @@ -1446,6 +1523,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "email_inbox", "fieldtype": "Section Break", "hidden": 0, @@ -1479,6 +1557,7 @@ "collapsible": 0, "columns": 0, "description": "", + "fetch_if_empty": 0, "fieldname": "user_emails", "fieldtype": "Table", "hidden": 0, @@ -1513,6 +1592,7 @@ "collapsible": 1, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "background", "fieldtype": "Section Break", "hidden": 0, @@ -1545,6 +1625,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "background_image", "fieldtype": "Attach", "hidden": 0, @@ -1577,6 +1658,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "background_style", "fieldtype": "Select", "hidden": 0, @@ -1612,6 +1694,7 @@ "columns": 0, "default": "", "description": "", + "fetch_if_empty": 0, "fieldname": "sb_allow_modules", "fieldtype": "Section Break", "hidden": 0, @@ -1644,6 +1727,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "modules_html", "fieldtype": "HTML", "hidden": 0, @@ -1676,6 +1760,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "block_modules", "fieldtype": "Table", "hidden": 1, @@ -1710,6 +1795,7 @@ "collapsible": 0, "columns": 0, "default": "", + "fetch_if_empty": 0, "fieldname": "home_settings", "fieldtype": "Code", "hidden": 0, @@ -1743,6 +1829,7 @@ "collapsible": 0, "columns": 0, "description": "These values will be automatically updated in transactions and also will be useful to restrict permissions for this user on transactions containing these values.", + "fetch_if_empty": 0, "fieldname": "sb2", "fieldtype": "Section Break", "hidden": 1, @@ -1778,6 +1865,7 @@ "collapsible": 0, "columns": 0, "description": "Enter default value fields (keys) and values. If you add multiple values for a field, the first one will be picked. These defaults are also used to set \"match\" permission rules. To see list of fields, go to \"Customize Form\".", + "fetch_if_empty": 0, "fieldname": "defaults", "fieldtype": "Table", "hidden": 1, @@ -1811,6 +1899,7 @@ "collapsible": 1, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "sb3", "fieldtype": "Section Break", "hidden": 0, @@ -1844,6 +1933,7 @@ "collapsible": 0, "columns": 0, "default": "1", + "fetch_if_empty": 0, "fieldname": "simultaneous_sessions", "fieldtype": "Int", "hidden": 0, @@ -1878,6 +1968,7 @@ "columns": 0, "default": "System User", "description": "If the user has any role checked, then the user becomes a \"System User\". \"System User\" has access to the desktop", + "fetch_if_empty": 0, "fieldname": "user_type", "fieldtype": "Select", "hidden": 0, @@ -1913,6 +2004,7 @@ "collapsible": 0, "columns": 0, "description": "Allow user to login only after this hour (0-24)", + "fetch_if_empty": 0, "fieldname": "login_after", "fieldtype": "Int", "hidden": 0, @@ -1945,6 +2037,7 @@ "collapsible": 0, "columns": 0, "description": "Allow user to login only before this hour (0-24)", + "fetch_if_empty": 0, "fieldname": "login_before", "fieldtype": "Int", "hidden": 0, @@ -1977,6 +2070,7 @@ "collapsible": 0, "columns": 0, "description": "Restrict user from this IP address only. Multiple IP addresses can be added by separating with commas. Also accepts partial IP addresses like (111.111.111)", + "fetch_if_empty": 0, "fieldname": "restrict_ip", "fieldtype": "Data", "hidden": 0, @@ -2010,6 +2104,7 @@ "columns": 0, "depends_on": "eval:doc.restrict_ip && doc.restrict_ip.length", "description": "If enabled, user can login from any IP Address using Two Factor Auth, this can also be set for all users in System Settings", + "fetch_if_empty": 0, "fieldname": "bypass_restrict_ip_check_if_2fa_enabled", "fieldtype": "Check", "hidden": 0, @@ -2042,6 +2137,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break1", "fieldtype": "Column Break", "hidden": 0, @@ -2075,6 +2171,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "last_login", "fieldtype": "Read Only", "hidden": 0, @@ -2108,6 +2205,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "last_ip", "fieldtype": "Read Only", "hidden": 0, @@ -2141,6 +2239,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "last_active", "fieldtype": "Datetime", "hidden": 0, @@ -2174,6 +2273,7 @@ "collapsible": 0, "columns": 0, "description": "Stores the JSON of last known versions of various installed apps. It is used to show release notes.", + "fetch_if_empty": 0, "fieldname": "last_known_versions", "fieldtype": "Text", "hidden": 1, @@ -2207,6 +2307,7 @@ "collapsible": 1, "columns": 0, "depends_on": "enabled", + "fetch_if_empty": 0, "fieldname": "third_party_authentication", "fieldtype": "Section Break", "hidden": 0, @@ -2238,6 +2339,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "social_logins", "fieldtype": "Table", "hidden": 0, @@ -2271,6 +2373,7 @@ "bold": 0, "collapsible": 1, "columns": 0, + "fetch_if_empty": 0, "fieldname": "api_access", "fieldtype": "Section Break", "hidden": 0, @@ -2304,6 +2407,7 @@ "collapsible": 0, "columns": 0, "description": "API Key cannot be regenerated", + "fetch_if_empty": 0, "fieldname": "api_key", "fieldtype": "Data", "hidden": 0, @@ -2336,6 +2440,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "generate_keys", "fieldtype": "Button", "hidden": 0, @@ -2368,6 +2473,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "column_break_65", "fieldtype": "Column Break", "hidden": 0, @@ -2399,6 +2505,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "fetch_if_empty": 0, "fieldname": "api_secret", "fieldtype": "Password", "hidden": 0, @@ -2437,7 +2544,8 @@ "issingle": 0, "istable": 0, "max_attachments": 5, - "modified": "2019-03-03 11:10:06.162541", + "menu_index": 0, + "modified": "2019-03-19 10:52:33.592908", "modified_by": "Administrator", "module": "Core", "name": "User", diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 17b88ffe13..9d0ea7436d 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -1082,4 +1082,4 @@ def generate_keys(user): user_details.save() return {"api_secret": api_secret} - frappe.throw(frappe._("Not Permitted"), frappe.PermissionError) + frappe.throw(frappe._("Not Permitted"), frappe.PermissionError) \ No newline at end of file diff --git a/frappe/core/page/energy_point_history/__init__.py b/frappe/core/page/energy_point_history/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/core/page/energy_point_history/energy_point_history.js b/frappe/core/page/energy_point_history/energy_point_history.js new file mode 100644 index 0000000000..cb53cef9e4 --- /dev/null +++ b/frappe/core/page/energy_point_history/energy_point_history.js @@ -0,0 +1,19 @@ +frappe.pages['energy-point-history'].on_page_load = function(wrapper) { + const page = frappe.ui.make_app_page({ + parent: wrapper, + title: 'Transaction', + single_column: true, + btn_primary: console.log + + }); + console.log(page); + frappe.db.get_list('Energy Point Log', { + filters: { user: frappe.session.user }, + fields: ['point', 'reason'] + }) + .then((data) => { + console.log(data); + $(frappe.render_template('energy_point_transactions', {data: data})) + .appendTo(page.body); + }) +} \ No newline at end of file diff --git a/frappe/core/page/energy_point_history/energy_point_history.json b/frappe/core/page/energy_point_history/energy_point_history.json new file mode 100644 index 0000000000..350feba8f4 --- /dev/null +++ b/frappe/core/page/energy_point_history/energy_point_history.json @@ -0,0 +1,18 @@ +{ + "content": null, + "creation": "2018-08-06 12:43:28.480030", + "docstatus": 0, + "doctype": "Page", + "idx": 0, + "modified": "2018-08-06 12:43:28.480030", + "modified_by": "Administrator", + "module": "Core", + "name": "energy-point-history", + "owner": "Administrator", + "page_name": "Energy Point History", + "roles": [], + "script": null, + "standard": "Yes", + "style": null, + "system_page": 1 +} \ No newline at end of file diff --git a/frappe/core/page/energy_point_history/energy_point_transactions.html b/frappe/core/page/energy_point_history/energy_point_transactions.html new file mode 100644 index 0000000000..90466ce8b8 --- /dev/null +++ b/frappe/core/page/energy_point_history/energy_point_transactions.html @@ -0,0 +1,10 @@ +
+ +
\ No newline at end of file diff --git a/frappe/hooks.py b/frappe/hooks.py index 6301c51f6a..0ef32601b4 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -130,12 +130,15 @@ doc_events = { ], "on_change": [ "frappe.core.doctype.feedback_trigger.feedback_trigger.trigger_feedback_request", + "frappe.social.doctype.energy_point_log.energy_point_log.update_log" ] }, "Email Group Member": { "validate": "frappe.email.doctype.email_group.email_group.restrict_email_group" }, - + "Energy Point Log": { + "after_insert": "frappe.social.doctype.energy_point_log.energy_point_log.update_user_energy_points" + }, } scheduler_events = { diff --git a/frappe/integrations/github_event_handler.py b/frappe/integrations/github_event_handler.py new file mode 100644 index 0000000000..052ccecdf8 --- /dev/null +++ b/frappe/integrations/github_event_handler.py @@ -0,0 +1,81 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import json +import frappe +import frappe.utils +from frappe.social.doctype.energy_point_log.energy_point_log import ENERGY_POINT_VALUES, create_energy_point_log + + +@frappe.whitelist(allow_guest=True) +def handle_event(*args, **kwargs): + r = frappe.request + event_type = r.headers.get('X-Github-Event') + payload = json.loads(r.get_data()) + if event_type == 'pull_request': + process_pull_request(payload) + if event_type == 'pull_request_review': + process_pull_request(payload) + elif event_type == 'issues': + process_issues(payload) + return True + +def process_pull_request(payload): + action = payload.get('action') + data = payload.get('pull_request') + user_github_id = data['user']['login'] + if not is_local_user(user_github_id): return + if action == 'closed' and data['merged']: + process_merged_pull_request(data) + if action == 'submitted': + process_pull_request_review(data) + +def process_issues(payload): + action = payload.get('action') + data = payload.get('issue') + user_github_id = data['user']['login'] + if not is_local_user(user_github_id): return + if action == 'opened': + create_energy_point_log( + ENERGY_POINT_VALUES['github_issue_open'], + 'Opened Issue: {}'.format(data['title']), + None, + None, + get_user_name(data['user']['login']) + ) + if action == 'closed': + create_energy_point_log( + ENERGY_POINT_VALUES['github_issue_close'], + 'Closed Issue: {}'.format(data['title']), + None, + None, + get_user_name(data['user']['login']) + ) + +def process_merged_pull_request(data): + create_energy_point_log( + ENERGY_POINT_VALUES['github_pull_request_merge'], + 'Pull Request Merged: {}'.format(data['title']), + None, + None, + get_user_name(data['user']['login']) + ) + +def process_pull_request_review(data): + create_energy_point_log( + ENERGY_POINT_VALUES['github_pull_request_review_submit'], + 'Reviewed Pull Request: {}'.format(data['title']), + None, + None, + get_user_name(data['user']['login']) + ) + + +def is_local_user(github_id): + return frappe.db.count('Social Profile', {'github_id': github_id}) + +def get_user_name(github_id): + return frappe.get_value('Social Profile', filters={ + 'github_id': github_id + }, fieldname='name') diff --git a/frappe/modules.txt b/frappe/modules.txt index 3a9ea8f05e..6505174327 100644 --- a/frappe/modules.txt +++ b/frappe/modules.txt @@ -11,4 +11,4 @@ Contacts Data Migration Chat Social -Automation \ No newline at end of file +Automation diff --git a/frappe/public/build.json b/frappe/public/build.json index 73a9fae189..f2285fd4aa 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -264,8 +264,8 @@ "public/less/form_grid.less" ], "js/form.min.js": [ - "public/js/frappe/form/templates/print_layout.html", "public/js/frappe/form/document_follow.js", + "public/js/frappe/form/templates/print_layout.html", "public/js/frappe/form/templates/users_in_sidebar.html", "public/js/frappe/form/templates/set_sharing.html", "public/js/frappe/form/templates/form_sidebar.html", diff --git a/frappe/public/js/frappe/misc/user.js b/frappe/public/js/frappe/misc/user.js index 15e91a82c5..311f208750 100644 --- a/frappe/public/js/frappe/misc/user.js +++ b/frappe/public/js/frappe/misc/user.js @@ -9,7 +9,7 @@ frappe.user_info = function(uid) { fullname: __("Bot"), image: "/assets/frappe/images/ui/bot.png", abbr: "B" - } + }; } if(!(frappe.boot.user_info && frappe.boot.user_info[uid])) { @@ -24,7 +24,7 @@ frappe.user_info = function(uid) { user_info.color = frappe.get_palette(user_info.fullname); return user_info; -} +}; frappe.ui.set_user_background = function(src, selector, style) { if(!selector) selector = "#page-desktop"; @@ -47,7 +47,7 @@ frappe.ui.set_user_background = function(src, selector, style) { background:background, style: style==="Fill Screen" ? "background-size: cover;" : "" })); -} +}; frappe.provide('frappe.user'); diff --git a/frappe/public/js/frappe/ui/toolbar/navbar.html b/frappe/public/js/frappe/ui/toolbar/navbar.html index ea6691a7a3..0f7df81088 100644 --- a/frappe/public/js/frappe/ui/toolbar/navbar.html +++ b/frappe/public/js/frappe/ui/toolbar/navbar.html @@ -20,15 +20,17 @@ {{ avatar }} - + +
- {{ __('All Users') }} + {{ __('Leaderboard') }}
diff --git a/frappe/public/js/frappe/social/pages/UserList.vue b/frappe/public/js/frappe/social/pages/UserList.vue index 5cdf1142e7..fbe6b836a8 100644 --- a/frappe/public/js/frappe/social/pages/UserList.vue +++ b/frappe/public/js/frappe/social/pages/UserList.vue @@ -1,29 +1,45 @@ \ No newline at end of file diff --git a/frappe/public/js/frappe/social/pages/UserList.vue b/frappe/public/js/frappe/social/pages/UserList.vue index 17154542d0..c935d7e830 100644 --- a/frappe/public/js/frappe/social/pages/UserList.vue +++ b/frappe/public/js/frappe/social/pages/UserList.vue @@ -16,40 +16,52 @@
  • -
    - -
    -
    {{ user.fullname }}
    -
    - {{ frappe.ellipsis(user.bio, 100) || 'No Bio'}} -
    + v-for="user in filtered_users" + :key="user.name" + @click="toggle_log(user.name)"> +
    +
    + + + {{ user.fullname }} +
    + {{ frappe.ellipsis(user.bio, 100) || 'No Bio'}} +
    +
    + + {{ user.energy_points }} + + + {{ user.review_points }} + + + {{ user.given_points }} +
    - - {{ user.energy_points }} - - - {{ user.review_points }} - - - {{ user.given_points }} - + +
  • -
  • {{__('No user found')}}
  • +
  • {{__('No user found')}}