diff --git a/partner_password_reset/README.rst b/partner_password_reset/README.rst new file mode 100755 index 000000000..c17622086 --- /dev/null +++ b/partner_password_reset/README.rst @@ -0,0 +1,62 @@ +.. 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 + +====================== +Partner Password Reset +====================== + +This module provides a wizard that allows users to send a password reset +email from the Partner view. + +Configuration +============= + +None required + +Usage +===== + +To use this module, simply select "Send password reset email" under the partner +view. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/9.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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Ted Salmon + +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/partner_password_reset/__init__.py b/partner_password_reset/__init__.py new file mode 100755 index 000000000..56ffac1a3 --- /dev/null +++ b/partner_password_reset/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import wizard diff --git a/partner_password_reset/__openerp__.py b/partner_password_reset/__openerp__.py new file mode 100755 index 000000000..1c512c87c --- /dev/null +++ b/partner_password_reset/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Password Reset", + "summary": "Add Wizard to allow resetting of a Partner's associated user " + "password from within the partner view.", + "version": "9.0.1.0.0", + "category": "Customer Relationship Management", + "website": "https://laslabs.com/", + "author": "LasLabs, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + 'depends': [ + 'auth_signup', + 'portal', + ], + 'data': [ + 'wizard/res_partner_password_reset_wizard_view.xml', + ], +} diff --git a/partner_password_reset/tests/__init__.py b/partner_password_reset/tests/__init__.py new file mode 100644 index 000000000..1148301e2 --- /dev/null +++ b/partner_password_reset/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_res_partner_password_reset_wizard diff --git a/partner_password_reset/tests/test_res_partner_password_reset_wizard.py b/partner_password_reset/tests/test_res_partner_password_reset_wizard.py new file mode 100644 index 000000000..ade4fb907 --- /dev/null +++ b/partner_password_reset/tests/test_res_partner_password_reset_wizard.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from mock import MagicMock +from openerp.exceptions import Warning +from openerp.tests.common import TransactionCase + + +class TestResPartnerPasswordResetWizard(TransactionCase): + + def test_exception_no_users(self): + """ It should raise `Warning` when there are no associated users """ + wizard = self.env['res.partner.password.reset.wizard'].with_context( + active_ids=[] + ) + with self.assertRaises(Warning): + wizard.fields_view_get() + + def test_fields_view_get(self): + """ It should return the wizard correctly """ + partner = self.env.ref('portal.partner_demo_portal') + wizard = self.env['res.partner.password.reset.wizard'].with_context( + active_ids=partner.id + ) + output = wizard.fields_view_get() + self.assertEquals(output.get('name'), 'Send Password Reset Email') + self.assertEquals(type(output.get('fields').get('user_ids')), dict) + + def test_action_submit(self): + """ It should call user_ids.action_reset_password """ + self.env['res.users']._patch_method( + 'action_reset_password', MagicMock() + ) + partners = self.env.ref('portal.partner_demo_portal') + wizard = self.env['res.partner.password.reset.wizard'].with_context( + active_ids=partners.ids + ) + wizard.action_submit() + self.env['res.users'].action_reset_password.assert_called_once() diff --git a/partner_password_reset/wizard/__init__.py b/partner_password_reset/wizard/__init__.py new file mode 100644 index 000000000..3aa0416ea --- /dev/null +++ b/partner_password_reset/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_partner_password_reset_wizard diff --git a/partner_password_reset/wizard/res_partner_password_reset_wizard.py b/partner_password_reset/wizard/res_partner_password_reset_wizard.py new file mode 100644 index 000000000..47c7e8b99 --- /dev/null +++ b/partner_password_reset/wizard/res_partner_password_reset_wizard.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import _, api, exceptions, fields, models + + +class ResPartnerPasswordResetWizard(models.TransientModel): + _name = 'res.partner.password.reset.wizard' + + user_ids = fields.Many2many( + comodel_name='res.users', + default=lambda s: s._default_user_ids(), + required=True, + readonly=True, + ) + + @api.multi + def _default_user_ids(self): + """ Return a RecordSet of `res.users` associated to the active IDs """ + partner_ids = self.env['res.partner'].browse( + self.env.context.get('active_ids') + ) + return partner_ids.mapped('user_ids') + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, + submenu=False): + """ Override to check that there are associated users when called """ + res = super(ResPartnerPasswordResetWizard, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=False) + if not self._default_user_ids(): + raise exceptions.Warning( + _('The selected partners have no associated portal users') + ) + return res + + @api.multi + def action_submit(self): + """ Reset the user passwords on submission """ + self.mapped('user_ids').action_reset_password() diff --git a/partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml b/partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml new file mode 100644 index 000000000..aaaf124e3 --- /dev/null +++ b/partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml @@ -0,0 +1,42 @@ + + + + + + + Send Password Reset Email + res.partner.password.reset.wizard + +
+

Are you sure you want to reset the password for + the following Users?

+ + + + + + +
+
+
+
+
+ + + +