Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions base_copy_user_access/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/server-tools/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
<https://github.com/OCA/
server-tools/issues/new?body=module:%20
base_copy_user_access%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Michael Viriyananda <viriyananda.michael@gmail.com>

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.
6 changes: 6 additions & 0 deletions base_copy_user_access/__init__.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions base_copy_user_access/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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',
}
Binary file added base_copy_user_access/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions base_copy_user_access/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions base_copy_user_access/tests/test_copy_user_access.py
Original file line number Diff line number Diff line change
@@ -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))
5 changes: 5 additions & 0 deletions base_copy_user_access/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions base_copy_user_access/wizards/wizard_base_copyUserAccess.py
Original file line number Diff line number Diff line change
@@ -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'}
43 changes: 43 additions & 0 deletions base_copy_user_access/wizards/wizard_base_copyUserAccess.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="form_base_wizardCopyUserAccess" model="ir.ui.view">
<field name="name">Copy User Access</field>
<field name="model">base.copy_user_access</field>
<field name="arch" type="xml">
<form string="Copy Access Right From User">
<group col="4">
<field name="user_id" required="True" />
</group>
<footer>
<button name="copy_access_right" string="Copy" type="object" class="oe_highlight"/>
Or
<button special="cancel" string="_Cancel" class="oe_link"/>
</footer>
</form>
</field>
</record>

<record id="action_base_wizardCopyUserAccess" model="ir.actions.act_window">
<field name="name">Copy User Access</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.copy_user_access</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="form_base_wizardCopyUserAccess"/>
<field name="target">new</field>
<field name="multi">True</field>
</record>

<record id="waction_base_wizardCopyUserAccess" model="ir.values">
<field name="model_id" ref="base.model_res_users" />
<field name="name">Copy User Access</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_base_wizardCopyUserAccess'))" />
<field name="key">action</field>
<field name="model">res.users</field>
</record>

</data>
</openerp>