Merge branch 'hub-redesign' of https://github.com/frappe/erpnext into hub-redesign
diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py
index 5ce0665..0f1b0a1 100644
--- a/erpnext/hub_node/api.py
+++ b/erpnext/hub_node/api.py
@@ -119,39 +119,52 @@
def load_base64_image_from_items(items):
- import io, base64, urllib, os
+ import io, base64, urllib, os, requests, tempfile
from frappe.utils.file_manager import get_file_path
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
- file_path = os.path.join('/tmp', file_name)
- urllib.urlretrieve(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())
- with io.open(file_path, 'rb') as f:
- image_data = json.dumps({
- 'file_name': file_name,
- 'base64': base64.b64encode(f.read())
- })
+ image_data = json.dumps({
+ 'file_name': file_name,
+ 'base64': base64content
+ })
item['image'] = image_data
def get_hub_connection():
+ read_only = True
+
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
- hub_connection = hub_connector.get_connection()
- return hub_connection.connection
+
+ # 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
- hub_connection = FrappeClient(frappe.conf.hub_url)
- return hub_connection
-
+ if read_only:
+ hub_url = frappe.db.get_single_value('Hub Settings', 'hub_url')
+ hub_connection = FrappeClient(hub_url)
+ return hub_connection
def get_field_mappings():
return []
diff --git a/erpnext/hub_node/doctype/hub_settings/hub_settings.js b/erpnext/hub_node/doctype/hub_settings/hub_settings.js
index ddd86b8..03314bb 100644
--- a/erpnext/hub_node/doctype/hub_settings/hub_settings.js
+++ b/erpnext/hub_node/doctype/hub_settings/hub_settings.js
@@ -1,8 +1,4 @@
frappe.ui.form.on("Hub Settings", {
- refresh: function(frm) {
- frm.disable_save();
- },
-
onload_post_render: function(frm) {
if(frm.get_field("unregister_from_hub").$input)
frm.get_field("unregister_from_hub").$input.addClass("btn-danger");
diff --git a/erpnext/hub_node/doctype/hub_settings/hub_settings.json b/erpnext/hub_node/doctype/hub_settings/hub_settings.json
index a0d8188..e230515 100644
--- a/erpnext/hub_node/doctype/hub_settings/hub_settings.json
+++ b/erpnext/hub_node/doctype/hub_settings/hub_settings.json
@@ -19,6 +19,39 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "default": "https://hubmarket.org",
+ "fieldname": "hub_url",
+ "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": "Hub URL",
+ "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": "registered",
"fieldtype": "Check",
"hidden": 0,
@@ -83,38 +116,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "company_registered",
- "fieldtype": "Check",
- "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 Registered",
- "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": "company",
"fieldtype": "Link",
"hidden": 0,
@@ -341,203 +342,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "users_sb",
- "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": "Enabled Users",
- "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,
- "depends_on": "",
- "fieldname": "publish_section",
- "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": "Publish",
- "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": "publish",
- "fieldtype": "Check",
- "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": "Publish Items to Hub",
- "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,
- "depends_on": "publish",
- "fieldname": "publish_pricing",
- "fieldtype": "Check",
- "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": "Publish Pricing",
- "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,
- "depends_on": "eval:(doc.publish && doc.publish_pricing)",
- "fieldname": "selling_price_list",
- "fieldtype": "Link",
- "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": "Selling Price List",
- "length": 0,
- "no_copy": 0,
- "options": "Price List",
- "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,
- "depends_on": "publish",
- "fieldname": "publish_availability",
- "fieldtype": "Check",
- "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": "Publish Availability",
- "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,
"depends_on": "",
"fieldname": "last_sync_datetime",
"fieldtype": "Datetime",
@@ -675,7 +479,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-07-30 10:43:28.818498",
+ "modified": "2018-08-29 17:46:30.413159",
"modified_by": "Administrator",
"module": "Hub Node",
"name": "Hub Settings",
@@ -709,5 +513,6 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1,
- "track_seen": 0
+ "track_seen": 0,
+ "track_views": 0
}
\ No newline at end of file
diff --git a/erpnext/hub_node/doctype/hub_settings/hub_settings.py b/erpnext/hub_node/doctype/hub_settings/hub_settings.py
index e445531..7478db9 100644
--- a/erpnext/hub_node/doctype/hub_settings/hub_settings.py
+++ b/erpnext/hub_node/doctype/hub_settings/hub_settings.py
@@ -15,22 +15,19 @@
class HubSettings(Document):
def validate(self):
- protocol = 'http://'
- self.site_name = protocol + frappe.local.site + ':' + str(frappe.conf.webserver_port)
- if self.publish_pricing and not self.selling_price_list:
- frappe.throw(_("Please select a Price List to publish pricing"))
+ self.site_name = frappe.utils.get_url()
def get_hub_url(self):
- if not frappe.conf.hub_url:
- frappe.throw('hub_url is not set in site_config')
- return frappe.conf.hub_url
+ return self.hub_url
def register(self):
""" Create a User on hub.erpnext.org and return username/password """
+ if 'System Manager' not in frappe.get_roles():
+ frappe.throw(_('Only users with System Manager role can register on Marketplace'), frappe.PermissionError)
+
# TODO: site_name for cloud sites
- protocol = 'http://'
- self.site_name = protocol + frappe.local.site + ':' + str(frappe.conf.webserver_port)
+ self.site_name = frappe.utils.get_url()
data = {
'profile': self.as_json()
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index ce69968..6738598 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -559,3 +559,4 @@
erpnext.patches.v10_0.update_address_template_for_india
execute:frappe.delete_doc("Page", "hub")
erpnext.patches.v11_0.reset_publish_in_hub_for_all_items
+erpnext.patches.v11_0.update_hub_url
\ No newline at end of file
diff --git a/erpnext/patches/v11_0/update_hub_url.py b/erpnext/patches/v11_0/update_hub_url.py
new file mode 100644
index 0000000..ced2aaf
--- /dev/null
+++ b/erpnext/patches/v11_0/update_hub_url.py
@@ -0,0 +1,5 @@
+import frappe
+
+def execute():
+ frappe.reload_doc('hub_node', 'doctype', 'Hub Settings')
+ frappe.db.set_value('Hub Settings', 'Hub Settings', 'hub_url', 'https://hubmarket.org')
diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js
index 373f552..67ac502 100644
--- a/erpnext/public/js/hub/marketplace.js
+++ b/erpnext/public/js/hub/marketplace.js
@@ -29,8 +29,8 @@
this.make_body();
this.setup_events();
this.refresh();
- if (!is_registered) {
- this.page.set_primary_action('Become A Seller', this.show_register_dialog.bind(this))
+ if (!is_registered && frappe.user_roles.includes('System Manager')) {
+ this.page.set_primary_action('Become a Seller', this.show_register_dialog.bind(this))
}
});
}