diff --git a/base_copy_user_access/README.rst b/base_copy_user_access/README.rst new file mode 100644 index 00000000000..0043b06e72e --- /dev/null +++ b/base_copy_user_access/README.rst @@ -0,0 +1,118 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================== +Base Copy User Access +===================== + +This Module allows the administrator to copy user access from one user to many users. + +This Module created a wizard that can be access on "More" button in Settings > Users > Users. + +Installation +============ + +To install this module, you need to: + +1. Clone the branch 8.0 of the repository https://github.com/OCA/server-tools +2. Add the path to this repository in your configuration (addons-path) +3. Update the module list +4. Go to menu *Setting -> Modules -> Local Modules* +5. Search For *Base Copy User Access* +6. Install the module + +Usage +===== + +To use this module, you need to: + - Go to menu Settings > Users > Users + - Select Users on the list of tree view + - Klik "More" button on the top + - Klik "Copy User Access" + - Select the user on the selection + - Klik "Copy" + +Case of study: +"User-A" is a users who have access as manager sales and accounting. +Administrator asked to make another two users who has the right equal access with User-A. +The two new users was named "User-B" and "User-C" + +So administrator have to do: + +- Without module Base Copy User Access is installed: + * Check user access of User-A + + Go to menu Settings > Users > Users + + Find the User-A and opened it + * Create a new User and named it User-B + + Go to menu Settings > Users > Users + + Create the User-B + * Set up the access of User-B that has the right equal access with User-A + + Go to menu Settings > Users > Users + + Find the User-B and opened it + + Fill user access of User-B according with user access of User-A + * Create a new User and named it User-C + + Go to menu Settings > Users > Users + + Create the User-C + * Set up the access of User-C that has the right equal access with User-A + + Go to menu Settings > Users > Users + + Find the User-C and opened it + + Fill user access of User-C according with user access of User-A + +- With module Base Copy User Access is installed: + * Create a new User and named it User-B + + Go to menu Settings > Users > Users + + Create the User-B + * Create a new User and named it User-C + + Go to menu Settings > Users > Users + + Create the User-C + * Copy user access of User-A to User-B and User-C + + Go to menu Settings > Users > Users + + Select User-A and User-B on the list of tree view + + Klik "More" button on the top + + Klik "Copy User Access" + + The wizard will show up and then fill the user with User-A + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Michael Viriyananda + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/base_copy_user_access/__init__.py b/base_copy_user_access/__init__.py new file mode 100644 index 00000000000..90275526840 --- /dev/null +++ b/base_copy_user_access/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import wizards +from . import tests diff --git a/base_copy_user_access/__openerp__.py b/base_copy_user_access/__openerp__.py new file mode 100644 index 00000000000..6363fac05d4 --- /dev/null +++ b/base_copy_user_access/__openerp__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Base Copy User Access', + 'version': '8.0.1.0.0', + 'summary': 'Copy access right from another user', + 'author': 'OpenSynergy Indonesia,Odoo Community Association (OCA)', + 'category': 'Generic Modules/Base', + 'website': 'https://opensynergy-indonesia.com', + 'depends': ['base'], + 'data': ['wizards/wizard_base_copyUserAccess.xml'], + 'installable': True, + 'license': 'AGPL-3', +} diff --git a/base_copy_user_access/static/description/icon.png b/base_copy_user_access/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/base_copy_user_access/static/description/icon.png differ diff --git a/base_copy_user_access/tests/__init__.py b/base_copy_user_access/tests/__init__.py new file mode 100644 index 00000000000..2d1b9c55508 --- /dev/null +++ b/base_copy_user_access/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_copy_user_access diff --git a/base_copy_user_access/tests/test_copy_user_access.py b/base_copy_user_access/tests/test_copy_user_access.py new file mode 100644 index 00000000000..662616a866a --- /dev/null +++ b/base_copy_user_access/tests/test_copy_user_access.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class TestCopyUserAccess(TransactionCase): + + def setUp(self, *args, **kwargs): + super(TestCopyUserAccess, self).setUp(*args, **kwargs) + + # Objects + self.obj_res_users = self.env['res.users'] + self.obj_wizard = self.env['base.copy_user_access'] + + # Data + self.demo_user = self.env.ref('base.user_demo') + + def _prepare_user_data(self): + data = { + 'login': 'test_user@test.com', + 'name': 'test user', + 'password': 'a' + } + + return data + + def test_copy_user_access(self): + # Create New User + data = self._prepare_user_data() + user = self.obj_res_users.create(data) + # Check create new user + self.assertIsNotNone(user) + + # Fill Context + context = self.obj_res_users.context_get() + ctx = context.copy() + ctx.update({'active_ids': user.ids}) + + # Create Wizard + wizard = self.obj_wizard\ + .with_context(ctx).create({'user_id': self.demo_user.id}) + wizard.with_context(ctx).copy_access_right() + + # Check group_ids(new_user) with group_ids(demo_user) + self.assertEquals(set(self.demo_user.groups_id.ids), + set(user.groups_id.ids)) diff --git a/base_copy_user_access/wizards/__init__.py b/base_copy_user_access/wizards/__init__.py new file mode 100644 index 00000000000..240157cd503 --- /dev/null +++ b/base_copy_user_access/wizards/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import wizard_base_copyUserAccess diff --git a/base_copy_user_access/wizards/wizard_base_copyUserAccess.py b/base_copy_user_access/wizards/wizard_base_copyUserAccess.py new file mode 100644 index 00000000000..b2663bafdfc --- /dev/null +++ b/base_copy_user_access/wizards/wizard_base_copyUserAccess.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api +from lxml import etree + + +class WizardBaseCopyUserAccess(models.TransientModel): + _name = 'base.copy_user_access' + _description = 'Wizard Copy User Access' + + user_id = fields.Many2one( + string='User', + comodel_name='res.users', + required=True + ) + + @api.model + def fields_view_get( + self, view_id=None, view_type='form', toolbar=False, submenu=False + ): + res = super(WizardBaseCopyUserAccess, self).fields_view_get( + view_id=view_id, view_type=view_type, + toolbar=toolbar, submenu=submenu) + doc = etree.XML(res['arch']) + for node in doc.xpath("//field[@name='user_id']"): + active_ids = self._context.get('active_ids') + domain = "[('id', 'not in', " + str(active_ids) + ")]" + node.set('domain', domain) + res['arch'] = etree.tostring(doc) + return res + + @api.multi + def copy_access_right(self): + res = [] + self.ensure_one() + + obj_user = self.env['res.users'] + + context = self._context + record_id = context['active_ids'] + + user = obj_user.browse(self.user_id.id) + + for group in user.groups_id: + res.append(group.id) + + for data in record_id: + user_id = obj_user.browse(data) + vals = { + 'groups_id': [(6, 0, res)], + } + + user_id.write(vals) + + return {'type': 'ir.actions.act_window_close'} diff --git a/base_copy_user_access/wizards/wizard_base_copyUserAccess.xml b/base_copy_user_access/wizards/wizard_base_copyUserAccess.xml new file mode 100644 index 00000000000..bbd4129ed95 --- /dev/null +++ b/base_copy_user_access/wizards/wizard_base_copyUserAccess.xml @@ -0,0 +1,43 @@ + + + + + + Copy User Access + base.copy_user_access + +
+ + + +
+
+
+
+
+ + + Copy User Access + ir.actions.act_window + base.copy_user_access + form + form + + new + True + + + + + Copy User Access + client_action_multi + + action + res.users + + +
+