From b797015c0eecc3838481dad04c1e507d45470a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20V=C3=A9zina?= Date: Wed, 28 Jun 2023 13:08:12 -0400 Subject: [PATCH] User Password Bundle automation --- bemade_user_password_bundle/__init__.py | 3 + bemade_user_password_bundle/__manifest__.py | 25 ++++++++ .../models/__init__.py | 4 ++ .../models/password_bundle.py | 30 ++++++++++ .../models/res_users.py | 23 +++++++ .../views/templates.xml | 24 ++++++++ bemade_user_password_bundle/views/views.xml | 60 +++++++++++++++++++ 7 files changed, 169 insertions(+) create mode 100644 bemade_user_password_bundle/__init__.py create mode 100644 bemade_user_password_bundle/__manifest__.py create mode 100644 bemade_user_password_bundle/models/__init__.py create mode 100644 bemade_user_password_bundle/models/password_bundle.py create mode 100644 bemade_user_password_bundle/models/res_users.py create mode 100644 bemade_user_password_bundle/views/templates.xml create mode 100644 bemade_user_password_bundle/views/views.xml diff --git a/bemade_user_password_bundle/__init__.py b/bemade_user_password_bundle/__init__.py new file mode 100644 index 0000000..5305644 --- /dev/null +++ b/bemade_user_password_bundle/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/bemade_user_password_bundle/__manifest__.py b/bemade_user_password_bundle/__manifest__.py new file mode 100644 index 0000000..893ccf6 --- /dev/null +++ b/bemade_user_password_bundle/__manifest__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +{ + 'name': "User Password Bundle", + + 'summary': """ + Module to create password bundles and provide access to them for admins of a newly created user. + """, + + 'description': """ + This module automate the creation of a password bundle for new users in Odoo 15 and changes the default admin + ownership of bundle to admin/setting group instead of the bundle creator. + """, + + 'author': "Bemade", + 'website': "https://www.bemade.org", + 'category': 'Technical', + 'version': '0.1', + 'license': 'AGPL-3', + 'depends': ['odoo_password_manager'], + + 'data': [ + ], + 'demo': [ + ], +} diff --git a/bemade_user_password_bundle/models/__init__.py b/bemade_user_password_bundle/models/__init__.py new file mode 100644 index 0000000..135d7d2 --- /dev/null +++ b/bemade_user_password_bundle/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import res_users +from . import password_bundle diff --git a/bemade_user_password_bundle/models/password_bundle.py b/bemade_user_password_bundle/models/password_bundle.py new file mode 100644 index 0000000..7a93cd2 --- /dev/null +++ b/bemade_user_password_bundle/models/password_bundle.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api + + +class password_bundle(models.Model): + _inherit = 'password.bundle' + _name = 'password.bundle' + + @api.model + def _default_access_admin_ids(self): + """ + Default method for access_ids + """ + values = { + 'access_level': 'admin', + 'group_id': self.env.ref('base.group_system').id, + } + return [(0, 0, values)] + + # BV: UGLY HACK + # I should be able to remove this field, but I can't just override the default function + # _default_access_ids, so I rename it _default_access_admin_ids and override the th field + + access_ids = fields.One2many( + "password.access", + "bundle_id", + default=_default_access_admin_ids, + ) + diff --git a/bemade_user_password_bundle/models/res_users.py b/bemade_user_password_bundle/models/res_users.py new file mode 100644 index 0000000..fe3c5dc --- /dev/null +++ b/bemade_user_password_bundle/models/res_users.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api + + +class ResUsers(models.Model): + _inherit = 'res.users' + + @api.model + def create(self, vals): + newuser = super(ResUsers, self).create(vals) + if vals.get("sel_groups_1_9_10", 9) == 1: + pw_bundle = self.env['password.bundle'].create({ + 'name': newuser.name, + }) + self.env['password.access'].create({ + 'bundle_id': pw_bundle.id, + 'user_id': newuser.id, + 'access_level': 'full' + }) + + return newuser + diff --git a/bemade_user_password_bundle/views/templates.xml b/bemade_user_password_bundle/views/templates.xml new file mode 100644 index 0000000..cea6b39 --- /dev/null +++ b/bemade_user_password_bundle/views/templates.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/bemade_user_password_bundle/views/views.xml b/bemade_user_password_bundle/views/views.xml new file mode 100644 index 0000000..3c24c24 --- /dev/null +++ b/bemade_user_password_bundle/views/views.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file