From bda50f100ed0c1b88a4c81363efb89087b4e1ad1 Mon Sep 17 00:00:00 2001 From: Ted Salmon Date: Wed, 3 May 2017 14:34:34 -0700 Subject: [PATCH] [IMP] partner_password_reset: Convert to Wizard * Convert functionality from action to wizard * Update tests --- partner_password_reset/README.rst | 4 +- partner_password_reset/__init__.py | 2 +- partner_password_reset/__manifest__.py | 5 ++- partner_password_reset/models/res_partner.py | 13 ------ partner_password_reset/tests/__init__.py | 2 +- .../tests/test_res_partner.py | 23 ---------- .../test_res_partner_password_reset_wizard.py | 30 +++++++++++++ .../views/res_partner_view.xml | 20 --------- .../{models => wizard}/__init__.py | 2 +- .../res_partner_password_reset_wizard.py | 43 +++++++++++++++++++ ...res_partner_password_reset_wizard_view.xml | 42 ++++++++++++++++++ 11 files changed, 123 insertions(+), 63 deletions(-) mode change 100755 => 100644 partner_password_reset/README.rst mode change 100755 => 100644 partner_password_reset/__init__.py mode change 100755 => 100644 partner_password_reset/__manifest__.py delete mode 100644 partner_password_reset/models/res_partner.py delete mode 100644 partner_password_reset/tests/test_res_partner.py create mode 100644 partner_password_reset/tests/test_res_partner_password_reset_wizard.py delete mode 100644 partner_password_reset/views/res_partner_view.xml rename partner_password_reset/{models => wizard}/__init__.py (72%) create mode 100644 partner_password_reset/wizard/res_partner_password_reset_wizard.py create mode 100644 partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml diff --git a/partner_password_reset/README.rst b/partner_password_reset/README.rst old mode 100755 new mode 100644 index 17d185e41..e619c1a41 --- a/partner_password_reset/README.rst +++ b/partner_password_reset/README.rst @@ -6,8 +6,8 @@ Partner Password Reset ====================== -This module provides an action that allows users to send a password reset -email from the Partner view. +This module provides a wizard that allows users to send a password reset email +from the Partner view. Configuration ============= diff --git a/partner_password_reset/__init__.py b/partner_password_reset/__init__.py old mode 100755 new mode 100644 index 44db863b6..56ffac1a3 --- a/partner_password_reset/__init__.py +++ b/partner_password_reset/__init__.py @@ -2,4 +2,4 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import models +from . import wizard diff --git a/partner_password_reset/__manifest__.py b/partner_password_reset/__manifest__.py old mode 100755 new mode 100644 index 3577a6985..b5e1eb7f2 --- a/partner_password_reset/__manifest__.py +++ b/partner_password_reset/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Partner Password Reset", - "summary": "Add Action to allow resetting of a Partner's associated user " + "summary": "Add Wizard to allow resetting of a Partner's associated user " "password from within the partner view.", "version": "10.0.1.0.0", "category": "Customer Relationship Management", @@ -15,8 +15,9 @@ "installable": True, 'depends': [ 'auth_signup', + 'portal', ], 'data': [ - 'views/res_partner_view.xml', + 'wizard/res_partner_password_reset_wizard_view.xml', ], } diff --git a/partner_password_reset/models/res_partner.py b/partner_password_reset/models/res_partner.py deleted file mode 100644 index 8036203bb..000000000 --- a/partner_password_reset/models/res_partner.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import api, models - - -class ResPartner(models.Model): - _inherit = 'res.partner' - - @api.multi - def action_reset_user_password(self): - self.mapped('user_ids').action_reset_password() diff --git a/partner_password_reset/tests/__init__.py b/partner_password_reset/tests/__init__.py index 5e00c31a7..1148301e2 100644 --- a/partner_password_reset/tests/__init__.py +++ b/partner_password_reset/tests/__init__.py @@ -2,4 +2,4 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import test_res_partner +from . import test_res_partner_password_reset_wizard diff --git a/partner_password_reset/tests/test_res_partner.py b/partner_password_reset/tests/test_res_partner.py deleted file mode 100644 index b473cfa2b..000000000 --- a/partner_password_reset/tests/test_res_partner.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- 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 odoo.tests.common import TransactionCase - - -class TestResPartner(TransactionCase): - - def setUp(self): - super(TestResPartner, self).setUp() - self.partner = self.env['res.partner'].search([ - ('user_ids', '!=', ''), - ], limit=1) - - def test_action_reset_user_password(self): - """ It should call user_ids.action_reset_password """ - self.env['res.users']._patch_method( - 'action_reset_password', MagicMock() - ) - self.partner.action_reset_user_password() - self.env['res.users'].action_reset_password.assert_called_once() 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..25bb71d2e --- /dev/null +++ b/partner_password_reset/tests/test_res_partner_password_reset_wizard.py @@ -0,0 +1,30 @@ +# -*- 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_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/views/res_partner_view.xml b/partner_password_reset/views/res_partner_view.xml deleted file mode 100644 index 057480ef7..000000000 --- a/partner_password_reset/views/res_partner_view.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Partner Reset User Password - res.partner - - - -
-
-
-
-
- -
diff --git a/partner_password_reset/models/__init__.py b/partner_password_reset/wizard/__init__.py similarity index 72% rename from partner_password_reset/models/__init__.py rename to partner_password_reset/wizard/__init__.py index 6cc445b5a..3aa0416ea 100644 --- a/partner_password_reset/models/__init__.py +++ b/partner_password_reset/wizard/__init__.py @@ -2,4 +2,4 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import res_partner +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..939036298 --- /dev/null +++ b/partner_password_reset/wizard/res_partner_password_reset_wizard.py @@ -0,0 +1,43 @@ +# -*- 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 """ + for rec in self: + rec.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?

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