-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ADD] 8.0 - New module 'base_user_role' to manage user roles efficiently #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a2f2ac1
to
9d85bf6
Compare
About Travis: flake8 errors and tests failure not related to this module. |
Very good contribution (high quality of code, useful, well documented). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thanks @sebalix
Code, no test. Comments inline
'license': 'AGPL-3', | ||
'maintainer': 'ABF OSIELL', | ||
'website': 'http://www.osiell.com', | ||
'depends': [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this key. base
dependency is implicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you should depend on your module at least in base, but base is implicit when depending on other module.
'res.users', string=u"Users", compute='_compute_user_ids') | ||
|
||
@api.multi | ||
@api.depends('line_ids') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line_ids.user_id
def update_users(self): | ||
"""Update all the users concerned by the roles identified by `ids`.""" | ||
users = self.mapped('user_ids') | ||
if users: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be need for this guard, mapped will just return an empty Recordset that should work with the other method just fine due to record loop
'res.users', string=u"User") | ||
date_from = fields.Date(u"From") | ||
date_to = fields.Date(u"To") | ||
is_active = fields.Boolean(u"Active", compute='_compute_is_active') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
active
is the Odoo norm for this col - although I'm with you on prefixing bool cols with linking verbs like is
, has
, etc. It also comes with some defaults filters and such, so makes it worth using despite the hurt to naming OCD
That said, it also needs to be store=True
to allow all of that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but I was unable to set a working domain
on the XML views to display all the lines (as we don't want to hide them from the administrator in any case, we just want to filter them when setting groups). If I set the domain on the Python field, it works fine, but then it does not dispense to filter the lines in the ResUsers.set_groups_from_roles
method. And as I've seen no benefit to use the standard active
field I ended up adding my own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I could rename it to 'is_enabled'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the is_enabled
idea - it is far enough away from active
that people won't be trying to change it all the time. I know I would have probably done this during a migration had I not already gotten the reasoning behind it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done!
'res.users.role', string=u"Roles", compute='_compute_role_ids') | ||
|
||
@api.multi | ||
@api.depends('role_line_ids') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role_line_ids.role_id
Oh please also check Travis and Runbot 😉 |
@@ -0,0 +1,2 @@ | |||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | |||
access_res_users_role,access_res_users_role,model_res_users_role,"base.group_erp_manager",1,1,1,1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From travis https://travis-ci.org/OCA/server-tools/jobs/176051212#L1703
The model res.users.role.line has no access rules, consider adding one. E.g.
access_res_users_role_line,access_res_users_role_line,model_res_users_role_line,"base.group_erp_manager",1,0,0,0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Thank you for the review, I'll fix these points soon |
'res.users.role', string=u"Role", ondelete='cascade') | ||
user_id = fields.Many2one( | ||
'res.users', string=u"User") | ||
date_from = fields.Date(u"From") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date from may be default the date now of the create moment.
Good contribution.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dates are optional, no dates = role activated immediately
I think all the points are fixed. |
Travis is still mad 🔴 |
You mean I have to fix lint errors of others modules in this one? Tests fail on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah ok the build looks broken on 8.0 branch in the same way, so you are correct that we should not be fixing it here.
I fixed the other modules in #616 to get green builds. |
7a32246
to
7fbd3b1
Compare
7fbd3b1
to
6227edf
Compare
Rebased |
@adrienpeiffer you should have a look at this. |
Tested functionality on runbot 👍 |
@mikevhe18 @azmimr67 you guys should take a look at this PR and help review |
We're approved for merge. @sebalix - do you prefer to squash your own commits or would you rather me do it? I don't think I've gotten this preference from you yet, but sorry if I'm double asking. |
@lasley You can squash them, no trouble |
Thanks for the awesome new module @sebalix! Do you have any plans to migrate it forward? |
…CA#608) * [ADD] New module 'base_user_role' * [FIX] base_user_role - Review * [FIX] base_user_role - Review s/is_active/is_enabled/ * [FIX] base_user_role - Review s/is_active/is_enabled/ * [IMP] base_user_role - Translations updated (template + FR) * [FIX] base_user_role - Lint
…CA#608) * [ADD] New module 'base_user_role' * [FIX] base_user_role - Review * [FIX] base_user_role - Review s/is_active/is_enabled/ * [FIX] base_user_role - Review s/is_active/is_enabled/ * [IMP] base_user_role - Translations updated (template + FR) * [FIX] base_user_role - Lint
…CA#608) * [ADD] New module 'base_user_role' * [FIX] base_user_role - Review * [FIX] base_user_role - Review s/is_active/is_enabled/ * [FIX] base_user_role - Review s/is_active/is_enabled/ * [IMP] base_user_role - Translations updated (template + FR) * [FIX] base_user_role - Lint
…CA#608) * [ADD] New module 'base_user_role' * [FIX] base_user_role - Review * [FIX] base_user_role - Review s/is_active/is_enabled/ * [FIX] base_user_role - Review s/is_active/is_enabled/ * [IMP] base_user_role - Translations updated (template + FR) * [FIX] base_user_role - Lint
…CA#608) * [ADD] New module 'base_user_role' * [FIX] base_user_role - Review * [FIX] base_user_role - Review s/is_active/is_enabled/ * [FIX] base_user_role - Review s/is_active/is_enabled/ * [IMP] base_user_role - Translations updated (template + FR) * [FIX] base_user_role - Lint
Syncing from upstream OCA/server-tools (13.0)
Note : we are using this module on version 6.0, 7.0 and 8.0 I just added the support for dates recently on the 8.0 version. I'll migrate it to 9.0 and 10.0 soon.
Related issue: #146
User roles
This module was written to extend the standard functionality regarding users and groups management. It helps creating well-defined user roles and associating them to users.
It can become very hard to maintain a large number of user profiles over time, juggling with many technical groups. For this purpose, this module will help you to:
That way you make clear the different responsabilities within a company, and are able to add and update user accounts in a scalable and reliable way.
Configuration
To configure this module, you need to go to Configuration / Users / Roles, and create a new role. From there, you can add groups to compose your role, and then associate users to it.