From fa6466efb251e09902a24706af5e8e196d56a067 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Mon, 14 Nov 2022 11:26:38 +0100 Subject: [PATCH] [Add] microsoft_outlook_single_tenant --- microsoft_outlook_single_tenant/README.rst | 88 ++++ microsoft_outlook_single_tenant/__init__.py | 1 + .../__manifest__.py | 15 + .../models/__init__.py | 2 + .../models/microsoft_outlook_mixin.py | 18 + .../models/res_config_settings.py | 14 + .../readme/CONFIGURE.rst | 7 + .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 436 ++++++++++++++++++ .../tests/__init__.py | 4 + .../tests/test_fetchmail_outlook.py | 56 +++ .../views/res_config_settings_views.xml | 25 + 13 files changed, 672 insertions(+) create mode 100644 microsoft_outlook_single_tenant/README.rst create mode 100644 microsoft_outlook_single_tenant/__init__.py create mode 100644 microsoft_outlook_single_tenant/__manifest__.py create mode 100644 microsoft_outlook_single_tenant/models/__init__.py create mode 100644 microsoft_outlook_single_tenant/models/microsoft_outlook_mixin.py create mode 100644 microsoft_outlook_single_tenant/models/res_config_settings.py create mode 100644 microsoft_outlook_single_tenant/readme/CONFIGURE.rst create mode 100644 microsoft_outlook_single_tenant/readme/CONTRIBUTORS.rst create mode 100644 microsoft_outlook_single_tenant/readme/DESCRIPTION.rst create mode 100644 microsoft_outlook_single_tenant/static/description/index.html create mode 100644 microsoft_outlook_single_tenant/tests/__init__.py create mode 100644 microsoft_outlook_single_tenant/tests/test_fetchmail_outlook.py create mode 100644 microsoft_outlook_single_tenant/views/res_config_settings_views.xml diff --git a/microsoft_outlook_single_tenant/README.rst b/microsoft_outlook_single_tenant/README.rst new file mode 100644 index 0000000..58171a7 --- /dev/null +++ b/microsoft_outlook_single_tenant/README.rst @@ -0,0 +1,88 @@ +=============================== +Microsoft Outlook Single Tenant +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/14.0/microsoft_outlook_single_tenant + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-microsoft_outlook_single_tenant + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +By default Odoo only supports multi-tenant apps authentication on Azure. +This module alows you configure Odoo as a single-tenant app. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +* Register a new application on azure +* Set who can use this application or access this API as single-tenant +* Set Outlook credentials Client ID and Client Secret in Settings +* Set a ir_config_parameter like that: + +[ir.config_parameter] +microsoft_outlook_directory_tenant_id = Directory (tenant) ID + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp SA `_: + + * Anna Janiszewska + * Telmo dos Santos + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/microsoft_outlook_single_tenant/__init__.py b/microsoft_outlook_single_tenant/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/microsoft_outlook_single_tenant/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/microsoft_outlook_single_tenant/__manifest__.py b/microsoft_outlook_single_tenant/__manifest__.py new file mode 100644 index 0000000..9912c1e --- /dev/null +++ b/microsoft_outlook_single_tenant/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +{ + "name": "Microsoft Outlook Single Tenant", + "version": "14.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Hidden", + "website": "https://github.com/OCA/social", + "depends": [ + "microsoft_outlook", + ], + "data": ["views/res_config_settings_views.xml"], + "installable": True, +} diff --git a/microsoft_outlook_single_tenant/models/__init__.py b/microsoft_outlook_single_tenant/models/__init__.py new file mode 100644 index 0000000..6822d6f --- /dev/null +++ b/microsoft_outlook_single_tenant/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_config_settings +from . import microsoft_outlook_mixin diff --git a/microsoft_outlook_single_tenant/models/microsoft_outlook_mixin.py b/microsoft_outlook_single_tenant/models/microsoft_outlook_mixin.py new file mode 100644 index 0000000..d933033 --- /dev/null +++ b/microsoft_outlook_single_tenant/models/microsoft_outlook_mixin.py @@ -0,0 +1,18 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import models + + +class MicrosoftOutlookMixin(models.AbstractModel): + _inherit = "microsoft.outlook.mixin" + + @property + def _OUTLOOK_ENDPOINT(self): + outlook_endpoint = "https://login.microsoftonline.com/{path}/oauth2/v2.0/" + path = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("microsoft_outlook_directory_tenant_id", "common") + ) + return outlook_endpoint.format(path=path) diff --git a/microsoft_outlook_single_tenant/models/res_config_settings.py b/microsoft_outlook_single_tenant/models/res_config_settings.py new file mode 100644 index 0000000..f372c31 --- /dev/null +++ b/microsoft_outlook_single_tenant/models/res_config_settings.py @@ -0,0 +1,14 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + microsoft_outlook_directory_tenant_id = fields.Char( + string="Directory (tenant) ID", + help="Place here Tenant ID (or Application ID), if single-tenant application", + config_parameter="microsoft_outlook_directory_tenant_id", + ) diff --git a/microsoft_outlook_single_tenant/readme/CONFIGURE.rst b/microsoft_outlook_single_tenant/readme/CONFIGURE.rst new file mode 100644 index 0000000..2cbffdf --- /dev/null +++ b/microsoft_outlook_single_tenant/readme/CONFIGURE.rst @@ -0,0 +1,7 @@ +* Register a new application on azure +* Set who can use this application or access this API as single-tenant +* Set Outlook credentials Client ID and Client Secret in Settings +* Set a ir_config_parameter like that: + +[ir.config_parameter] +microsoft_outlook_directory_tenant_id = Directory (tenant) ID diff --git a/microsoft_outlook_single_tenant/readme/CONTRIBUTORS.rst b/microsoft_outlook_single_tenant/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..f62bede --- /dev/null +++ b/microsoft_outlook_single_tenant/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Camptocamp SA `_: + + * Anna Janiszewska + * Telmo dos Santos diff --git a/microsoft_outlook_single_tenant/readme/DESCRIPTION.rst b/microsoft_outlook_single_tenant/readme/DESCRIPTION.rst new file mode 100644 index 0000000..4f184f3 --- /dev/null +++ b/microsoft_outlook_single_tenant/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +By default Odoo only supports multi-tenant apps authentication on Azure. +This module alows you configure Odoo as a single-tenant app. diff --git a/microsoft_outlook_single_tenant/static/description/index.html b/microsoft_outlook_single_tenant/static/description/index.html new file mode 100644 index 0000000..db8c2d3 --- /dev/null +++ b/microsoft_outlook_single_tenant/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Microsoft Outlook Single Tenant + + + +
+

Microsoft Outlook Single Tenant

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

By default Odoo only supports multi-tenant apps authentication on Azure. +This module alows you configure Odoo as a single-tenant app.

+

Table of contents

+ +
+

Configuration

+
    +
  • Register a new application on azure
  • +
  • Set who can use this application or access this API as single-tenant
  • +
  • Set Outlook credentials Client ID and Client Secret in Settings
  • +
  • Set a ir_config_parameter like that:
  • +
+

[ir.config_parameter] +microsoft_outlook_directory_tenant_id = Directory (tenant) ID

+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/microsoft_outlook_single_tenant/tests/__init__.py b/microsoft_outlook_single_tenant/tests/__init__.py new file mode 100644 index 0000000..1c673f9 --- /dev/null +++ b/microsoft_outlook_single_tenant/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import test_fetchmail_outlook diff --git a/microsoft_outlook_single_tenant/tests/test_fetchmail_outlook.py b/microsoft_outlook_single_tenant/tests/test_fetchmail_outlook.py new file mode 100644 index 0000000..cd216ae --- /dev/null +++ b/microsoft_outlook_single_tenant/tests/test_fetchmail_outlook.py @@ -0,0 +1,56 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo.tests.common import SavepointCase + + +class TestFetchMailServerMicrosoftOutlook(SavepointCase): + def _create_mail_server(self): + return self.env["fetchmail.server"].create( + { + "name": "Test server", + "use_microsoft_outlook_service": True, + "user": "test@example.com", + "password": "", + "server_type": "imap", + "is_ssl": True, + } + ) + + def test_default_app_endpoint(self): + self.env["res.config.settings"].create( + { + "microsoft_outlook_client_identifier": "test_client_id", + "microsoft_outlook_client_secret": "test_secret", + } + ).set_values() + + mail_server = self._create_mail_server() + common_endpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/" + self.assertIn(common_endpoint, mail_server.microsoft_outlook_uri) + + def test_single_tenant_app_endpoint(self): + self.env["res.config.settings"].create( + { + "microsoft_outlook_client_identifier": "test_client_id", + "microsoft_outlook_directory_tenant_id": "test_directory_tenant_id", + "microsoft_outlook_client_secret": "test_secret", + } + ).set_values() + + mail_server = self._create_mail_server() + mail_server = self.env["fetchmail.server"].create( + { + "name": "Test server", + "use_microsoft_outlook_service": True, + "user": "test@example.com", + "password": "", + "server_type": "imap", + "is_ssl": True, + } + ) + + single_tenant_endpoint = ( + "https://login.microsoftonline.com/test_directory_tenant_id/oauth2/v2.0/" + ) + self.assertIn(single_tenant_endpoint, mail_server.microsoft_outlook_uri) diff --git a/microsoft_outlook_single_tenant/views/res_config_settings_views.xml b/microsoft_outlook_single_tenant/views/res_config_settings_views.xml new file mode 100644 index 0000000..87f7b73 --- /dev/null +++ b/microsoft_outlook_single_tenant/views/res_config_settings_views.xml @@ -0,0 +1,25 @@ + + + + res.config.settings.view.form.inherit.microsoft_outlook_tenant + res.config.settings + + +
+
+
+
+
+
+