Function which registers new System User from Setup Page
I tried to tinker with a function in frappe/frappe/utils/user.py
def add_system_manager(email, first_name=None, last_name=None):
# add user
user = frappe.new_doc(“User”)
user.update({
“_id”: uuid.uuid4(),
“name”: email,
“email”: email,
“enabled”: 1,
“first_name”: first_name or email,
“last_name”: last_name,
“user_type”: “System User”
})
user.insert()
Please notice the highlighted text , I am expecting something like that to add in the tabUser table every time a system user is added. But however no changes are reflected.
did you create the custom field _id
? if not please create the custom field and try again.
Thanks, Makarand
Hi makarand_b , I created a custom field _id and tried again this time if entered from the form the value gets inserted in the db but it doesn’t happen programmatically as I listed in the above code.
check the return value of uuid.uuid4()
Thanks for reply , It returns string , but i also tried manually entering the value for
_id = “5688” even that doesn’t updates. Is there any other function responsible for user signup ?
Hi @makarand_b I tried but no success
user = frappe.get_doc({
“doctype”:“User”,
“_id” : “2345678900000098765432234567”,
“email”: email,
“first_name”: full_name,
“enabled”: 1,
“new_password”: random_string(10),
“user_type”: “Website User”
})
However the _id gets updated if we use API . Not sure what the problem is .
Thanks
@srajelli may be it is because the fieldname is _id
. Most likely, fieldnames that start with underscores are considered internal/temporary and are not passed from frappe form to the Document model.
Try using some other id fieldname like unique_id
and see if it works successfully.
@anand Thanks for reply , I tried changing the fieldname from _id to unique_id but still no updates are recorded. By the way I am trying to register the value for the id like this :
frappe/frappe/utils/user.py
add user
user = frappe.new_doc(“User”)
user.update({
“_id”: uuid.uuid4(),
“name”: email,
“email”: email,
“enabled”: 1,
“first_name”: first_name or email,
“last_name”: last_name,
“user_type”: “System User”
})
user.insert()
I also tried changing sign_up() function frappe/frappe/core/doctype/user/user.py
But I think actual user sign_up is not handled here but somewhere else ?
UPDATE : Fixed the issue by creating a hook