diff --git a/mail_restrict_follower_selection/README.rst b/mail_restrict_follower_selection/README.rst new file mode 100644 index 0000000..5a633d5 --- /dev/null +++ b/mail_restrict_follower_selection/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 +Restrict follower selection +=========================== + +This module was written to allow you to restrict the selection of possible followers. For example, if you use the social ERP functions only internally, it makes sense to filter possible followers for being employees. Otherwise, you'll get a quite crowded list of partners to choose from. + +Configuration +============= + +To configure this module, you need to go to `System parameters` and adjust `mail_restrict_follower_selection.domain` as you see fit. This restricts followers globally, if you want to restrict only the followers for a certain record type (or have different restrictions for different record types), create a parameter `mail_restrict_follower_selection.domain.$your_model`. + +As an example, you could use `[('customer', '=', True)]` to allow only customers to be added as follower. + +Note: This module won't change existing followers! + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/205/8.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +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 smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +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 http://odoo-community.org. diff --git a/mail_restrict_follower_selection/__init__.py b/mail_restrict_follower_selection/__init__.py new file mode 100644 index 0000000..cdb7d73 --- /dev/null +++ b/mail_restrict_follower_selection/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import models diff --git a/mail_restrict_follower_selection/__openerp__.py b/mail_restrict_follower_selection/__openerp__.py new file mode 100644 index 0000000..9d24261 --- /dev/null +++ b/mail_restrict_follower_selection/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Restrict follower selection", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Social Network", + "summary": "Define a domain from which followers can be selected", + "depends": [ + 'mail', + ], + "data": [ + "data/ir_config_parameter.xml", + "data/ir_actions.xml", + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/mail_restrict_follower_selection/data/ir_actions.xml b/mail_restrict_follower_selection/data/ir_actions.xml new file mode 100644 index 0000000..0b08598 --- /dev/null +++ b/mail_restrict_follower_selection/data/ir_actions.xml @@ -0,0 +1,15 @@ + + + + + + + + + Configure the restriction on followers + automatic + + + + diff --git a/mail_restrict_follower_selection/data/ir_config_parameter.xml b/mail_restrict_follower_selection/data/ir_config_parameter.xml new file mode 100644 index 0000000..25c093c --- /dev/null +++ b/mail_restrict_follower_selection/data/ir_config_parameter.xml @@ -0,0 +1,9 @@ + + + + + mail_restrict_follower_selection.domain + [('employee', '=', True)] + + + diff --git a/mail_restrict_follower_selection/models/__init__.py b/mail_restrict_follower_selection/models/__init__.py new file mode 100644 index 0000000..cc7bb9c --- /dev/null +++ b/mail_restrict_follower_selection/models/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import mail_wizard_invite diff --git a/mail_restrict_follower_selection/models/mail_wizard_invite.py b/mail_restrict_follower_selection/models/mail_wizard_invite.py new file mode 100644 index 0000000..5d0e7ee --- /dev/null +++ b/mail_restrict_follower_selection/models/mail_wizard_invite.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from lxml import etree +from openerp import models, api + + +class MailWizardInvite(models.TransientModel): + _inherit = 'mail.wizard.invite' + + @api.model + def _mail_restrict_follower_selection_get_domain(self): + parameter_name = 'mail_restrict_follower_selection.domain' + return self.env['ir.config_parameter'].get_param( + '%s.%s' % (parameter_name, + self.env.context.get('default_res_model')), + self.env['ir.config_parameter'].get_param( + parameter_name, default='[]') + ) + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, + submenu=False): + result = super(MailWizardInvite, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=submenu) + arch = etree.fromstring(result['arch']) + for field in arch.xpath('//field[@name="partner_ids"]'): + field.attrib['domain'] = self\ + ._mail_restrict_follower_selection_get_domain() + result['arch'] = etree.tostring(arch) + return result diff --git a/mail_restrict_follower_selection/static/description/icon.png b/mail_restrict_follower_selection/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/mail_restrict_follower_selection/static/description/icon.png differ diff --git a/mail_restrict_follower_selection/tests/__init__.py b/mail_restrict_follower_selection/tests/__init__.py new file mode 100644 index 0000000..6d2a768 --- /dev/null +++ b/mail_restrict_follower_selection/tests/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_mail_restrict_follower_selection diff --git a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py new file mode 100644 index 0000000..b89567e --- /dev/null +++ b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from lxml import etree +from openerp.tests.common import TransactionCase + + +class TestMailRestrictFollowerSelection(TransactionCase): + def test_fields_view_get(self): + result = self.env['mail.wizard.invite'].fields_view_get( + view_type='form') + for field in etree.fromstring(result['arch']).xpath( + '//field[@name="partner_ids"]'): + self.assertTrue(field.get('domain'))