[hub] move register_seller to api, remove old code
This commit is contained in:
parent
c726fce4b1
commit
a8065ff725
@ -1,11 +1,63 @@
|
|||||||
from __future__ import unicode_literals
|
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.frappeclient import FrappeClient
|
||||||
from frappe.desk.form.load import get_attachments
|
from frappe.desk.form.load import get_attachments
|
||||||
from frappe.utils.file_manager import get_file_path
|
from frappe.utils.file_manager import get_file_path
|
||||||
from six import string_types
|
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()
|
@frappe.whitelist()
|
||||||
def call_hub_method(method, params=None):
|
def call_hub_method(method, params=None):
|
||||||
connection = get_hub_connection()
|
connection = get_hub_connection()
|
||||||
|
@ -208,38 +208,6 @@
|
|||||||
"translatable": 0,
|
"translatable": 0,
|
||||||
"unique": 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_bulk_edit": 0,
|
||||||
"allow_in_quick_entry": 0,
|
"allow_in_quick_entry": 0,
|
||||||
@ -512,7 +480,7 @@
|
|||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 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",
|
"modified_by": "cave@aperture.com",
|
||||||
"module": "Hub Node",
|
"module": "Hub Node",
|
||||||
"name": "Marketplace Settings",
|
"name": "Marketplace Settings",
|
||||||
|
@ -15,107 +15,29 @@ class MarketplaceSettings(Document):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
self.site_name = frappe.utils.get_url()
|
self.site_name = frappe.utils.get_url()
|
||||||
|
|
||||||
|
|
||||||
def get_marketplace_url(self):
|
def get_marketplace_url(self):
|
||||||
return self.marketplace_url
|
return self.marketplace_url
|
||||||
|
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
""" Create a User on hub.erpnext.org and return username/password """
|
""" 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()
|
self.site_name = frappe.utils.get_url()
|
||||||
|
|
||||||
data = {
|
register_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register'
|
||||||
'profile': self.as_json()
|
data = {'profile': self.as_json(), 'email': frappe.session.user}
|
||||||
}
|
headers = {'accept': 'application/json'}
|
||||||
post_url = self.get_marketplace_url() + '/api/method/hub.hub.api.register'
|
|
||||||
|
|
||||||
response = requests.post(post_url, data=data, headers = {'accept': 'application/json'})
|
|
||||||
|
|
||||||
|
response = requests.post(register_url, data = data, headers = headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
message = response.json().get('message')
|
message = response.json().get('message')
|
||||||
else:
|
else:
|
||||||
frappe.throw(json.loads(response.text))
|
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
|
return message or None
|
||||||
|
|
||||||
# def unregister(self):
|
|
||||||
# """ Disable the User on hub.erpnext.org"""
|
|
||||||
|
|
||||||
# hub_connector = frappe.get_doc(
|
def unregister(self):
|
||||||
# 'Data Migration Connector', 'Hub Connector')
|
""" Disable the User on hub.erpnext.org"""
|
||||||
|
pass
|
||||||
# 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')
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hub_registered: hub.settings.registered && frappe.session.user === hub.settings.company_email,
|
hub_registered: hub.settings.registered,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
label: __('Browse'),
|
label: __('Browse'),
|
||||||
|
@ -101,7 +101,7 @@ erpnext.hub.Marketplace = class Marketplace {
|
|||||||
|
|
||||||
register_seller(form_values) {
|
register_seller(form_values) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: 'erpnext.hub_node.doctype.marketplace_settings.marketplace_settings.register_seller',
|
method: 'erpnext.hub_node.api.register_seller',
|
||||||
args: form_values
|
args: form_values
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.register_dialog.hide();
|
this.register_dialog.hide();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user