Skip to content

Conversation

sebalix
Copy link
Contributor

@sebalix sebalix commented Nov 15, 2016

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:

  • define functional roles by aggregating low-level groups,
  • set user accounts with the predefined roles (roles are cumulative),
  • update groups of all relevant user accounts (all at once),
  • ensure that user accounts will have the groups defined in their roles (nothing more, nothing less). In other words, you can not set groups manually on a user as long as there is roles configured on it,
  • activate/deactivate roles depending on the date (useful to plan holidays, etc)
  • get a quick overview of roles and the related user accounts.

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.

@sebalix
Copy link
Contributor Author

sebalix commented Nov 15, 2016

About Travis: flake8 errors and tests failure not related to this module.

@jcdrubay
Copy link
Contributor

Very good contribution (high quality of code, useful, well documented).
I hope it can be reviewed and merged soon 👍

Copy link
Contributor

@lasley lasley left a 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': [
Copy link
Contributor

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.

Copy link
Member

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')
Copy link
Contributor

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:
Copy link
Contributor

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')
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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'?

Copy link
Contributor

@lasley lasley Nov 17, 2016

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.

Copy link
Contributor Author

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')
Copy link
Contributor

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

@lasley lasley added this to the 8.0 milestone Nov 16, 2016
@lasley
Copy link
Contributor

lasley commented Nov 16, 2016

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@sebalix
Copy link
Contributor Author

sebalix commented Nov 16, 2016

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")
Copy link

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.
👍

Copy link
Contributor Author

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

@sebalix
Copy link
Contributor Author

sebalix commented Nov 18, 2016

I think all the points are fixed.

@lasley
Copy link
Contributor

lasley commented Nov 18, 2016

Travis is still mad 🔴

@sebalix
Copy link
Contributor Author

sebalix commented Nov 18, 2016

You mean I have to fix lint errors of others modules in this one? Tests fail on fetchmail_notify_error_to_sender.

Copy link
Contributor

@lasley lasley left a 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.

@sebalix
Copy link
Contributor Author

sebalix commented Nov 19, 2016

I fixed the other modules in #616 to get green builds.

@sebalix
Copy link
Contributor Author

sebalix commented Nov 19, 2016

Rebased

@sbidoul
Copy link
Member

sbidoul commented Nov 20, 2016

@adrienpeiffer you should have a look at this.

@andhit-r
Copy link
Member

andhit-r commented Dec 8, 2016

Tested functionality on runbot 👍

@andhit-r
Copy link
Member

andhit-r commented Dec 9, 2016

@mikevhe18 @azmimr67 you guys should take a look at this PR and help review

@lasley
Copy link
Contributor

lasley commented Dec 9, 2016

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.

@sebalix
Copy link
Contributor Author

sebalix commented Dec 9, 2016

@lasley You can squash them, no trouble

@lasley lasley merged commit 7a272ae into OCA:8.0 Dec 9, 2016
@lasley
Copy link
Contributor

lasley commented Dec 9, 2016

Thanks for the awesome new module @sebalix! Do you have any plans to migrate it forward?

sebalix added a commit to osiell/server-tools that referenced this pull request Dec 9, 2016
…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
@sebalix
Copy link
Contributor Author

sebalix commented Dec 9, 2016

@lasley Thank you! Yes, I plan to migrate it to v9 (see #641) and v10 right after.

@sebalix sebalix deleted the 8.0-base_user_role branch December 9, 2016 21:02
adrienpeiffer pushed a commit to acsone/server-tools that referenced this pull request Jan 2, 2017
…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
mstuttgart pushed a commit to multidadosti-erp/server-tools that referenced this pull request Apr 20, 2017
…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
novawish pushed a commit to novawish/server-tools that referenced this pull request Oct 23, 2017
…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
sbejaoui pushed a commit to acsone/server-tools that referenced this pull request Dec 14, 2018
…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
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (13.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants