For an app I would like to create two custom user roles and save them to a custom app where I already have a number of custom doctypes set up. Is it possible to define custom user roles with permissions and save them inside of an app?
Define Custom roles in hooks.py file of your app like this
{"dt": "Role", "filters": [
[
"name", "in", [
"Role1" ,
"Role2"
]
]
]},
and Custom Doc Permission like this
{"dt": "Custom DocPerm", "filters": [
[
"role", "in", [
"Role1",
"Role2"
]
]
]},
Is it correct like this? I do not see the extra user roles show up inside of the user roles list view.
Also, I am just using frappe without erpnext, could that interfere?
do it like this
fixtures = [ {"dt": "Role", "filters": [ [ "name", "in", [ "Role1" , "Role2" ] ] ]}, {"dt": "Custom DocPerm", "filters": [ [ "role", "in", [ "Role1", "Role2" ] ] }, ]
Hey,
Thanks for your help. I believe it did something but not quite what I needed it. For now I will just develop the roles in our environment and see if I can export them as fixtures later on and try to attach them.
EDIT: You need to check the quote marks to be regular double quotes instead of the angled ones.
Yes, create your Roles and test them, then create a hook like this (the filter syntax is quite flexible):
fixtures = [{
'dt': 'Role', 'filters': {'name': ('in', ('Role1','Role2','Role3'))}
}]
Then run the following to export to your custom app. They will be imported on a migrate if your app is installed on another site:
bench --site <site> export-fixtures
Backticks won’t work as they are not valid python syntax
Roles also appear to be installed mainly in the hook after_install
, e.g.:
after_install = "erpnext.setup.install.after_install"