diff --git a/base_user_role_profile/README.rst b/base_user_role_profile/README.rst index 15719a4af..d858a887e 100644 --- a/base_user_role_profile/README.rst +++ b/base_user_role_profile/README.rst @@ -23,9 +23,9 @@ User profiles :target: https://runbot.odoo-community.org/runbot/253/12.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| -Extending the base_user_role module, this one adds the notion of profiles. Effectively profiles act as an additional filter to how the roles are used. Through the new widget, much in the same way that a user can switch companies when they are part of the multi company group, users have the possibility to change profiles when they are part of the multi profiles group. +Extending the base_user_role module, this one adds the notion of profiles. Effectively profiles act as an additional filter to how the roles are used. This allows users to switch their permission groups dynamically. This can be useful for example to: - finer grain control on menu and model permissions (with record rules this becomes very flexible) diff --git a/base_user_role_profile/models/user.py b/base_user_role_profile/models/user.py index 5cf879613..181494e28 100644 --- a/base_user_role_profile/models/user.py +++ b/base_user_role_profile/models/user.py @@ -37,7 +37,7 @@ class ResUsers(models.Model): @api.model def create(self, vals): new_record = super().create(vals) - if vals.get("company_id") or vals.get("role_line_ids"): + if vals.get("role_line_ids"): new_record.sudo()._compute_profile_ids() return new_record @@ -47,11 +47,7 @@ class ResUsers(models.Model): self.sudo().write({"profile_id": vals["profile_id"]}) del vals["profile_id"] res = super().write(vals) - if ( - vals.get("company_id") - or vals.get("profile_id") - or vals.get("role_line_ids") - ): + if vals.get("profile_id") or vals.get("role_line_ids"): self.sudo()._compute_profile_ids() return res @@ -73,9 +69,7 @@ class ResUsers(models.Model): def _compute_profile_ids(self): for rec in self: role_lines = rec.role_line_ids - profiles = role_lines.filtered( - lambda r: r.company_id == rec.company_id - ).mapped("profile_id") + profiles = role_lines.mapped("profile_id") rec.profile_ids = profiles # set defaults in case applicable profile changes rec._update_profile_id() diff --git a/base_user_role_profile/readme/CONFIGURE.rst b/base_user_role_profile/readme/CONFIGURE.rst index 31f2dabee..d45c6d318 100644 --- a/base_user_role_profile/readme/CONFIGURE.rst +++ b/base_user_role_profile/readme/CONFIGURE.rst @@ -1,2 +1 @@ Go to Configuration / Users / Profiles and create a profile. Go to Configuration / Users / Roles and define some role lines with profiles. -Be careful when defining role lines that company ids and profiles are correctly configured. diff --git a/base_user_role_profile/readme/DESCRIPTION.rst b/base_user_role_profile/readme/DESCRIPTION.rst index 3f2b4e36a..5eab53627 100644 --- a/base_user_role_profile/readme/DESCRIPTION.rst +++ b/base_user_role_profile/readme/DESCRIPTION.rst @@ -1,4 +1,4 @@ -Extending the base_user_role module, this one adds the notion of profiles. Effectively profiles act as an additional filter to how the roles are used. Through the new widget, much in the same way that a user can switch companies when they are part of the multi company group, users have the possibility to change profiles when they are part of the multi profiles group. +Extending the base_user_role module, this one adds the notion of profiles. Effectively profiles act as an additional filter to how the roles are used. This allows users to switch their permission groups dynamically. This can be useful for example to: - finer grain control on menu and model permissions (with record rules this becomes very flexible) @@ -8,5 +8,3 @@ This allows users to switch their permission groups dynamically. This can be use When you define a role, you have the possibility to link it to a profile. Roles are applied to users in the following way: - Apply user's roles without profiles in any case - Apply user's roles that are linked to the currently selected profile - -Note that this module assumes a multicompany environment diff --git a/base_user_role_profile/static/src/js/switch_profile_menu.js b/base_user_role_profile/static/src/js/switch_profile_menu.js deleted file mode 100644 index 033029d09..000000000 --- a/base_user_role_profile/static/src/js/switch_profile_menu.js +++ /dev/null @@ -1,85 +0,0 @@ -odoo.define("web.SwitchProfileMenu", function (require) { - "use strict"; - - var config = require("web.config"); - var core = require("web.core"); - var session = require("web.session"); - var SystrayMenu = require("web.SystrayMenu"); - var Widget = require("web.Widget"); - var _t = core._t; - - var SwitchProfileMenu = Widget.extend({ - template: "SwitchProfileMenu", - events: { - "click .dropdown-item[data-menu]": "_onClick", - }, - - init: function () { - this._super.apply(this, arguments); - this.isMobile = config.device.isMobile; - this._onClick = _.debounce(this._onClick, 1500, true); - }, - - willStart: function () { - return session.user_profiles ? this._super() : $.Deferred().reject(); - }, - - start: function () { - var profilesList = ""; - if (this.isMobile) { - profilesList = - '
  • ' + - _t("Tap on the list to change profile") + - "
  • "; - } else { - this.$(".oe_topbar_name").text( - session.user_profiles.current_profile[1] - ); - } - _.each(session.user_profiles.allowed_profiles, function (profile) { - var a = ""; - if (profile[0] == session.user_profiles.current_profile[0]) { - a = ''; - } else { - a = ''; - } - profilesList += - '' + - a + - profile[1] + - ""; - }); - this.$(".dropdown-menu").html(profilesList); - return this._super(); - }, - - _onClick: function (ev) { - var self = this; - ev.preventDefault(); - var profileID = $(ev.currentTarget).data("profile-id"); - // We use this instead of the location.reload() because permissions change - // and we might land on a menu that we don't have permissions for. Thus it - // is cleaner to reload any root menu - this._rpc({ - model: "res.users", - method: "action_profile_change", - args: [ - [session.uid], - { - profile_id: profileID, - }, - ], - }).done(function (result) { - self.trigger_up("do_action", { - action: result, - }); - }); - }, - }); - - SystrayMenu.Items.push(SwitchProfileMenu); - - return SwitchProfileMenu; -}); diff --git a/base_user_role_profile/static/src/xml/templates.xml b/base_user_role_profile/static/src/xml/templates.xml deleted file mode 100644 index 4d7162594..000000000 --- a/base_user_role_profile/static/src/xml/templates.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - -
  • - -
  • -
    - -
    diff --git a/base_user_role_profile/tests/test_user_role.py b/base_user_role_profile/tests/test_user_role.py index dbfd9ad13..44830c4b2 100644 --- a/base_user_role_profile/tests/test_user_role.py +++ b/base_user_role_profile/tests/test_user_role.py @@ -18,15 +18,10 @@ class TestUserProfile(TransactionCase): self.user_model = self.env["res.users"] self.role_model = self.env["res.users.role"] - self.company1 = self.env.ref("base.main_company") - self.company2 = self.env["res.company"].create({"name": "company2"}) - self.default_user = self.env.ref("base.default_user") user_vals = { "name": "USER TEST (ROLES)", "login": "user_test_roles", - "company_ids": [(6, 0, [self.company1.id, self.company2.id])], - "company_id": self.company1.id, } self.user_id = self.user_model.create(user_vals) @@ -115,29 +110,3 @@ class TestUserProfile(TransactionCase): user_group_ids = set(user_group_ids) expected_groups = set(self.role1_group_ids + self.role3_group_ids) self.assertEqual(user_group_ids, expected_groups) - - def test_sync_profile_change_company(self): - line1_vals = { - "role_id": self.role1_id.id, - "user_id": self.user_id.id, - "company_id": self.company1.id, - } - self.user_id.write({"role_line_ids": [(0, 0, line1_vals)]}) - line2_vals = { - "role_id": self.role2_id.id, - "user_id": self.user_id.id, - "company_id": self.company2.id, - } - - self.user_id.write({"role_line_ids": [(0, 0, line2_vals)]}) - self.assertEqual(self.user_id.profile_ids, self.profile1_id) - - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - expected_group_ids = sorted(set(self.role1_group_ids)) - self.assertEqual(user_group_ids, expected_group_ids) - - self.user_id.company_id = self.company2 - self.assertEqual(self.user_id.profile_ids, self.profile2_id) - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - expected_group_ids = sorted(set(self.role2_group_ids)) - self.assertEqual(user_group_ids, expected_group_ids) diff --git a/base_user_role_profile/views/role.xml b/base_user_role_profile/views/role.xml index 60e4f21e3..b07afdce5 100644 --- a/base_user_role_profile/views/role.xml +++ b/base_user_role_profile/views/role.xml @@ -8,7 +8,7 @@ diff --git a/base_user_role_profile/views/user.xml b/base_user_role_profile/views/user.xml index 59e833cc9..55adcd465 100644 --- a/base_user_role_profile/views/user.xml +++ b/base_user_role_profile/views/user.xml @@ -22,25 +22,11 @@ - - - res.users.form.inherit - res.users - - - - - - -