Browse Source

May 19: [FIX] Bug Fixed 'hide_menu_user'

pull/346/merge
Cybrosys Technologies 1 month ago
parent
commit
7b05a66aa3
  1. 1
      hide_menu_user/__manifest__.py
  2. 48
      hide_menu_user/models/res_users.py
  3. 9
      hide_menu_user/security/security.xml
  4. BIN
      hide_menu_user/static/description/assets/icons/logo.png
  5. BIN
      hide_menu_user/static/description/assets/misc/categories.png
  6. BIN
      hide_menu_user/static/description/assets/misc/check-box.png
  7. BIN
      hide_menu_user/static/description/assets/misc/compass.png
  8. BIN
      hide_menu_user/static/description/assets/misc/corporate.png
  9. BIN
      hide_menu_user/static/description/assets/misc/customer-support.png
  10. BIN
      hide_menu_user/static/description/assets/misc/cybrosys-logo.png
  11. BIN
      hide_menu_user/static/description/assets/misc/features.png
  12. BIN
      hide_menu_user/static/description/assets/misc/logo.png
  13. BIN
      hide_menu_user/static/description/assets/misc/pictures.png
  14. BIN
      hide_menu_user/static/description/assets/misc/pie-chart.png
  15. BIN
      hide_menu_user/static/description/assets/misc/right-arrow.png
  16. BIN
      hide_menu_user/static/description/assets/misc/star.png
  17. BIN
      hide_menu_user/static/description/assets/misc/support.png
  18. BIN
      hide_menu_user/static/description/assets/misc/whatsapp.png
  19. BIN
      hide_menu_user/static/description/assets/modules/budget_image.png
  20. BIN
      hide_menu_user/static/description/assets/modules/credit_image.png
  21. BIN
      hide_menu_user/static/description/assets/modules/employee_image.png
  22. BIN
      hide_menu_user/static/description/assets/modules/export_image.png
  23. BIN
      hide_menu_user/static/description/assets/modules/gantt_image.png
  24. BIN
      hide_menu_user/static/description/assets/modules/quotation_image.png
  25. BIN
      hide_menu_user/static/description/assets/screenshots/hero.gif
  26. BIN
      hide_menu_user/static/description/assets/screenshots/screenshot-1.png
  27. BIN
      hide_menu_user/static/description/assets/screenshots/screenshot-2.png
  28. BIN
      hide_menu_user/static/description/assets/screenshots/screenshot-3.png
  29. BIN
      hide_menu_user/static/description/assets/screenshots/screenshot-4.png
  30. BIN
      hide_menu_user/static/description/banner.png

1
hide_menu_user/__manifest__.py

@ -31,7 +31,6 @@
'website': "https://www.cybrosys.com",
'depends': ['base'],
'data': [
'security/security.xml',
'views/res_users_views.xml',
],
'license': 'LGPL-3',

48
hide_menu_user/models/res_users.py

@ -19,7 +19,8 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import fields, models
from odoo import fields, models, api
class ResUsers(models.Model):
@ -29,24 +30,21 @@ class ResUsers(models.Model):
_inherit = 'res.users'
def write(self, vals):
"""
Write method for the ResUsers model.
Ensure the menu will not remain hidden after removing it from the list.
"""
res = super(ResUsers, self).write(vals)
# Store old hide_menu_ids per record
old_hide_menu_map = {record.id: record.hide_menu_ids for record in self}
res = super().write(vals)
for record in self:
old_hide_menu_ids = old_hide_menu_map.get(record.id,
self.env['ir.ui.menu'])
# Add new restrictions
for menu in record.hide_menu_ids:
menu.write({
'restrict_user_ids': [fields.Command.link(record.id)]
})
# Handle unlinked menus (removed from hide_menu_ids)
previous_menus = self.env['ir.ui.menu'].search(
[('restrict_user_ids', 'in', [record.id])])
removed_menus = previous_menus - record.hide_menu_ids
menu.sudo().write({'restrict_user_ids': [(4, record.id)]})
# Remove old ones that are no longer selected
removed_menus = old_hide_menu_ids - record.hide_menu_ids
for menu in removed_menus:
menu.write({
'restrict_user_ids': [fields.Command.unlink(record.id)]
})
menu.sudo().write({'restrict_user_ids': [(3, record.id)]})
return res
def _get_is_admin(self):
@ -63,11 +61,10 @@ class ResUsers(models.Model):
'ir.ui.menu', string="Hidden Menu",
store=True, help='Select menu items that need to '
'be hidden to this user.')
is_admin = fields.Boolean(compute=_get_is_admin, string="Is Admin",
is_admin = fields.Boolean(compute='_get_is_admin', string="Is Admin",
help='Check if the user is an admin.')
class IrUiMenu(models.Model):
"""
Model to restrict the menu for specific users.
@ -77,3 +74,18 @@ class IrUiMenu(models.Model):
restrict_user_ids = fields.Many2many(
'res.users', string="Restricted Users",
help='Users restricted from accessing this menu.')
@api.returns('self')
def _filter_visible_menus(self):
"""
Override to filter out menus restricted for current user.
Applies only to the current user context.
"""
menus = super()._filter_visible_menus()
# Allow system admin to see everything
if self.env.user.has_group('base.group_system'):
return menus
return menus.filtered(
lambda m: self.env.user not in m.restrict_user_ids)

9
hide_menu_user/security/security.xml

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--Rule to hide menu items -->
<record id="ir_ui_menu_rule_user" model="ir.rule">
<field name="name">Restrict Menu from Users</field>
<field name="model_id" ref="model_ir_ui_menu"/>
<field name="domain_force">[('restrict_user_ids','not in',user.id)]</field>
</record>
</odoo>

BIN
hide_menu_user/static/description/assets/icons/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
hide_menu_user/static/description/assets/misc/categories.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
hide_menu_user/static/description/assets/misc/check-box.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
hide_menu_user/static/description/assets/misc/compass.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
hide_menu_user/static/description/assets/misc/corporate.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
hide_menu_user/static/description/assets/misc/customer-support.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
hide_menu_user/static/description/assets/misc/cybrosys-logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
hide_menu_user/static/description/assets/misc/features.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

BIN
hide_menu_user/static/description/assets/misc/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
hide_menu_user/static/description/assets/misc/pictures.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
hide_menu_user/static/description/assets/misc/pie-chart.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
hide_menu_user/static/description/assets/misc/right-arrow.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

BIN
hide_menu_user/static/description/assets/misc/star.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
hide_menu_user/static/description/assets/misc/support.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
hide_menu_user/static/description/assets/misc/whatsapp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
hide_menu_user/static/description/assets/modules/budget_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
hide_menu_user/static/description/assets/modules/credit_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
hide_menu_user/static/description/assets/modules/employee_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
hide_menu_user/static/description/assets/modules/export_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
hide_menu_user/static/description/assets/modules/gantt_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
hide_menu_user/static/description/assets/modules/quotation_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
hide_menu_user/static/description/assets/screenshots/hero.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

BIN
hide_menu_user/static/description/assets/screenshots/screenshot-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 KiB

BIN
hide_menu_user/static/description/assets/screenshots/screenshot-2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 KiB

BIN
hide_menu_user/static/description/assets/screenshots/screenshot-3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

BIN
hide_menu_user/static/description/assets/screenshots/screenshot-4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 KiB

BIN
hide_menu_user/static/description/banner.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Loading…
Cancel
Save