[SOLVED] Which function is responsible for registering new System User?

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.

@rmehta Can you please take a look ?

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 @srajelli,

check sign_up()` method in user.py

Thanks, Makarand

1 Like

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

@anand can you have a look

@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

@srajelli since you are a dev, please spend some time answering other users too. :wink:

1 Like

@rmehta Happily :slight_smile: