Browse Source

[RFR] Expose as a user preference

pull/321/head
Stefan Rijnhart 9 years ago
parent
commit
9dfde4d687
  1. 19
      base_technical_features/README.rst
  2. 8
      base_technical_features/__openerp__.py
  3. 6
      base_technical_features/data/res_users.xml
  4. 25
      base_technical_features/i18n/nl.po
  5. 1
      base_technical_features/models/__init__.py
  6. 2
      base_technical_features/models/basemodel_monkeypatch.py
  7. 4
      base_technical_features/models/ir_ui_menu.py
  8. 59
      base_technical_features/models/res_users.py
  9. 1
      base_technical_features/security/res_groups.xml
  10. BIN
      base_technical_features/static/description/user_preferences.png
  11. 36
      base_technical_features/tests/test_base_technical_features.py
  12. 16
      base_technical_features/views/res_users.xml

19
base_technical_features/README.rst

@ -8,17 +8,26 @@ Access to technical features without activating debug mode
In Odoo 9.0, the debug mode grants every employee user access to the technical In Odoo 9.0, the debug mode grants every employee user access to the technical
features. This module enables persistent access to technical features based on features. This module enables persistent access to technical features based on
group access.
user preference.
Configuration Configuration
============= =============
After installation of this module, every employee can still access technical After installation of this module, every employee can still access technical
features for the applications that they have access to by enabling debug mode. features for the applications that they have access to by enabling debug mode.
Additionally, users can be assigned the *Technical feature (w/o debug mode)*
access right on their user form which will enable technical features at any
time. As an Odoo administrator, you might want to review who to grant this
access to.
Additionally, users can check the *Technical feature* field in their
preferences to gain permanent access to the menus and views that fall under
this category.
.. figure:: static/description/user_preferences.png
:alt: User preferences
Upon installation of this module, this preference is already
set for the administrator user of the database.
In the background, this preference is mapped to the *Technical feature (w/o
debug mode)* group that this module adds. As an administrator, you can
therefore manage this preference from the regular Users and Groups menu items.
Usage Usage
===== =====

8
base_technical_features/__openerp__.py

@ -1,15 +1,17 @@
# -*- coding: utf-8 -*-
# © 2016 Opener B.V.
# coding: utf-8
# © 2016 Opener B.V. (<https://opener.am>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Technical features group", "name": "Technical features group",
"summary": "Access to technical features without activating debug mode", "summary": "Access to technical features without activating debug mode",
"version": "9.0.1.0.0", "version": "9.0.1.0.0",
"category": "Usability", "category": "Usability",
"website": "https://odoo-community.org/",
"website": "https://github.com/oca/server-tools",
"author": "Opener B.V., Odoo Community Association (OCA)", "author": "Opener B.V., Odoo Community Association (OCA)",
"data": [ "data": [
'security/res_groups.xml', 'security/res_groups.xml',
'views/res_users.xml',
'data/res_users.xml',
], ],
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,

6
base_technical_features/data/res_users.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="res.users" id="base.user_root">
<field name="technical_features" eval="True" />
</record>
</odoo>

25
base_technical_features/i18n/nl.po

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n" "Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-01 17:57+0000\n"
"PO-Revision-Date: 2016-01-01 17:57+0000\n"
"POT-Creation-Date: 2016-01-03 16:11+0000\n"
"PO-Revision-Date: 2016-01-03 16:11+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -15,7 +15,28 @@ msgstr ""
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: base_technical_features
#: model:ir.model.fields,field_description:base_technical_features.field_res_users_show_technical_features
msgid "Show field Technical Features"
msgstr "Toon veld Technische mogelijkheden"
#. module: base_technical_features #. module: base_technical_features
#: model:res.groups,name:base_technical_features.group_technical_features #: model:res.groups,name:base_technical_features.group_technical_features
msgid "Technical Features (w/o debug mode)" msgid "Technical Features (w/o debug mode)"
msgstr "Technische mogelijkheden (zonder debugmodus)" msgstr "Technische mogelijkheden (zonder debugmodus)"
#. module: base_technical_features
#: model:ir.model.fields,field_description:base_technical_features.field_res_users_technical_features
msgid "Technical features"
msgstr "Technische mogelijkheden"
#. module: base_technical_features
#: code:addons/base_technical_features/models/res_users.py:45
#, python-format
msgid "The user does not have access to technical features."
msgstr "De gebruiker heeft geen toegang tot technische mogelijkheden."
#. module: base_technical_features
#: model:ir.model.fields,help:base_technical_features.field_res_users_show_technical_features
msgid "Whether to display the technical features field in the user preferences."
msgstr "Geeft aan of het veld Technische mogelijkheden wordt getoond in de voorkeuren van de gebruiker."

1
base_technical_features/models/__init__.py

@ -1,2 +1,3 @@
from . import basemodel_monkeypatch from . import basemodel_monkeypatch
from . import ir_ui_menu from . import ir_ui_menu
from . import res_users

2
base_technical_features/models/basemodel_monkeypatch.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Opener B.V. (<https://opener.am>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api from openerp import models, api

4
base_technical_features/models/ir_ui_menu.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# coding: utf-8
# © 2016 Opener B.V. (<https://opener.am>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, models from openerp import api, models

59
base_technical_features/models/res_users.py

@ -0,0 +1,59 @@
# coding: utf-8
# © 2016 Opener B.V. (<https://opener.am>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
from openerp.exceptions import AccessError
from openerp.tools.translate import _
class ResUsers(models.Model):
_inherit = 'res.users'
technical_features = fields.Boolean(
compute='get_technical_features',
inverse='set_technical_features')
show_technical_features = fields.Boolean(
string='Show field Technical Features',
compute='get_show_technical_features',
help=('Whether to display the technical features field in the user '
'preferences.'))
@api.multi
@api.depends('groups_id')
def get_show_technical_features(self):
""" Only display the technical features checkbox in the user
preferences if the user has access to them """
users = self.env.ref('base.group_no_one').users
for user in self:
user.show_technical_features = user in users
@api.multi
@api.depends('groups_id')
def get_technical_features(self):
""" Map user membership to boolean field value """
users = self.env.ref(
'base_technical_features.group_technical_features').users
for user in self:
user.technical_features = user in users
@api.multi
def set_technical_features(self):
""" Map boolean field value to group membership, but checking
access """
group = self.env.ref(
'base_technical_features.group_technical_features')
for user in self:
if self.env.ref('base.group_no_one') not in user.groups_id:
raise AccessError(
_('The user does not have access to technical '
'features.'))
if user.technical_features:
self.sudo().write({'groups_id': [(4, group.id)]})
else:
self.sudo().write({'groups_id': [(3, group.id)]})
def __init__(self, pool, cr):
super(ResUsers, self).__init__(pool, cr)
self.SELF_READABLE_FIELDS += [
'technical_features', 'show_technical_features']
self.SELF_WRITEABLE_FIELDS.append('technical_features')

1
base_technical_features/security/res_groups.xml

@ -3,6 +3,5 @@
<record model="res.groups" id="group_technical_features"> <record model="res.groups" id="group_technical_features">
<field name="name">Technical Features (w/o debug mode)</field> <field name="name">Technical Features (w/o debug mode)</field>
<field name="implied_ids" eval="[(4, ref('base.group_no_one'))]" /> <field name="implied_ids" eval="[(4, ref('base.group_no_one'))]" />
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record> </record>
</odoo> </odoo>

BIN
base_technical_features/static/description/user_preferences.png

After

Width: 594  |  Height: 357  |  Size: 30 KiB

36
base_technical_features/tests/test_base_technical_features.py

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import api
from openerp.exceptions import AccessError
from openerp.tests import common from openerp.tests import common
from lxml import etree from lxml import etree
@ -13,11 +15,9 @@ class TestBaseTechnicalFeatures(common.TransactionCase):
menu_id = menu_obj.search( menu_id = menu_obj.search(
[('groups_id', '=', self.env.ref('base.group_no_one').id)], [('groups_id', '=', self.env.ref('base.group_no_one').id)],
limit=1).id limit=1).id
self.env.user.groups_id -= self.env.ref(
'base_technical_features.group_technical_features')
self.env.user.write({'technical_features': False})
self.assertNotIn(menu_id, menu_obj._visible_menu_ids()) self.assertNotIn(menu_id, menu_obj._visible_menu_ids())
self.env.user.groups_id += self.env.ref(
'base_technical_features.group_technical_features')
self.env.user.write({'technical_features': True})
self.assertIn(menu_id, menu_obj._visible_menu_ids()) self.assertIn(menu_id, menu_obj._visible_menu_ids())
def test02_visible_fields(self): def test02_visible_fields(self):
@ -33,9 +33,29 @@ class TestBaseTechnicalFeatures(common.TransactionCase):
'//div/group/field[@name="partner_id"]')[0].get('invisible') '//div/group/field[@name="partner_id"]')[0].get('invisible')
self.env['basemodel.monkeypatch']._register_hook() self.env['basemodel.monkeypatch']._register_hook()
self.env.user.groups_id -= self.env.ref(
'base_technical_features.group_technical_features')
self.env.user.write({'technical_features': False})
self.assertEqual(get_partner_field_invisible(), '1') self.assertEqual(get_partner_field_invisible(), '1')
self.env.user.write({'groups_id': [(4, self.env.ref(
'base_technical_features.group_technical_features').id)]})
self.env.user.write({'technical_features': True})
self.assertEqual(get_partner_field_invisible(), None) self.assertEqual(get_partner_field_invisible(), None)
def test03_user_access(self):
""" Setting the user pref raises an access error if the user is not \
in group_no_one """
user = self.env['res.users'].create({
'name': 'Test user technical features',
'login': 'testusertechnicalfeatures',
'groups_id': [(6, 0, [])]})
with api.Environment.manage():
env = api.Environment(
self.env.cr, user.id, self.env.context)
with self.assertRaises(AccessError):
env['res.users'].browse(user.id).write(
{'technical_features': True})
with self.assertRaises(AccessError):
user.write({'technical_features': True})
user.write({'groups_id': [(4, self.env.ref('base.group_no_one').id)]})
with api.Environment.manage():
env = api.Environment(
self.env.cr, user.id, self.env.context)
env['res.users'].browse(user.id).write({
'technical_features': True})

16
base_technical_features/views/res_users.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_users_form_simple_modif" model="ir.ui.view">
<field name="name">Add technical features checkbox to user preferences form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="technical_features" readonly="0"
attrs="{'invisible': [('show_technical_features', '=', False)]}" />
<field name="show_technical_features" invisible="1" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save