Ver código fonte

commit inicial

Rodney Enciso Arias 8 anos atrás
commit
15fe942295

+ 102 - 0
README.rst

@@ -0,0 +1,102 @@
+.. 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/open-synergy/opnsynid-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
+    - Click "More" button on the top
+    - Click "Copy User Access"
+    - Select the user on the selection
+    - Click "Copy"
+
+Use Case
+========
+"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
+        + Click "More" button on the top
+        + Click "Copy User Access"
+        + The wizard will show up and then fill the user with User-A
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+<https://github.com/open-synergy/opnsynid-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.
+
+
+Credits
+=======
+
+Contributors
+------------
+
+* Michael Viriyananda <viriyananda.michael@gmail.com>
+
+Maintainer
+----------
+
+.. image:: https://opensynergy-indonesia.com/logo.png
+   :alt: OpenSynergy Indonesia
+   :target: https://opensynergy-indonesia.com
+
+This module is maintained by the OpenSynergy Indonesia.

+ 5 - 0
__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 wizards

BIN
__init__.pyc


+ 16 - 0
__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",
+    'category': 'Generic Modules/Base',
+    'website': 'https://opensynergy-indonesia.com',
+    'depends': ['base'],
+    'data': ['wizards/base_copy_user_access.xml'],
+    'installable': True,
+    'license': 'AGPL-3',
+}

BIN
static/description/icon.png


+ 5 - 0
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

+ 58 - 0
tests/test_copy_user_access.py

@@ -0,0 +1,58 @@
+# -*- 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
+from lxml import etree
+
+
+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 lagi',
+            '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})
+
+        # Check fields_view_get
+        view = wizard.fields_view_get()
+
+        doc = etree.XML(view['arch'])
+        for node in doc.xpath("//field[@name='user_id']"):
+            domain = node.get('domain')
+            test_domain = "[('id', 'not in', " + str(user.ids) + ")]"
+            self.assertEquals(domain, test_domain)
+
+        # Check group_ids(new_user) with group_ids(demo_user)
+        wizard.with_context(ctx).copy_access_right()
+        self.assertEquals(set(self.demo_user.groups_id.ids),
+                          set(user.groups_id.ids))

+ 5 - 0
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 base_copy_user_access

BIN
wizards/__init__.pyc


+ 57 - 0
wizards/base_copy_user_access.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'}

BIN
wizards/base_copy_user_access.pyc


+ 43 - 0
wizards/base_copy_user_access.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record id="base_copy_user_access_view_form" 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="base_copy_user_access_action" 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="base_copy_user_access_view_form"/>
+            <field name="target">new</field>
+            <field name="multi">True</field>
+        </record>
+
+        <record id="base_copy_user_access_values" 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('base_copy_user_access_action'))" />
+            <field name="key">action</field>
+            <field name="model">res.users</field>
+        </record>
+        
+    </data>
+</openerp>