mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-21 15:48:29 +00:00
feat: Add add_user dialog and methods
- wip
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user