From ea2b9cbd1c444604e9ca27ac47378b63babb1045 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 31 Aug 2018 14:37:23 +0530 Subject: [PATCH 01/25] [hub] add user selection in register --- erpnext/hub_node/doctype/hub_user/__init__.py | 0 .../hub_node/doctype/hub_user/hub_user.json | 140 ++++++++++++++++++ erpnext/hub_node/doctype/hub_user/hub_user.py | 10 ++ .../marketplace_settings.json | 49 +++++- .../marketplace_settings.py | 27 +++- .../test_marketplace_settings.js | 23 +++ .../test_marketplace_settings.py | 10 ++ .../js/hub/components/profile_dialog.js | 27 +++- 8 files changed, 272 insertions(+), 14 deletions(-) create mode 100644 erpnext/hub_node/doctype/hub_user/__init__.py create mode 100644 erpnext/hub_node/doctype/hub_user/hub_user.json create mode 100644 erpnext/hub_node/doctype/hub_user/hub_user.py create mode 100644 erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.js create mode 100644 erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.py diff --git a/erpnext/hub_node/doctype/hub_user/__init__.py b/erpnext/hub_node/doctype/hub_user/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.json b/erpnext/hub_node/doctype/hub_user/hub_user.json new file mode 100644 index 0000000000..f72f01d11c --- /dev/null +++ b/erpnext/hub_node/doctype/hub_user/hub_user.json @@ -0,0 +1,140 @@ +{ + "allow_copy": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "autoname": "field:user", + "beta": 0, + "creation": "2018-08-31 12:36:45.627531", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "user", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "User", + "length": 0, + "no_copy": 0, + "options": "User", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "hub_username", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Hub Username", + "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, + "fieldname": "hub_password", + "fieldtype": "Password", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Hub Password", + "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 + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "image_view": 0, + "in_create": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2018-08-31 13:58:46.098710", + "modified_by": "Administrator", + "module": "Hub Node", + "name": "Hub User", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.py b/erpnext/hub_node/doctype/hub_user/hub_user.py new file mode 100644 index 0000000000..de43f4e0c0 --- /dev/null +++ b/erpnext/hub_node/doctype/hub_user/hub_user.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class HubUser(Document): + pass diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json index 5243f38022..2663dc5f82 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json @@ -240,6 +240,38 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "company_logo", + "fieldtype": "Attach Image", + "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": "Company Logo", + "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, @@ -344,8 +376,8 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "logo", - "fieldtype": "Attach Image", + "fieldname": "company_description", + "fieldtype": "Long Text", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -353,7 +385,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Company Logo", + "label": "Company Description", "length": 0, "no_copy": 0, "permlevel": 0, @@ -376,8 +408,8 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "company_description", - "fieldtype": "Text Editor", + "fieldname": "users", + "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -385,9 +417,10 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Description", + "label": "Users", "length": 0, "no_copy": 0, + "options": "Hub User", "permlevel": 0, "precision": "", "print_hide": 0, @@ -479,8 +512,8 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2018-08-31 17:30:37.305704", - "modified_by": "netchamp@rawcoderz.com", + "modified": "2018-08-31 17:56:23.354092", + "modified_by": "cave@aperture.com", "module": "Hub Node", "name": "Marketplace Settings", "name_case": "", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index 9b83898536..909ed998c3 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -44,7 +44,7 @@ class MarketplaceSettings(Document): frappe.throw(json.loads(response.text)) if message.get('email'): - self.create_hub_connector(message) + self.update_session_user_password(message) self.registered = 1 self.save() @@ -63,6 +63,10 @@ class MarketplaceSettings(Document): # self.enabled = 0 # self.save() + def update_session_user_password(self, message): + # TODO: Update child table session user password + pass + def create_hub_connector(self, message): if frappe.db.exists('Data Migration Connector', 'Hub Connector'): hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector') @@ -98,7 +102,24 @@ def reset_hub_settings(last_sync_datetime = ""): @frappe.whitelist() def register_seller(**kwargs): settings = frappe.get_doc('Marketplace Settings') - settings.update(kwargs) - message = settings.register() + user_emails = kwargs.get('users').strip()[:-1].split(', ') + users = [] + + for user_email in user_emails: + users.append({ + "user": user_email + }) + + users.insert(0, { + "user": frappe.session.user, + "hub_username": kwargs.get('username') + }) + + kwargs['users'] = users + settings.update(kwargs) + + settings.save() + + message = settings.register() return message.get('email') diff --git a/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.js b/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.js new file mode 100644 index 0000000000..fba3e098d4 --- /dev/null +++ b/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +// rename this file from _test_[name] to test_[name] to activate +// and remove above this line + +QUnit.test("test: Marketplace Settings", function (assert) { + let done = assert.async(); + + // number of asserts + assert.expect(1); + + frappe.run_serially([ + // insert a new Marketplace Settings + () => frappe.tests.make('Marketplace Settings', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +}); diff --git a/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.py new file mode 100644 index 0000000000..549b9914c3 --- /dev/null +++ b/erpnext/hub_node/doctype/marketplace_settings/test_marketplace_settings.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import frappe +import unittest + +class TestMarketplaceSettings(unittest.TestCase): + pass diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index ae44659ec5..36672b93b8 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -1,5 +1,11 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { const fields = [ + { + // TODO: add hub check for taken + fieldname: 'username', + label: __('Username'), + fieldtype: 'Data' + }, { fieldtype: 'Link', fieldname: 'company', @@ -13,7 +19,8 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { .then(company => { dialog.set_values({ country: company.country, - currency: company.default_currency + currency: company.default_currency, + company_email: company.email }); }); } @@ -21,8 +28,13 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { }, { fieldname: 'company_email', - label: __('Email'), - fieldtype: 'Read Only' + label: __('Company Email'), + fieldtype: 'Data' + }, + { + fieldname: 'users', + label: __('Users'), + fieldtype: 'MultiSelect' }, { fieldname: 'country', @@ -62,6 +74,15 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { } }); + frappe.db.get_list('User') + .then(result => { + const users = result.map(result => result.name) + .filter(user => !['Guest', 'Administrator', frappe.session.user].includes(user)); + dialog.fields_dict.users.set_data(users); + }); + + dialog.set_values(initial_values); + // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); From c726fce4b1fa9931869664266e1547d0e3f551d5 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 31 Aug 2018 20:42:48 +0530 Subject: [PATCH 02/25] [hub] set first user's password in marketplace users --- erpnext/hub_node/doctype/hub_user/hub_user.json | 8 ++++---- .../doctype/marketplace_settings/marketplace_settings.py | 6 +----- erpnext/public/js/hub/components/profile_dialog.js | 9 +++------ erpnext/public/js/hub/marketplace.js | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.json b/erpnext/hub_node/doctype/hub_user/hub_user.json index f72f01d11c..4e4deffe8b 100644 --- a/erpnext/hub_node/doctype/hub_user/hub_user.json +++ b/erpnext/hub_node/doctype/hub_user/hub_user.json @@ -53,7 +53,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "hub_username", + "fieldname": "username", "fieldtype": "Data", "hidden": 0, "ignore_user_permissions": 0, @@ -85,7 +85,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "hub_password", + "fieldname": "password", "fieldtype": "Password", "hidden": 0, "ignore_user_permissions": 0, @@ -121,8 +121,8 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2018-08-31 13:58:46.098710", - "modified_by": "Administrator", + "modified": "2018-08-31 20:39:55.944828", + "modified_by": "cave@aperture.com", "module": "Hub Node", "name": "Hub User", "name_case": "", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index 909ed998c3..6dcbd13fe2 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -44,8 +44,8 @@ class MarketplaceSettings(Document): frappe.throw(json.loads(response.text)) if message.get('email'): - self.update_session_user_password(message) self.registered = 1 + self.users[0].password = message.get('password') self.save() return message or None @@ -63,10 +63,6 @@ class MarketplaceSettings(Document): # self.enabled = 0 # self.save() - def update_session_user_password(self, message): - # TODO: Update child table session user password - pass - def create_hub_connector(self, message): if frappe.db.exists('Data Migration Connector', 'Hub Connector'): hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector') diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 36672b93b8..03e7f48748 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -19,8 +19,7 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { .then(company => { dialog.set_values({ country: company.country, - currency: company.default_currency, - company_email: company.email + currency: company.default_currency }); }); } @@ -28,8 +27,8 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { }, { fieldname: 'company_email', - label: __('Company Email'), - fieldtype: 'Data' + label: __('Email'), + fieldtype: 'Read Only' }, { fieldname: 'users', @@ -81,8 +80,6 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { dialog.fields_dict.users.set_data(users); }); - dialog.set_values(initial_values); - // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index e062c6a31d..7659a3687f 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -101,7 +101,7 @@ erpnext.hub.Marketplace = class Marketplace { register_seller(form_values) { frappe.call({ - method: 'erpnext.hub_node.doctype.hub_settings.hub_settings.register_seller', + method: 'erpnext.hub_node.doctype.marketplace_settings.marketplace_settings.register_seller', args: form_values }).then(() => { this.register_dialog.hide(); From a8065ff72567fa24e81305f8e4c85f46c0cb93a1 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 31 Aug 2018 22:41:26 +0530 Subject: [PATCH 03/25] [hub] move register_seller to api, remove old code --- erpnext/hub_node/api.py | 56 ++++++++++- .../marketplace_settings.json | 34 +------ .../marketplace_settings.py | 96 ++----------------- erpnext/public/js/hub/Sidebar.vue | 2 +- erpnext/public/js/hub/marketplace.js | 2 +- 5 files changed, 66 insertions(+), 124 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index fe419196c5..84042e8c14 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -1,11 +1,63 @@ from __future__ import unicode_literals -import frappe, json -import io, base64, os, requests + +import frappe +import json +import io +import base64 +import os +import requests + +from frappe import _ from frappe.frappeclient import FrappeClient from frappe.desk.form.load import get_attachments from frappe.utils.file_manager import get_file_path from six import string_types +@frappe.whitelist() +def register_seller(**kwargs): + settings = frappe.get_single('Marketplace Settings') + settings.update(kwargs) + settings.users = [] + + validate_registerer() + + message = settings.register() + + if message.get('email'): + settings.registered = 1 + + user_emails = kwargs.get('users').strip()[:-1].split(', ') + settings.users = get_users_object_list( + user_emails, + kwargs.get('username'), + message.get('password') + ) + + settings.save() + + return message + +def validate_registerer(): + if frappe.session.user == 'Administrator': + frappe.throw(_('Please login as another user to register on Marketplace')) + + if 'System Manager' not in frappe.get_roles(): + frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError) + +def get_users_object_list(user_emails, session_user_username, session_user_password): + users = [] + + for user_email in user_emails: + users.append({ 'user': user_email }) + + users.insert(0, { + 'user': frappe.session.user, + 'username': session_user_username, + 'password': session_user_password + }) + + return users + @frappe.whitelist() def call_hub_method(method, params=None): connection = get_hub_connection() diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json index 2663dc5f82..066202a357 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json @@ -208,38 +208,6 @@ "translatable": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "company_email", - "fieldtype": "Data", - "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": "Company Email", - "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, @@ -512,7 +480,7 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2018-08-31 17:56:23.354092", + "modified": "2018-08-31 22:14:59.497780", "modified_by": "cave@aperture.com", "module": "Hub Node", "name": "Marketplace Settings", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index 6dcbd13fe2..f0046d0d2a 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -15,107 +15,29 @@ class MarketplaceSettings(Document): def validate(self): self.site_name = frappe.utils.get_url() + def get_marketplace_url(self): return self.marketplace_url + def register(self): """ Create a User on hub.erpnext.org and return username/password """ - - if frappe.session.user == 'Administrator': - frappe.throw(_('Please login as another user to register on Marketplace')) - - if 'System Manager' not in frappe.get_roles(): - frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError) - self.site_name = frappe.utils.get_url() - data = { - 'profile': self.as_json() - } - post_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register' - - response = requests.post(post_url, data=data, headers = {'accept': 'application/json'}) + register_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register' + data = {'profile': self.as_json(), 'email': frappe.session.user} + headers = {'accept': 'application/json'} + response = requests.post(register_url, data = data, headers = headers) response.raise_for_status() - if response.ok: message = response.json().get('message') else: frappe.throw(json.loads(response.text)) - if message.get('email'): - self.registered = 1 - self.users[0].password = message.get('password') - self.save() - return message or None - # def unregister(self): - # """ Disable the User on hub.erpnext.org""" - # hub_connector = frappe.get_doc( - # 'Data Migration Connector', 'Hub Connector') - - # connection = hub_connector.get_connection() - # response_doc = connection.update('User', frappe._dict({'enabled': 0}), hub_connector.username) - - # if response_doc['enabled'] == 0: - # self.enabled = 0 - # self.save() - - def create_hub_connector(self, message): - if frappe.db.exists('Data Migration Connector', 'Hub Connector'): - hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector') - hub_connector.hostname = self.get_marketplace_url() - hub_connector.username = message['email'] - hub_connector.password = message['password'] - hub_connector.save() - return - - frappe.get_doc({ - 'doctype': 'Data Migration Connector', - 'connector_type': 'Frappe', - 'connector_name': 'Hub Connector', - 'hostname': self.get_marketplace_url(), - 'username': message['email'], - 'password': message['password'] - }).insert() - -def reset_hub_publishing_settings(last_sync_datetime = ""): - doc = frappe.get_doc("Marketplace Settings", "Marketplace Settings") - doc.reset_publishing_settings(last_sync_datetime) - doc.in_callback = 1 - doc.save() - -def reset_hub_settings(last_sync_datetime = ""): - doc = frappe.get_doc("Marketplace Settings", "Marketplace Settings") - doc.reset_publishing_settings(last_sync_datetime) - doc.reset_enable() - doc.in_callback = 1 - doc.save() - frappe.msgprint(_("Successfully unregistered.")) - -@frappe.whitelist() -def register_seller(**kwargs): - settings = frappe.get_doc('Marketplace Settings') - user_emails = kwargs.get('users').strip()[:-1].split(', ') - - users = [] - - for user_email in user_emails: - users.append({ - "user": user_email - }) - - users.insert(0, { - "user": frappe.session.user, - "hub_username": kwargs.get('username') - }) - - kwargs['users'] = users - settings.update(kwargs) - - settings.save() - - message = settings.register() - return message.get('email') + def unregister(self): + """ Disable the User on hub.erpnext.org""" + pass diff --git a/erpnext/public/js/hub/Sidebar.vue b/erpnext/public/js/hub/Sidebar.vue index cff580e5ff..6e0b26ce58 100644 --- a/erpnext/public/js/hub/Sidebar.vue +++ b/erpnext/public/js/hub/Sidebar.vue @@ -19,7 +19,7 @@ export default { data() { return { - hub_registered: hub.settings.registered && frappe.session.user === hub.settings.company_email, + hub_registered: hub.settings.registered, items: [ { label: __('Browse'), diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index 7659a3687f..a4f38c721e 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -101,7 +101,7 @@ erpnext.hub.Marketplace = class Marketplace { register_seller(form_values) { frappe.call({ - method: 'erpnext.hub_node.doctype.marketplace_settings.marketplace_settings.register_seller', + method: 'erpnext.hub_node.api.register_seller', args: form_values }).then(() => { this.register_dialog.hide(); From 747c46424870b3424b1f31d9d7e630df73cbc4e0 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 1 Sep 2018 00:12:17 +0530 Subject: [PATCH 04/25] [fix] save() -> insert() for single doc, use doc.append in child table --- erpnext/hub_node/api.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 84042e8c14..84ec3a16b0 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -20,20 +20,23 @@ def register_seller(**kwargs): settings.users = [] validate_registerer() - message = settings.register() if message.get('email'): settings.registered = 1 - user_emails = kwargs.get('users').strip()[:-1].split(', ') - settings.users = get_users_object_list( - user_emails, - kwargs.get('username'), - message.get('password') - ) + settings.append('users', { + 'user': frappe.session.user, + 'name': frappe.session.user, + 'username': kwargs.get('username'), + 'password': message.get('password') + }) - settings.save() + user_emails = kwargs.get('users').strip()[:-1].split(', ') + for email in user_emails: + settings.append('users', {'user': email, 'name': email}) + + settings.insert() return message @@ -44,20 +47,6 @@ def validate_registerer(): if 'System Manager' not in frappe.get_roles(): frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError) -def get_users_object_list(user_emails, session_user_username, session_user_password): - users = [] - - for user_email in user_emails: - users.append({ 'user': user_email }) - - users.insert(0, { - 'user': frappe.session.user, - 'username': session_user_username, - 'password': session_user_password - }) - - return users - @frappe.whitelist() def call_hub_method(method, params=None): connection = get_hub_connection() From 1801cc8962a5a2e65d8f7c0025fc8f4dba82967a Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 1 Sep 2018 00:39:08 +0530 Subject: [PATCH 05/25] [fix] hub_url -> marketplace_url --- erpnext/hub_node/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 84ec3a16b0..b9a3295d01 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -203,8 +203,8 @@ def get_hub_connection(): # read-only connection if read_only: - hub_url = frappe.db.get_single_value('Marketplace Settings', 'hub_url') - hub_connection = FrappeClient(hub_url) + marketplace_url = frappe.db.get_single_value('Marketplace Settings', 'marketplace_url') + hub_connection = FrappeClient(marketplace_url) return hub_connection def get_field_mappings(): From 810ae018324d0a67f2f503cd8a5478b273a70db3 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 1 Sep 2018 01:14:29 +0530 Subject: [PATCH 06/25] [hub] make client connection for first registered user - remove usage of Hub Connector --- erpnext/hub_node/api.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index b9a3295d01..dc42de76bd 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -13,6 +13,8 @@ from frappe.desk.form.load import get_attachments from frappe.utils.file_manager import get_file_path from six import string_types +current_user = frappe.session.user + @frappe.whitelist() def register_seller(**kwargs): settings = frappe.get_single('Marketplace Settings') @@ -26,8 +28,8 @@ def register_seller(**kwargs): settings.registered = 1 settings.append('users', { - 'user': frappe.session.user, - 'name': frappe.session.user, + 'user': current_user, + 'name': current_user, 'username': kwargs.get('username'), 'password': message.get('password') }) @@ -41,7 +43,7 @@ def register_seller(**kwargs): return message def validate_registerer(): - if frappe.session.user == 'Administrator': + if current_user == 'Administrator': frappe.throw(_('Please login as another user to register on Marketplace')) if 'System Manager' not in frappe.get_roles(): @@ -188,24 +190,19 @@ def load_base64_image_from_items(items): def get_hub_connection(): - read_only = True + settings = frappe.get_single('Marketplace Settings') + marketplace_url = settings.marketplace_url + current_user_records = filter(lambda x: x.user == current_user, settings.users) - if frappe.db.exists('Data Migration Connector', 'Hub Connector'): - hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector') - - # full rights to user who registered as hub_seller - if hub_connector.username == frappe.session.user: - read_only = False - - if not read_only: - hub_connection = hub_connector.get_connection() - return hub_connection.connection - - # read-only connection - if read_only: - marketplace_url = frappe.db.get_single_value('Marketplace Settings', 'marketplace_url') - hub_connection = FrappeClient(marketplace_url) + if current_user_records: + record = current_user_records[0] + password = frappe.get_doc('Hub User', current_user).get_password() + hub_connection = FrappeClient(marketplace_url, record.user, password) return hub_connection + else: + read_only_hub_connection = FrappeClient(marketplace_url) + return read_only_hub_connection + def get_field_mappings(): return [] From 4e1fd0b417e3a874fc17cf9643facd0e75f820fc Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 1 Sep 2018 09:55:43 +0530 Subject: [PATCH 07/25] [hub] register_seller -> register_marketplace - resgister_seller will be for subsequent users - make username and password readonly - check if password present before trying to create connection --- erpnext/hub_node/api.py | 21 ++++++++++++++++--- .../hub_node/doctype/hub_user/hub_user.json | 6 +++--- erpnext/public/js/hub/marketplace.js | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index dc42de76bd..af34844d46 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -15,8 +15,9 @@ from six import string_types current_user = frappe.session.user + @frappe.whitelist() -def register_seller(**kwargs): +def register_marketplace(**kwargs): settings = frappe.get_single('Marketplace Settings') settings.update(kwargs) settings.users = [] @@ -42,6 +43,12 @@ def register_seller(**kwargs): return message + +@frappe.whitelist() +def register_user(username, first_name, company): + pass + + def validate_registerer(): if current_user == 'Administrator': frappe.throw(_('Please login as another user to register on Marketplace')) @@ -49,6 +56,7 @@ def validate_registerer(): if 'System Manager' not in frappe.get_roles(): frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError) + @frappe.whitelist() def call_hub_method(method, params=None): connection = get_hub_connection() @@ -63,6 +71,7 @@ def call_hub_method(method, params=None): response = connection.post_request(params) return response + def map_fields(items): field_mappings = get_field_mappings() table_fields = [d.fieldname for d in frappe.get_meta('Item').get_table_fields()] @@ -87,6 +96,7 @@ def map_fields(items): return items + @frappe.whitelist() def get_valid_items(search_value=''): items = frappe.get_list( @@ -111,6 +121,7 @@ def get_valid_items(search_value=''): return valid_items + @frappe.whitelist() def publish_selected_items(items_to_publish): items_to_publish = json.loads(items_to_publish) @@ -128,7 +139,6 @@ def publish_selected_items(items_to_publish): 'image_list': item.get('image_list') }).insert(ignore_if_duplicate=True) - items = map_fields(items_to_publish) try: @@ -143,6 +153,7 @@ def publish_selected_items(items_to_publish): except Exception as e: frappe.log_error(message=e, title='Hub Sync Error') + def item_sync_preprocess(intended_item_publish_count): response = call_hub_method('pre_items_publish', { 'intended_item_publish_count': intended_item_publish_count @@ -154,6 +165,7 @@ def item_sync_preprocess(intended_item_publish_count): else: frappe.throw('Unable to update remote activity') + def item_sync_postprocess(): response = call_hub_method('post_items_publish', {}) if response: @@ -192,7 +204,10 @@ def load_base64_image_from_items(items): def get_hub_connection(): settings = frappe.get_single('Marketplace Settings') marketplace_url = settings.marketplace_url - current_user_records = filter(lambda x: x.user == current_user, settings.users) + current_user_records = filter( + lambda x: x.user == current_user and x.password, + settings.users + ) if current_user_records: record = current_user_records[0] diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.json b/erpnext/hub_node/doctype/hub_user/hub_user.json index 4e4deffe8b..08a59c6958 100644 --- a/erpnext/hub_node/doctype/hub_user/hub_user.json +++ b/erpnext/hub_node/doctype/hub_user/hub_user.json @@ -69,7 +69,7 @@ "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, - "read_only": 0, + "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, @@ -101,7 +101,7 @@ "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, - "read_only": 0, + "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, @@ -121,7 +121,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2018-08-31 20:39:55.944828", + "modified": "2018-09-01 09:46:54.327880", "modified_by": "cave@aperture.com", "module": "Hub Node", "name": "Hub User", diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index a4f38c721e..bea30bd942 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -92,16 +92,16 @@ erpnext.hub.Marketplace = class Marketplace { __('Become a Seller'), { label: __('Register'), - on_submit: this.register_seller.bind(this) + on_submit: this.register_marketplace.bind(this) } ); this.register_dialog.show(); } - register_seller(form_values) { + register_marketplace(form_values) { frappe.call({ - method: 'erpnext.hub_node.api.register_seller', + method: 'erpnext.hub_node.api.register_marketplace', args: form_values }).then(() => { this.register_dialog.hide(); From 255dd0e03dc98ef746c8237354c2145163272868 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sat, 1 Sep 2018 14:30:46 +0530 Subject: [PATCH 08/25] feat: Add new registration flow --- erpnext/hub_node/api.py | 41 ++++++++------- .../hub_node/doctype/hub_user/hub_user.json | 10 ++-- .../marketplace_settings.json | 36 ++++++++++++- .../marketplace_settings.py | 51 +++++++++++++------ .../js/hub/components/profile_dialog.js | 29 ----------- erpnext/public/js/hub/marketplace.js | 19 ++++--- 6 files changed, 106 insertions(+), 80 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index af34844d46..12a564a342 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -17,31 +17,27 @@ current_user = frappe.session.user @frappe.whitelist() -def register_marketplace(**kwargs): - settings = frappe.get_single('Marketplace Settings') - settings.update(kwargs) - settings.users = [] - +def register_marketplace(company, company_description): validate_registerer() + + settings = frappe.get_single('Marketplace Settings') + country, currency = frappe.db.get_value('Company', company, ['country', 'default_currency']) + + settings.company = company + settings.country = country + settings.currency = currency + settings.company_description = company_description + message = settings.register() - if message.get('email'): + if message.get('hub_seller_name'): settings.registered = 1 + settings.hub_seller_name = message.get('hub_seller_name') + settings.save() - settings.append('users', { - 'user': current_user, - 'name': current_user, - 'username': kwargs.get('username'), - 'password': message.get('password') - }) + settings.add_user(frappe.session.user) - user_emails = kwargs.get('users').strip()[:-1].split(', ') - for email in user_emails: - settings.append('users', {'user': email, 'name': email}) - - settings.insert() - - return message + return { 'ok': 1 } @frappe.whitelist() @@ -53,8 +49,11 @@ def validate_registerer(): if current_user == 'Administrator': frappe.throw(_('Please login as another user to register on Marketplace')) - if 'System Manager' not in frappe.get_roles(): - frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError) + valid_roles = ['System Manager', 'Item Manager'] + + if not frappe.utils.is_subset(valid_roles, frappe.get_roles()): + frappe.throw(_('Only users with {0} role can register on Marketplace').format(', '.join(valid_roles)), + frappe.PermissionError) @frappe.whitelist() diff --git a/erpnext/hub_node/doctype/hub_user/hub_user.json b/erpnext/hub_node/doctype/hub_user/hub_user.json index 08a59c6958..a660022736 100644 --- a/erpnext/hub_node/doctype/hub_user/hub_user.json +++ b/erpnext/hub_node/doctype/hub_user/hub_user.json @@ -3,7 +3,7 @@ "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, - "autoname": "field:user", + "autoname": "", "beta": 0, "creation": "2018-08-31 12:36:45.627531", "custom": 0, @@ -53,7 +53,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "username", + "fieldname": "hub_user_name", "fieldtype": "Data", "hidden": 0, "ignore_user_permissions": 0, @@ -62,7 +62,7 @@ "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, - "label": "Hub Username", + "label": "Hub User", "length": 0, "no_copy": 0, "permlevel": 0, @@ -121,8 +121,8 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2018-09-01 09:46:54.327880", - "modified_by": "cave@aperture.com", + "modified": "2018-09-01 13:56:07.816894", + "modified_by": "netchamp@rawcoderz.com", "module": "Hub Node", "name": "Hub User", "name_case": "", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json index 066202a357..f2d8b05e05 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json @@ -208,6 +208,38 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "hub_seller_name", + "fieldtype": "Data", + "hidden": 1, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Hub Seller Name", + "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, @@ -480,8 +512,8 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2018-08-31 22:14:59.497780", - "modified_by": "cave@aperture.com", + "modified": "2018-09-01 14:15:40.676256", + "modified_by": "suraj@rawcoderz.com", "module": "Hub Node", "name": "Marketplace Settings", "name_case": "", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index f0046d0d2a..cfb9acee2f 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -7,6 +7,7 @@ import frappe, requests, json, time from frappe.model.document import Document from frappe.utils import add_years, now, get_datetime, get_datetime_str from frappe import _ +from frappe.frappeclient import FrappeClient from erpnext.utilities.product import get_price, get_qty_in_stock from six import string_types @@ -15,27 +16,45 @@ class MarketplaceSettings(Document): def validate(self): self.site_name = frappe.utils.get_url() - - def get_marketplace_url(self): - return self.marketplace_url - - def register(self): - """ Create a User on hub.erpnext.org and return username/password """ + """ Create a User on hubmarket.org and return username/password """ self.site_name = frappe.utils.get_url() - register_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register' - data = {'profile': self.as_json(), 'email': frappe.session.user} - headers = {'accept': 'application/json'} + hub_connection = self.get_connection() - response = requests.post(register_url, data = data, headers = headers) - response.raise_for_status() - if response.ok: - message = response.json().get('message') - else: - frappe.throw(json.loads(response.text)) + response = hub_connection.post_request({ + 'cmd': 'hub.hub.api.register', + 'company_details': self.as_json() + }) - return message or None + return response + + def add_user(self, user_email): + if not self.registered: + return + + hub_connection = self.get_connection() + + first_name, last_name = frappe.db.get_value('User', user_email, ['first_name', 'last_name']) + + hub_user = hub_connection.post_request({ + 'cmd': 'hub.hub.api.add_hub_user', + 'user_email': user_email, + 'first_name': first_name, + 'last_name': last_name, + 'hub_seller': self.hub_seller_name + }) + + self.append('users', { + 'user': hub_user.get('user_email'), + 'hub_user_name': hub_user.get('hub_user_name'), + 'password': hub_user.get('password') + }) + + self.insert() + + def get_connection(self): + return FrappeClient(self.marketplace_url) def unregister(self): diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 03e7f48748..240df82ec1 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -1,11 +1,5 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { const fields = [ - { - // TODO: add hub check for taken - fieldname: 'username', - label: __('Username'), - fieldtype: 'Data' - }, { fieldtype: 'Link', fieldname: 'company', @@ -30,21 +24,6 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { label: __('Email'), fieldtype: 'Read Only' }, - { - fieldname: 'users', - label: __('Users'), - fieldtype: 'MultiSelect' - }, - { - fieldname: 'country', - label: __('Country'), - fieldtype: 'Read Only' - }, - { - fieldname: 'currency', - label: __('Currency'), - fieldtype: 'Read Only' - }, { fieldtype: 'Text', label: __('About your Company'), @@ -72,14 +51,6 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { action.on_submit(form_values); } }); - - frappe.db.get_list('User') - .then(result => { - const users = result.map(result => result.name) - .filter(user => !['Guest', 'Administrator', frappe.session.user].includes(user)); - dialog.fields_dict.users.set_data(users); - }); - // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index bea30bd942..2bd55521b2 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -99,15 +99,20 @@ erpnext.hub.Marketplace = class Marketplace { this.register_dialog.show(); } - register_marketplace(form_values) { + register_marketplace({company, company_email, company_description}) { frappe.call({ method: 'erpnext.hub_node.api.register_marketplace', - args: form_values - }).then(() => { - this.register_dialog.hide(); - frappe.set_route('marketplace', 'publish'); - - erpnext.hub.trigger('seller-registered'); + args: { + company, + company_email, + company_description + } + }).then((r) => { + if (r.message && r.message.ok) { + this.register_dialog.hide(); + frappe.set_route('marketplace', 'publish'); + erpnext.hub.trigger('seller-registered'); + } }); } From b2b745fc7a98d21f41159c02b42e6de125fef187 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 1 Sep 2018 17:20:08 +0530 Subject: [PATCH 09/25] [hub] simplify marketplace settings, remove company fields - Company attributes will be fetched/calculated to send to server - removed them as fields in settings - Added description in company, with existing logo field - TODO: for things like logo and description, ask user to set in master --- erpnext/hub_node/api.py | 14 +- .../marketplace_settings.json | 167 +----------------- .../marketplace_settings.py | 29 ++- .../js/hub/components/profile_dialog.js | 27 +-- erpnext/public/js/hub/marketplace.js | 3 +- erpnext/setup/doctype/company/company.json | 139 +++++++++++---- 6 files changed, 136 insertions(+), 243 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 12a564a342..c82890c100 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -17,25 +17,17 @@ current_user = frappe.session.user @frappe.whitelist() -def register_marketplace(company, company_description): +def register_marketplace(company): validate_registerer() - settings = frappe.get_single('Marketplace Settings') - country, currency = frappe.db.get_value('Company', company, ['country', 'default_currency']) - - settings.company = company - settings.country = country - settings.currency = currency - settings.company_description = company_description - - message = settings.register() + message = settings.register_seller(company) if message.get('hub_seller_name'): settings.registered = 1 settings.hub_seller_name = message.get('hub_seller_name') settings.save() - settings.add_user(frappe.session.user) + settings.add_hub_user(frappe.session.user) return { 'ok': 1 } diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json index f2d8b05e05..12837111a7 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.json @@ -95,7 +95,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Marketplace URL", + "label": "Marketplace URL (to hide and update label)", "length": 0, "no_copy": 0, "permlevel": 0, @@ -240,167 +240,6 @@ "translatable": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "company_logo", - "fieldtype": "Attach Image", - "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": "Company Logo", - "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, - "fieldname": "site_name", - "fieldtype": "Data", - "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": "Site Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "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, - "fieldname": "country", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Country", - "length": 0, - "no_copy": 0, - "options": "Country", - "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, - "fieldname": "currency", - "fieldtype": "Currency", - "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": "Currency", - "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, - "fieldname": "company_description", - "fieldtype": "Long Text", - "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": "Company Description", - "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, @@ -512,8 +351,8 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2018-09-01 14:15:40.676256", - "modified_by": "suraj@rawcoderz.com", + "modified": "2018-09-01 17:05:59.600583", + "modified_by": "cave@aperture.com", "module": "Hub Node", "name": "Marketplace Settings", "name_case": "", diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index cfb9acee2f..43543a8a2b 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -13,23 +13,33 @@ from six import string_types class MarketplaceSettings(Document): - def validate(self): - self.site_name = frappe.utils.get_url() + def register_seller(self, company): - def register(self): - """ Create a User on hubmarket.org and return username/password """ - self.site_name = frappe.utils.get_url() + country, currency, company_description = frappe.db.get_value('Company', company, + ['country', 'default_currency', 'company_description']) + + company_details = { + 'company': company, + 'country': country, + # 'city': '', + 'currency': currency, + 'company_description': company_description, + # 'company_logo': company_logo, + + 'site_name': frappe.utils.get_url(), + } hub_connection = self.get_connection() response = hub_connection.post_request({ - 'cmd': 'hub.hub.api.register', - 'company_details': self.as_json() + 'cmd': 'hub.hub.api.add_hub_seller', + 'company_details': json.dumps(company_details) }) return response - def add_user(self, user_email): + + def add_hub_user(self, user_email): if not self.registered: return @@ -53,10 +63,11 @@ class MarketplaceSettings(Document): self.insert() + def get_connection(self): return FrappeClient(self.marketplace_url) def unregister(self): - """ Disable the User on hub.erpnext.org""" + """Disable the User on hubmarket.org""" pass diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 240df82ec1..0f22eaa361 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -4,30 +4,12 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { fieldtype: 'Link', fieldname: 'company', label: __('Company'), - options: 'Company', - onchange: () => { - const value = dialog.get_value('company'); - - if (value) { - frappe.db.get_doc('Company', value) - .then(company => { - dialog.set_values({ - country: company.country, - currency: company.default_currency - }); - }); - } - } + options: 'Company' }, { fieldname: 'company_email', label: __('Email'), fieldtype: 'Read Only' - }, - { - fieldtype: 'Text', - label: __('About your Company'), - fieldname: 'company_description' } ]; @@ -38,7 +20,11 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { primary_action: () => { const form_values = dialog.get_values(); let values_filled = true; - const mandatory_fields = ['company', 'company_email', 'company_description']; + + // TODO: Say "we notice that the company description and logo isn't set. Please set them in master." + // Only then allow to register + + const mandatory_fields = ['company']; mandatory_fields.forEach(field => { const value = form_values[field]; if (!value) { @@ -51,6 +37,7 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { action.on_submit(form_values); } }); + // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index 2bd55521b2..ce72042c00 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -99,13 +99,12 @@ erpnext.hub.Marketplace = class Marketplace { this.register_dialog.show(); } - register_marketplace({company, company_email, company_description}) { + register_marketplace({company, company_email}) { frappe.call({ method: 'erpnext.hub_node.api.register_marketplace', args: { company, company_email, - company_description } }).then((r) => { if (r.message && r.message.ok) { diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index a4c81c5cea..96d11163f5 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -305,6 +305,102 @@ "translatable": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "sb_about", + "fieldtype": "Section Break", + "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": "About the Company", + "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, + "fieldname": "company_logo", + "fieldtype": "Attach Image", + "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": "Company Logo", + "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, + "fieldname": "company_description", + "fieldtype": "Text Editor", + "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": "Company Description", + "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, @@ -741,7 +837,7 @@ "label": "Create Chart Of Accounts Based On", "length": 0, "no_copy": 0, - "options": "\nStandard Template\nExisting Company", + "options": "\nStandard Template\nExisting Company\n\n\n", "permlevel": 0, "precision": "", "print_hide": 0, @@ -775,7 +871,7 @@ "label": "Chart Of Accounts Template", "length": 0, "no_copy": 1, - "options": "", + "options": "\n\n\n", "permlevel": 0, "precision": "", "print_hide": 0, @@ -2630,38 +2726,6 @@ "translatable": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "company_logo", - "fieldtype": "Attach Image", - "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": "Company Logo", - "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, @@ -2772,8 +2836,8 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2018-08-28 15:47:50.757131", - "modified_by": "Administrator", + "modified": "2018-09-01 16:03:30.716918", + "modified_by": "cave@aperture.com", "module": "Setup", "name": "Company", "owner": "Administrator", @@ -2918,5 +2982,6 @@ "show_name_in_global_search": 1, "sort_order": "ASC", "track_changes": 1, - "track_seen": 0 + "track_seen": 0, + "track_views": 0 } \ No newline at end of file From 68129df74c38bbdb93c4959e5bb3fbf6347e1e65 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sun, 2 Sep 2018 18:29:00 +0530 Subject: [PATCH 10/25] feat: Add add_user dialog and methods - wip --- erpnext/hub_node/api.py | 23 +++++----- .../marketplace_settings.py | 15 +++++++ erpnext/public/js/hub/marketplace.js | 44 +++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index c82890c100..e69a9631f2 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -33,8 +33,15 @@ def register_marketplace(company): @frappe.whitelist() -def register_user(username, first_name, company): - pass +def register_users(user_list): + user_list = json.loads(user_list) + + settings = frappe.get_single('Marketplace Settings') + + for user in user_list: + settings.add_hub_user(user) + + return user_list def validate_registerer(): @@ -195,15 +202,11 @@ def load_base64_image_from_items(items): def get_hub_connection(): settings = frappe.get_single('Marketplace Settings') marketplace_url = settings.marketplace_url - current_user_records = filter( - lambda x: x.user == current_user and x.password, - settings.users - ) + hub_user = settings.get_hub_user(frappe.session.user) - if current_user_records: - record = current_user_records[0] - password = frappe.get_doc('Hub User', current_user).get_password() - hub_connection = FrappeClient(marketplace_url, record.user, password) + if hub_user: + password = hub_user.get_password() + hub_connection = FrappeClient(marketplace_url, hub_user.user, password) return hub_connection else: read_only_hub_connection = FrappeClient(marketplace_url) diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index 43543a8a2b..a9dfe8a557 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -40,6 +40,10 @@ class MarketplaceSettings(Document): def add_hub_user(self, user_email): + '''Create a Hub User and User record on hub server + and if successfull append it to Hub User table + ''' + if not self.registered: return @@ -63,6 +67,17 @@ class MarketplaceSettings(Document): self.insert() + def get_hub_user(self, user): + '''Return the Hub User doc from the `users` table if password is set''' + + filtered_users = filter( + lambda x: x.user == user and x.password, + self.users + ) + + if filtered_users: + return filtered_users[0] + def get_connection(self): return FrappeClient(self.marketplace_url) diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index ce72042c00..bdcb353e90 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -31,6 +31,8 @@ erpnext.hub.Marketplace = class Marketplace { this.refresh(); if (!is_registered && !is_registered_seller && frappe.user_roles.includes('System Manager')) { this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this)) + } else { + this.page.set_secondary_action('Add Users', this.show_add_user_dialog.bind(this)); } }); } @@ -115,4 +117,46 @@ erpnext.hub.Marketplace = class Marketplace { }); } + show_add_user_dialog() { + const user_list = Object.keys(frappe.boot.user_info) + .filter(user => !['Administrator', 'Guest', frappe.session.user].includes(user)); + const d = new frappe.ui.Dialog({ + title: __('Add Users to Marketplace'), + fields: [ + { + label: __('Users'), + fieldname: 'users', + fieldtype: 'MultiSelect', + reqd: 1, + get_data() { + return user_list; + } + } + ], + primary_action({ users }) { + const selected_users = users.split(',').map(d => d.trim()).filter(Boolean); + + if (!selected_users.every(user => user_list.includes(user))) { + d.set_df_property('users', 'description', __('Some emails are invalid')); + return; + } else { + d.set_df_property('users', 'description', ''); + } + + frappe.call('erpnext.hub_node.api.register_users', { + user_list: selected_users + }) + .then(r => { + d.hide(); + + if (r.message && r.message.length) { + frappe.show_alert('Added {0} users', [r.message.length]); + } + }); + } + }); + + d.show(); + } + } From a094c0f3f162f863d6c6aca284d790a215db0fcc Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sun, 2 Sep 2018 19:45:56 +0530 Subject: [PATCH 11/25] [fix] encrypted password in Hub User child record by frappe/frappe#6048 - use save() instead of insert() --- .../doctype/marketplace_settings/marketplace_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index a9dfe8a557..482efadaed 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -65,7 +65,7 @@ class MarketplaceSettings(Document): 'password': hub_user.get('password') }) - self.insert() + self.save() def get_hub_user(self, user): '''Return the Hub User doc from the `users` table if password is set''' From 5511e06f06255957195217352c5241e10a2ae16f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 02:25:41 +0530 Subject: [PATCH 12/25] [hub][api] Update save and view api to be user specific --- .../public/js/hub/components/detail_view.js | 138 ------------------ erpnext/public/js/hub/components/item_card.js | 80 ---------- erpnext/public/js/hub/pages/Item.vue | 4 +- erpnext/public/js/hub/pages/Profile.vue | 2 +- erpnext/public/js/hub/pages/SavedItems.vue | 6 +- 5 files changed, 6 insertions(+), 224 deletions(-) delete mode 100644 erpnext/public/js/hub/components/detail_view.js delete mode 100644 erpnext/public/js/hub/components/item_card.js diff --git a/erpnext/public/js/hub/components/detail_view.js b/erpnext/public/js/hub/components/detail_view.js deleted file mode 100644 index d80720c1da..0000000000 --- a/erpnext/public/js/hub/components/detail_view.js +++ /dev/null @@ -1,138 +0,0 @@ -import { get_rating_html } from './reviews'; - -function get_detail_view_html(item, allow_edit) { - const title = item.item_name || item.name; - const seller = item.company; - - const who = __('Posted By {0}', [seller]); - const when = comment_when(item.creation); - - const city = item.city ? item.city + ', ' : ''; - const country = item.country ? item.country : ''; - const where = `${city}${country}`; - - const dot_spacer = ''; - - const description = item.description || ''; - - let stats = __('No views yet'); - if(item.view_count) { - const views_message = __(`${item.view_count} Views`); - - const rating_html = get_rating_html(item.average_rating); - const rating_count = item.no_of_ratings > 0 ? `${item.no_of_ratings} reviews` : __('No reviews yet'); - - stats = `${views_message}${dot_spacer}${rating_html} (${rating_count})`; - } - - let favourite_button = '' - if (hub.settings.registered) { - favourite_button = !item.favourited - ? `` - : ``; - } - - const contact_seller_button = item.hub_seller !== hub.settings.company_email - ? `` - : ''; - - let menu_items = ''; - - if(allow_edit) { - menu_items = ` -
  • ${__('Edit Details')}
  • -
  • ${__('Unpublish')}
  • `; - } else { - menu_items = ` -
  • ${__('Report this item')}
  • - `; - } - - const html = ` -
    -
    -
    - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -

    ${title}

    -
    -

    ${where}${dot_spacer}${when}

    -

    ${stats}

    -
    -
    - -
    - ${favourite_button} - ${contact_seller_button} -
    -
    -
    - -
    -
    -
    -
    - Item Description -
    -

    - ${description ? description : __('No details')} -

    -
    -
    - -
    - Seller Information -
    -
    - -
    -
    - -
    -
    - -
    - -
    -
    - `; - - return html; -} - -export { - get_detail_view_html, - get_profile_html -} diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js deleted file mode 100644 index 41ab33aaf9..0000000000 --- a/erpnext/public/js/hub/components/item_card.js +++ /dev/null @@ -1,80 +0,0 @@ -function get_buying_item_message_card_html(item) { - const item_name = item.item_name || item.name; - const title = strip_html(item_name); - - const message = item.recent_message - const sender = message.sender === frappe.session.user ? 'You' : message.sender - const content = strip_html(message.content) - - // route - item.route = `marketplace/buying/${item.name}` - - const item_html = ` -
    -
    -
    - -
    -
    ${item_name}
    -
    - ${sender}: - ${content} -
    -
    -
    -
    - ${comment_when(message.creation, true)} -
    -
    -
    - `; - - return item_html; -} - -function get_selling_item_message_card_html(item) { - const item_name = item.item_name || item.name; - const title = strip_html(item_name); - - // route - if (!item.route) { - item.route = `marketplace/item/${item.name}` - } - - let received_messages = ''; - item.received_messages.forEach(message => { - const sender = message.sender === frappe.session.user ? 'You' : message.sender - const content = strip_html(message.content) - - received_messages += ` -
    - ${comment_when(message.creation, true)} -
    - ${sender}: - ${content} -
    -
    - ` - }); - - const item_html = ` -
    -
    - -
    ${item_name}
    -
    - ${received_messages} -
    -
    -
    - `; - - return item_html; -} - -export { - get_item_card_html, - get_local_item_card_html, - get_buying_item_message_card_html, - get_selling_item_message_card_html -} diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue index 3305b1da4c..5d07bcd620 100644 --- a/erpnext/public/js/hub/pages/Item.vue +++ b/erpnext/public/js/hub/pages/Item.vue @@ -190,9 +190,9 @@ export default { }, add_to_saved_items() { - hub.call('add_item_to_seller_saved_items', { + hub.call('add_item_to_user_saved_items', { hub_item_name: this.hub_item_name, - hub_seller: hub.settings.company_email + hub_user: frappe.session.user }) .then(() => { const saved_items_link = `${__('Saved')}` diff --git a/erpnext/public/js/hub/pages/Profile.vue b/erpnext/public/js/hub/pages/Profile.vue index a0bc6cba78..91ed946761 100644 --- a/erpnext/public/js/hub/pages/Profile.vue +++ b/erpnext/public/js/hub/pages/Profile.vue @@ -52,7 +52,7 @@ export default { get_profile() { hub.call( 'get_hub_seller_profile', - { hub_seller: hub.settings.company_email } + { hub_seller: hub.settings.hub_seller_name } ).then(profile => { this.init = false; diff --git a/erpnext/public/js/hub/pages/SavedItems.vue b/erpnext/public/js/hub/pages/SavedItems.vue index e5d21cdd3c..c29675acd3 100644 --- a/erpnext/public/js/hub/pages/SavedItems.vue +++ b/erpnext/public/js/hub/pages/SavedItems.vue @@ -38,7 +38,7 @@ export default { methods: { get_items() { hub.call( - 'get_saved_items_of_seller', {}, + 'get_saved_items_of_user', {}, 'action:item_save' ) .then((items) => { @@ -83,9 +83,9 @@ export default { remove_item_from_saved_items(hub_item_name) { erpnext.hub.trigger('action:item_save'); - hub.call('remove_item_from_seller_saved_items', { + hub.call('remove_item_from_user_saved_items', { hub_item_name, - hub_seller: hub.settings.company_email + hub_user: frappe.session.user }) .then(() => { this.get_items(); From 85563ddfd3f797a449fcb26b527362d636f09841 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 02:44:27 +0530 Subject: [PATCH 13/25] [hub] update publish hub api --- erpnext/hub_node/api.py | 4 ++-- erpnext/public/js/hub/pages/PublishedItems.vue | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index e69a9631f2..ff1d267b72 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -74,7 +74,7 @@ def map_fields(items): field_mappings = get_field_mappings() table_fields = [d.fieldname for d in frappe.get_meta('Item').get_table_fields()] - hub_seller = frappe.db.get_value('Marketplace Settings' , 'Marketplace Settings', 'company_email') + hub_seller_name = frappe.db.get_value('Marketplace Settings' , 'Marketplace Settings', 'hub_seller_name') for item in items: for fieldname in table_fields: @@ -89,7 +89,7 @@ def map_fields(items): item[remote_fieldname] = value item['doctype'] = 'Hub Item' - item['hub_seller'] = hub_seller + item['hub_seller'] = hub_seller_name item.pop('attachments', None) return items diff --git a/erpnext/public/js/hub/pages/PublishedItems.vue b/erpnext/public/js/hub/pages/PublishedItems.vue index 114259b93c..52df2850a9 100644 --- a/erpnext/public/js/hub/pages/PublishedItems.vue +++ b/erpnext/public/js/hub/pages/PublishedItems.vue @@ -63,7 +63,7 @@ export default { get_items() { hub.call('get_items', { filters: { - hub_seller: hub.settings.company_email + hub_seller: hub.settings.hub_seller_name } }) .then((items) => { From 47cc30da853fa04a4b091421e7ec4ad67ec473c9 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 13:11:23 +0530 Subject: [PATCH 14/25] [hub] ask company description in dialog --- erpnext/hub_node/api.py | 4 +-- .../marketplace_settings.py | 4 +-- .../js/hub/components/profile_dialog.js | 36 +++++++++++++++---- erpnext/public/js/hub/marketplace.js | 4 +-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index ff1d267b72..2a928d44a2 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -17,10 +17,10 @@ current_user = frappe.session.user @frappe.whitelist() -def register_marketplace(company): +def register_marketplace(company, company_description): validate_registerer() settings = frappe.get_single('Marketplace Settings') - message = settings.register_seller(company) + message = settings.register_seller(company, company_description) if message.get('hub_seller_name'): settings.registered = 1 diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index 482efadaed..ebe8b702ab 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -13,9 +13,9 @@ from six import string_types class MarketplaceSettings(Document): - def register_seller(self, company): + def register_seller(self, company, company_description): - country, currency, company_description = frappe.db.get_value('Company', company, + country, currency, description = frappe.db.get_value('Company', company, ['country', 'default_currency', 'company_description']) company_details = { diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 0f22eaa361..ea827ff3bf 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -1,15 +1,39 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { const fields = [ - { - fieldtype: 'Link', - fieldname: 'company', - label: __('Company'), - options: 'Company' - }, { fieldname: 'company_email', label: __('Email'), fieldtype: 'Read Only' + }, + { + fieldtype: 'Link', + fieldname: 'company', + label: __('Company'), + options: 'Company', + onchange: () => { + const value = dialog.get_value('company'); + if (value) { + frappe.db.get_doc('Company', value) + .then(company => { + console.log(company.company_logo); + dialog.set_values({ + company_logo: company.company_logo, + company_description: company.company_description + }); + }); + } + } + }, + // { + // fieldname: 'company_logo', + // label: __('Logo'), + // fieldtype: 'Attach Image', + // read_only: true + // }, + { + fieldname: 'company_description', + label: __('About Your Company'), + fieldtype: 'Long Text' } ]; diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index bdcb353e90..9df6303f6b 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -101,12 +101,12 @@ erpnext.hub.Marketplace = class Marketplace { this.register_dialog.show(); } - register_marketplace({company, company_email}) { + register_marketplace({company, company_description}) { frappe.call({ method: 'erpnext.hub_node.api.register_marketplace', args: { company, - company_email, + company_description } }).then((r) => { if (r.message && r.message.ok) { From 18e3c61109b4ae0b3d951ca3ed44c7197bce32dd Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 15:22:13 +0530 Subject: [PATCH 15/25] [marketplace] Disallow unregistered routes if not registered --- erpnext/public/js/hub/PageContainer.vue | 41 +++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/erpnext/public/js/hub/PageContainer.vue b/erpnext/public/js/hub/PageContainer.vue index cec4c8d746..981c44e8f5 100644 --- a/erpnext/public/js/hub/PageContainer.vue +++ b/erpnext/public/js/hub/PageContainer.vue @@ -20,23 +20,29 @@ import Messages from './pages/Messages.vue'; import Profile from './pages/Profile.vue'; import NotFound from './pages/NotFound.vue'; -const route_map = { - 'marketplace/home': Home, - 'marketplace/search/:keyword': Search, - 'marketplace/category/:category': Category, - 'marketplace/item/:item': Item, - 'marketplace/seller/:seller': Seller, - 'marketplace/not-found': NotFound, - - // Registered seller routes - 'marketplace/profile': Profile, - 'marketplace/saved-items': SavedItems, - 'marketplace/publish': Publish, - 'marketplace/published-items': PublishedItems, - 'marketplace/buying': Buying, - 'marketplace/buying/:item': Messages, - 'marketplace/selling': Selling, - 'marketplace/selling/:buyer/:item': Messages +function get_route_map() { + const read_only_routes = { + 'marketplace/home': Home, + 'marketplace/search/:keyword': Search, + 'marketplace/category/:category': Category, + 'marketplace/item/:item': Item, + 'marketplace/seller/:seller': Seller, + 'marketplace/not-found': NotFound, + } + const registered_routes = { + 'marketplace/profile': Profile, + 'marketplace/saved-items': SavedItems, + 'marketplace/publish': Publish, + 'marketplace/published-items': PublishedItems, + 'marketplace/buying': Buying, + 'marketplace/buying/:item': Messages, + 'marketplace/selling': Selling, + 'marketplace/selling/:buyer/:item': Messages + } + const hub_registered = hub.settings.registered; + return hub_registered + ? Object.assign({}, read_only_routes, registered_routes) + : read_only_routes; } export default { @@ -56,6 +62,7 @@ export default { this.current_page = this.get_current_page(); }, get_current_page() { + const route_map = get_route_map(); const curr_route = frappe.get_route_str(); let route = Object.keys(route_map).filter(route => route == curr_route)[0]; if (!route) { From ad0be6aaa2fe9b29530d6b535608696361fdc83f Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 3 Sep 2018 15:42:00 +0530 Subject: [PATCH 16/25] fix: Messages - update messages according to new doctype - sync logo in seller registration - hub.is_seller_registered() and hub.is_user_registered() api - Add Users dialog --- erpnext/hub_node/api.py | 9 ++ .../marketplace_settings.py | 10 +- erpnext/public/js/hub/Sidebar.vue | 2 +- .../public/js/hub/components/ReviewArea.vue | 2 - .../js/hub/components/profile_dialog.js | 14 +-- erpnext/public/js/hub/marketplace.js | 109 +++++++++++------- erpnext/public/js/hub/pages/Buying.vue | 7 +- erpnext/public/js/hub/pages/Item.vue | 6 +- erpnext/public/js/hub/pages/Messages.vue | 7 +- .../public/js/hub/pages/PublishedItems.vue | 19 +-- erpnext/public/js/hub/vue-plugins.js | 2 +- 11 files changed, 105 insertions(+), 82 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 2a928d44a2..df3e7efb8f 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -19,6 +19,7 @@ current_user = frappe.session.user @frappe.whitelist() def register_marketplace(company, company_description): validate_registerer() + settings = frappe.get_single('Marketplace Settings') message = settings.register_seller(company, company_description) @@ -151,6 +152,14 @@ def publish_selected_items(items_to_publish): except Exception as e: frappe.log_error(message=e, title='Hub Sync Error') +@frappe.whitelist() +def get_unregistered_users(): + settings = frappe.get_single('Marketplace Settings') + registered_users = [user.user for user in settings.users] + ['Administrator', 'Guest'] + all_users = [user.name for user in frappe.db.get_all('User', filters={'enabled': 1})] + unregistered_users = [user for user in all_users if user not in registered_users] + return unregistered_users + def item_sync_preprocess(intended_item_publish_count): response = call_hub_method('pre_items_publish', { diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py index ebe8b702ab..5ea3011a86 100644 --- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py +++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py @@ -15,18 +15,16 @@ class MarketplaceSettings(Document): def register_seller(self, company, company_description): - country, currency, description = frappe.db.get_value('Company', company, - ['country', 'default_currency', 'company_description']) + country, currency, company_logo = frappe.db.get_value('Company', company, + ['country', 'default_currency', 'company_logo']) company_details = { 'company': company, 'country': country, - # 'city': '', 'currency': currency, 'company_description': company_description, - # 'company_logo': company_logo, - - 'site_name': frappe.utils.get_url(), + 'company_logo': company_logo, + 'site_name': frappe.utils.get_url() } hub_connection = self.get_connection() diff --git a/erpnext/public/js/hub/Sidebar.vue b/erpnext/public/js/hub/Sidebar.vue index 6e0b26ce58..164e78d30d 100644 --- a/erpnext/public/js/hub/Sidebar.vue +++ b/erpnext/public/js/hub/Sidebar.vue @@ -19,7 +19,7 @@ export default { data() { return { - hub_registered: hub.settings.registered, + hub_registered: hub.is_user_registered(), items: [ { label: __('Browse'), diff --git a/erpnext/public/js/hub/components/ReviewArea.vue b/erpnext/public/js/hub/components/ReviewArea.vue index 070d0a69cb..159fdd112f 100644 --- a/erpnext/public/js/hub/components/ReviewArea.vue +++ b/erpnext/public/js/hub/components/ReviewArea.vue @@ -56,8 +56,6 @@ export default { }, on_submit_review(values) { - values.user = hub.settings.company_email; - this.review_area.reset(); hub.call('add_item_review', { diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index ea827ff3bf..636bf1436a 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -24,16 +24,10 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { } } }, - // { - // fieldname: 'company_logo', - // label: __('Logo'), - // fieldtype: 'Attach Image', - // read_only: true - // }, { + label: __('About your company'), fieldname: 'company_description', - label: __('About Your Company'), - fieldtype: 'Long Text' + fieldtype: 'Text' } ]; @@ -48,7 +42,7 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { // TODO: Say "we notice that the company description and logo isn't set. Please set them in master." // Only then allow to register - const mandatory_fields = ['company']; + const mandatory_fields = ['company', 'company_description']; mandatory_fields.forEach(field => { const value = form_values[field]; if (!value) { @@ -65,7 +59,7 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); - dialog.set_value('company_email', frappe.session.user); + dialog.set_value('email', frappe.session.user); return dialog; } diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index 9df6303f6b..bacca47545 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -22,17 +22,20 @@ erpnext.hub.Marketplace = class Marketplace { frappe.model.with_doc('Marketplace Settings').then(doc => { hub.settings = doc; - const is_registered = hub.settings.registered; - const is_registered_seller = hub.settings.company_email === frappe.session.user; + this.setup_header(); this.make_sidebar(); this.make_body(); this.setup_events(); this.refresh(); - if (!is_registered && !is_registered_seller && frappe.user_roles.includes('System Manager')) { - this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this)) - } else { - this.page.set_secondary_action('Add Users', this.show_add_user_dialog.bind(this)); + + if (is_subset(['System Manager', 'Item Manager'], frappe.user_roles)) { + // show buttons only to System Manager + if (!hub.is_seller_registered()) { + this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this)) + } else { + this.page.set_secondary_action('Add Users', this.show_add_user_dialog.bind(this)); + } } }); } @@ -118,45 +121,73 @@ erpnext.hub.Marketplace = class Marketplace { } show_add_user_dialog() { - const user_list = Object.keys(frappe.boot.user_info) - .filter(user => !['Administrator', 'Guest', frappe.session.user].includes(user)); - const d = new frappe.ui.Dialog({ - title: __('Add Users to Marketplace'), - fields: [ - { - label: __('Users'), - fieldname: 'users', - fieldtype: 'MultiSelect', - reqd: 1, - get_data() { - return user_list; - } - } - ], - primary_action({ users }) { - const selected_users = users.split(',').map(d => d.trim()).filter(Boolean); + this.get_unregistered_users() + .then(r => { + const user_list = r.message; - if (!selected_users.every(user => user_list.includes(user))) { - d.set_df_property('users', 'description', __('Some emails are invalid')); - return; - } else { - d.set_df_property('users', 'description', ''); - } + const d = new frappe.ui.Dialog({ + title: __('Add Users to Marketplace'), + fields: [ + { + label: __('Users'), + fieldname: 'users', + fieldtype: 'MultiSelect', + reqd: 1, + get_data() { + return user_list; + } + } + ], + primary_action({ users }) { + const selected_users = users.split(',').map(d => d.trim()).filter(Boolean); - frappe.call('erpnext.hub_node.api.register_users', { - user_list: selected_users - }) - .then(r => { - d.hide(); + if (!selected_users.every(user => user_list.includes(user))) { + d.set_df_property('users', 'description', __('Some emails are invalid')); + return; + } else { + d.set_df_property('users', 'description', ''); + } - if (r.message && r.message.length) { - frappe.show_alert('Added {0} users', [r.message.length]); + frappe.call('erpnext.hub_node.api.register_users', { + user_list: selected_users + }) + .then(r => { + d.hide(); + + if (r.message && r.message.length) { + frappe.show_alert(__('Added {0} users', [r.message.length])); + } + }); } }); - } - }); - d.show(); + d.show(); + }); + } + + get_unregistered_users() { + return frappe.call('erpnext.hub_node.api.get_unregistered_users') } } + +Object.assign(hub, { + is_seller_registered() { + return hub.settings.registered; + }, + + is_user_registered() { + return this.is_seller_registered() && hub.settings.users + .filter(hub_user => hub_user.user === frappe.session.user) + .length === 1; + }, +}); + +/** + * Returns true if list_a is subset of list_b + * @param {Array} list_a + * @param {Array} list_b + */ +function is_subset(list_a, list_b) { + return list_a.every(item => list_b.includes(item)); +} diff --git a/erpnext/public/js/hub/pages/Buying.vue b/erpnext/public/js/hub/pages/Buying.vue index ddb4b11db9..ebf593aca4 100644 --- a/erpnext/public/js/hub/pages/Buying.vue +++ b/erpnext/public/js/hub/pages/Buying.vue @@ -13,8 +13,8 @@ v-route="'marketplace/buying/' + item.name" >
    - {{item.recent_message.sender}}: - {{item.recent_message.content | striphtml}} + {{ get_sender(item.recent_message) }}: + {{ item.recent_message.message | striphtml }}
    @@ -47,6 +47,9 @@ export default { methods: { get_items_for_messages() { return hub.call('get_buying_items_for_messages', {}, 'action:send_message'); + }, + get_sender(message) { + return message.sender === frappe.session.user ? __('You') : (message.sender_name || message.sender); } } } diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue index 5d07bcd620..272be58133 100644 --- a/erpnext/public/js/hub/pages/Item.vue +++ b/erpnext/public/js/hub/pages/Item.vue @@ -81,7 +81,7 @@ export default { is_own_item() { let is_own_item = false; if(this.item) { - if(this.item.hub_seller === hub.setting.company_email) { + if(this.item.hub_seller === hub.settings.hub_seller_name) { is_own_item = true; } } @@ -224,13 +224,11 @@ export default { if (!message) return; hub.call('send_message', { - from_seller: hub.settings.company_email, - to_seller: this.item.hub_seller, hub_item: this.item.name, message }) .then(() => { - d.hide(); + this.contact_seller_dialog.hide(); frappe.set_route('marketplace', 'buying', this.item.name); erpnext.hub.trigger('action:send_message') }); diff --git a/erpnext/public/js/hub/pages/Messages.vue b/erpnext/public/js/hub/pages/Messages.vue index 1930bcb22a..73506e9926 100644 --- a/erpnext/public/js/hub/pages/Messages.vue +++ b/erpnext/public/js/hub/pages/Messages.vue @@ -16,7 +16,7 @@
    -
    +
    @@ -64,13 +64,12 @@ export default { methods: { send_message(message) { this.messages.push({ - sender: hub.settings.company_email, - content: message, + sender: frappe.session.user, + message: message, creation: Date.now(), name: frappe.utils.get_random(6) }); hub.call('send_message', { - from_seller: hub.settings.company_email, to_seller: this.get_against_seller(), hub_item: this.item_details.name, message diff --git a/erpnext/public/js/hub/pages/PublishedItems.vue b/erpnext/public/js/hub/pages/PublishedItems.vue index 52df2850a9..6559f7910a 100644 --- a/erpnext/public/js/hub/pages/PublishedItems.vue +++ b/erpnext/public/js/hub/pages/PublishedItems.vue @@ -5,10 +5,10 @@ >
    -
    {{ page_title }}
    +
    {{ __('Published Items') }}

    - {{ published_items_message }} + {{ __('You can publish upto 200 items.') }}

    @@ -16,7 +16,7 @@ class="btn btn-default btn-xs publish-items" v-route="'marketplace/publish'" > - {{ publish_button_text }} + {{ __('Publish More Items') }}
    @@ -26,7 +26,7 @@ :items="items" :item_id_fieldname="item_id_fieldname" :on_click="go_to_item_details_page" - :empty_state_message="empty_state_message" + :empty_state_message="__('You haven\'t published any items yet.')" :empty_state_action="publish_page_action" > @@ -44,16 +44,9 @@ export default { publish_page_action: { label: __('Publish Your First Items'), on_click: () => { - frappe.set_route(`marketplace/home`); + frappe.set_route(`marketplace/publish`); } - }, - - // Constants - page_title: __('Published Items'), - publish_button_text: __('Publish More Items'), - published_items_message: __('You can publish upto 200 items.'), - // TODO: Add empty state action - empty_state_message: __('You haven\'t published any items yet.') + } }; }, created() { diff --git a/erpnext/public/js/hub/vue-plugins.js b/erpnext/public/js/hub/vue-plugins.js index e18af0c428..439c1f24e2 100644 --- a/erpnext/public/js/hub/vue-plugins.js +++ b/erpnext/public/js/hub/vue-plugins.js @@ -62,5 +62,5 @@ Vue.directive('img-src', { }); Vue.filter('striphtml', function (text) { - return strip_html(text); + return strip_html(text || ''); }); \ No newline at end of file From adef70f8df948442cff1f7e9d7bb844b97ee03ac Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 16:12:50 +0530 Subject: [PATCH 17/25] [hub] update_hub_url patch to use marketplace_url --- erpnext/patches.txt | 2 +- erpnext/patches/v11_0/update_hub_url.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 1af75e8397..512e33bdb5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -560,6 +560,6 @@ erpnext.patches.v10_0.update_address_template_for_india erpnext.patches.v11_0.add_expense_claim_default_account execute:frappe.delete_doc("Page", "hub") erpnext.patches.v11_0.reset_publish_in_hub_for_all_items -erpnext.patches.v11_0.update_hub_url # 2018-08-31 +erpnext.patches.v11_0.update_hub_url # 2018-08-31 # 2018-09-03 erpnext.patches.v10_0.set_discount_amount erpnext.patches.v10_0.recalculate_gross_margin_for_project diff --git a/erpnext/patches/v11_0/update_hub_url.py b/erpnext/patches/v11_0/update_hub_url.py index abddfd6391..40181a2e90 100644 --- a/erpnext/patches/v11_0/update_hub_url.py +++ b/erpnext/patches/v11_0/update_hub_url.py @@ -2,4 +2,4 @@ import frappe def execute(): frappe.reload_doc('hub_node', 'doctype', 'Marketplace Settings') - frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'hub_url', 'https://hubmarket.org') + frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'marketplace_url', 'https://hubmarket.org') From bffb707c177beae4db07df96302843706e629abd Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 16:39:59 +0530 Subject: [PATCH 18/25] [fix] add message for admin users before register dialog - use is_registered api for page routes --- erpnext/public/js/hub/PageContainer.vue | 4 ++-- erpnext/public/js/hub/marketplace.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/hub/PageContainer.vue b/erpnext/public/js/hub/PageContainer.vue index 981c44e8f5..0bc6712056 100644 --- a/erpnext/public/js/hub/PageContainer.vue +++ b/erpnext/public/js/hub/PageContainer.vue @@ -39,8 +39,8 @@ function get_route_map() { 'marketplace/selling': Selling, 'marketplace/selling/:buyer/:item': Messages } - const hub_registered = hub.settings.registered; - return hub_registered + + return hub.is_seller_registered() ? Object.assign({}, read_only_routes, registered_routes) : read_only_routes; } diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index bacca47545..bd9f64bcdd 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -93,6 +93,11 @@ erpnext.hub.Marketplace = class Marketplace { } show_register_dialog() { + if(frappe.session.user === 'Administrator') { + frappe.msgprint(__('You need to be a user other than Administrator with System Manager and Item Manager roles to register on Marketplace.')); + return; + } + this.register_dialog = ProfileDialog( __('Become a Seller'), { From b296be041e3c02f0ba6570f6b8adec0ab7fcd724 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 3 Sep 2018 16:53:56 +0530 Subject: [PATCH 19/25] fix: email in profile dialog --- .../js/hub/components/profile_dialog.js | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 636bf1436a..8e3abc37eb 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -1,28 +1,15 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { const fields = [ - { - fieldname: 'company_email', - label: __('Email'), - fieldtype: 'Read Only' - }, { fieldtype: 'Link', fieldname: 'company', label: __('Company'), - options: 'Company', - onchange: () => { - const value = dialog.get_value('company'); - if (value) { - frappe.db.get_doc('Company', value) - .then(company => { - console.log(company.company_logo); - dialog.set_values({ - company_logo: company.company_logo, - company_description: company.company_description - }); - }); - } - } + options: 'Company' + }, + { + fieldtype: 'Read Only', + fieldname: 'email', + label: __('Email') }, { label: __('About your company'), From d4bba297c28fa1e80a199df965d0c18c348d297b Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 3 Sep 2018 17:12:22 +0530 Subject: [PATCH 20/25] fix: Container title --- erpnext/public/js/hub/pages/PublishedItems.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/hub/pages/PublishedItems.vue b/erpnext/public/js/hub/pages/PublishedItems.vue index 6559f7910a..cbb22164e6 100644 --- a/erpnext/public/js/hub/pages/PublishedItems.vue +++ b/erpnext/public/js/hub/pages/PublishedItems.vue @@ -22,7 +22,7 @@ Date: Mon, 3 Sep 2018 17:24:17 +0530 Subject: [PATCH 21/25] fix: Move image saving code to hub server --- erpnext/hub_node/api.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index df3e7efb8f..0492dde527 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -142,7 +142,7 @@ def publish_selected_items(items_to_publish): try: item_sync_preprocess(len(items)) - load_base64_image_from_items(items) + convert_relative_image_urls_to_absolute(items) # TODO: Publish Progress connection = get_hub_connection() @@ -183,29 +183,14 @@ def item_sync_postprocess(): frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'sync_in_progress', 0) -def load_base64_image_from_items(items): +def convert_relative_image_urls_to_absolute(items): + from urlparse import urljoin + for item in items: file_path = item['image'] - file_name = os.path.basename(file_path) - base64content = None - if file_path.startswith('http'): - # fetch content and then base64 it - url = file_path - response = requests.get(url) - base64content = base64.b64encode(response.content) - else: - # read file then base64 it - file_path = os.path.abspath(get_file_path(file_path)) - with io.open(file_path, 'rb') as f: - base64content = base64.b64encode(f.read()) - - image_data = json.dumps({ - 'file_name': file_name, - 'base64': base64content - }) - - item['image'] = image_data + if file_path.startswith('/files/'): + item['image'] = urljoin(frappe.utils.get_url(), file_path) def get_hub_connection(): From b2eadfe31de5dbfd23d6f875df37fc3d391d884e Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 17:31:43 +0530 Subject: [PATCH 22/25] [hub] show become a seller button to all, but not dialog --- erpnext/public/js/hub/marketplace.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index bd9f64bcdd..808afca37e 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -29,13 +29,10 @@ erpnext.hub.Marketplace = class Marketplace { this.setup_events(); this.refresh(); - if (is_subset(['System Manager', 'Item Manager'], frappe.user_roles)) { - // show buttons only to System Manager - if (!hub.is_seller_registered()) { - this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this)) - } else { - this.page.set_secondary_action('Add Users', this.show_add_user_dialog.bind(this)); - } + if (!hub.is_seller_registered()) { + this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this)) + } else { + this.page.set_secondary_action('Add Users', this.show_add_user_dialog.bind(this)); } }); } @@ -98,6 +95,11 @@ erpnext.hub.Marketplace = class Marketplace { return; } + if (!is_subset(['System Manager', 'Item Manager'], frappe.user_roles)) { + frappe.msgprint(__('You need to be a user with System Manager and Item Manager roles to register on Marketplace.')); + return; + } + this.register_dialog = ProfileDialog( __('Become a Seller'), { @@ -126,6 +128,11 @@ erpnext.hub.Marketplace = class Marketplace { } show_add_user_dialog() { + if (!is_subset(['System Manager', 'Item Manager'], frappe.user_roles)) { + frappe.msgprint(__('You need to be a user with System Manager and Item Manager roles to add users to Marketplace.')); + return; + } + this.get_unregistered_users() .then(r => { const user_list = r.message; From b592a76016f14199c31d199d0de20f9558c0f0c7 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 3 Sep 2018 17:49:11 +0530 Subject: [PATCH 23/25] fix: Selling Messages --- erpnext/public/js/hub/pages/Selling.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/hub/pages/Selling.vue b/erpnext/public/js/hub/pages/Selling.vue index 9c8ede6664..8743027885 100644 --- a/erpnext/public/js/hub/pages/Selling.vue +++ b/erpnext/public/js/hub/pages/Selling.vue @@ -17,15 +17,15 @@
    - {{ message.buyer }} + {{ message.buyer_name }}
    - {{ message.sender }}: {{ message.content }} + {{ message.sender }}: {{ message.message | striphtml }}
    From 6ba9b3f4dea25fc567dfba9187415e582386d47b Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 17:49:11 +0530 Subject: [PATCH 24/25] [hub] hide Contact Seller and Save Item in read-only --- .../public/js/hub/components/DetailView.vue | 2 +- erpnext/public/js/hub/pages/Item.vue | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/erpnext/public/js/hub/components/DetailView.vue b/erpnext/public/js/hub/components/DetailView.vue index 70ec94c6c1..2f1a941b46 100644 --- a/erpnext/public/js/hub/components/DetailView.vue +++ b/erpnext/public/js/hub/components/DetailView.vue @@ -38,7 +38,7 @@
    -
    +