diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index d9d3a83a..1b397390 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -61,6 +61,7 @@ "web_email_field_new_tab", "dms_document_url", "event_allowed_ceu", + "google_api_auth", "web_base_url_freeze", ], "installable": True, diff --git a/.docker_files/test-requirements.txt b/.docker_files/test-requirements.txt index b27b4ea1..fa037151 100644 --- a/.docker_files/test-requirements.txt +++ b/.docker_files/test-requirements.txt @@ -1,2 +1,5 @@ ddt==1.2.1 -PyJWT==2.4.0 \ No newline at end of file +PyJWT==2.4.0 +google-api-python-client==2.134.0 +google-auth-httplib2==0.2.0 +google-auth-oauthlib==1.2.0 diff --git a/Dockerfile b/Dockerfile index 5e022e53..8e3c1f44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,7 @@ COPY utm_archive /mnt/extra-addons/utm_archive COPY web_email_field_new_tab /mnt/extra-addons/web_email_field_new_tab COPY dms_document_url /mnt/extra-addons/dms_document_url COPY event_allowed_ceu /mnt/extra-addons/event_allowed_ceu +COPY google_api_auth /mnt/extra-addons/google_api_auth COPY web_base_url_freeze /mnt/extra-addons/web_base_url_freeze COPY .docker_files/main /mnt/extra-addons/main diff --git a/google_api_auth/README.rst b/google_api_auth/README.rst new file mode 100644 index 00000000..399e9693 --- /dev/null +++ b/google_api_auth/README.rst @@ -0,0 +1,16 @@ +Google API Authentication +========================= +This module allows connect to Google Applications. + +Usage +----- + +In `Settings > Technical > Google API > Google Applications`, you can set google applications configuration. + +Click on "Test Google API Auth" to check if the Authentication is well set. + +.. image:: static/description/google_application_configuration.png + +Contributors +------------ +* Numigi (tm) and all its contributors (https://bit.ly/numigiens) diff --git a/google_api_auth/__init__.py b/google_api_auth/__init__.py new file mode 100644 index 00000000..01e87973 --- /dev/null +++ b/google_api_auth/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/google_api_auth/__manifest__.py b/google_api_auth/__manifest__.py new file mode 100644 index 00000000..f889ee64 --- /dev/null +++ b/google_api_auth/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Google API Authentication", + "version": "1.0.0", + "author": "Numigi", + "maintainer": "Numigi", + "website": "https://bit.ly/numigi-com", + "license": "AGPL-3", + "category": "Hidden/Tools", + "external_dependencies": { + "python": [ + "google-api-python-client", + "google-auth-httplib2", + "google-auth-oauthlib", + ] + }, + "depends": ["base"], + "summary": "Allow users to connect to Google applications.", + "data": [ + "security/ir.model.access.csv", + "views/google_application_views.xml", + ], + "installable": True, +} diff --git a/google_api_auth/i18n/fr.po b/google_api_auth/i18n/fr.po new file mode 100644 index 00000000..58d52a33 --- /dev/null +++ b/google_api_auth/i18n/fr.po @@ -0,0 +1,135 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * google_api_auth +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-06-27 18:39+0000\n" +"PO-Revision-Date: 2024-06-27 18:39+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__active +msgid "Active" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__name +msgid "Application name" +msgstr "Nom d'application" + +#. module: google_api_auth +#: code:addons/google_api_auth/models/google_application.py:0 +#, python-format +msgid "" +"Authentication Test Failed! \n" +" %s" +msgstr "Le test d'authentification a échoué ! \n" +" %s" + +#. module: google_api_auth +#: code:addons/google_api_auth/models/google_application.py:0 +#, python-format +msgid "Authentication Test Succeeded!" +msgstr "Test d'authentification réussi !" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__auth_type +msgid "Authentication Type" +msgstr "Type d'authentification" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__create_uid +msgid "Created by" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__create_date +msgid "Created on" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__display_name +msgid "Display Name" +msgstr "" + +#. module: google_api_auth +#: code:addons/google_api_auth/models/google_application.py:0 +#, python-format +msgid "Everything seems properly set up!" +msgstr "Tout semble bien configuré !" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__filename +msgid "File Name" +msgstr "Nom du fichier" + +#. module: google_api_auth +#: model:ir.ui.menu,name:google_api_auth.google_application_main +msgid "Google API" +msgstr "" + +#. module: google_api_auth +#: model:ir.model,name:google_api_auth.model_google_application +#: model_terms:ir.ui.view,arch_db:google_api_auth.google_application_view_form +msgid "Google Application" +msgstr "Application Google" + +#. module: google_api_auth +#: model:ir.actions.act_window,name:google_api_auth.google_application_action +#: model:ir.ui.menu,name:google_api_auth.google_application_menu +#: model_terms:ir.ui.view,arch_db:google_api_auth.google_application_view_tree +msgid "Google Applications" +msgstr "Applications Google" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__id +msgid "ID" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__json_file +msgid "Json File" +msgstr "Fichier Json" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application____last_update +msgid "Last Modified on" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__write_date +msgid "Last Updated on" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__project_id +msgid "Project name" +msgstr "Nom du projet" + +#. module: google_api_auth +#: model:ir.model.fields,field_description:google_api_auth.field_google_application__scope +msgid "Scope" +msgstr "" + +#. module: google_api_auth +#: model:ir.model.fields.selection,name:google_api_auth.selection__google_application__auth_type__service_account +msgid "Service Account" +msgstr "Compte de service" + +#. module: google_api_auth +#: model_terms:ir.ui.view,arch_db:google_api_auth.google_application_view_form +msgid "Test Google API Auth" +msgstr "Testez l'authentification de l'API Google" diff --git a/google_api_auth/models/__init__.py b/google_api_auth/models/__init__.py new file mode 100644 index 00000000..97cbd75c --- /dev/null +++ b/google_api_auth/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import google_application diff --git a/google_api_auth/models/google_application.py b/google_api_auth/models/google_application.py new file mode 100644 index 00000000..2d5c1854 --- /dev/null +++ b/google_api_auth/models/google_application.py @@ -0,0 +1,60 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 +import json + +from google.oauth2 import service_account +from odoo.exceptions import UserError +from odoo import api, fields, models, _ + + +class GoogleAppConf(models.Model): + _name = "google.application" + _description = "Google Application" + + active = fields.Boolean(string="Active", default=True) + name = fields.Char(string="Application name", required=True, copy=False) + project_id = fields.Char(string="Project name", required=True, copy=False) + auth_type = fields.Selection( + [("service_account", "Service Account")], + string="Authentication Type", + required=True, + default="service_account", + ) + filename = fields.Char("File Name") + json_file = fields.Binary(attachment=True) + scope = fields.Char(string="Scope", required=True, copy=False) + + @api.model + def google_api_auth(self): + self.ensure_one() + try: + info = json.loads( + base64.b64decode(self.json_file).decode("utf-8") + ) + creds = service_account.Credentials.from_service_account_info( + info, scopes=[self.scope] + ) + + return creds + except Exception as error: + UserError(_("Authentication Test Failed! \n %s" % error)) + + def test_google_api_auth(self): + for app in self: + try: + app.google_api_auth() + except UserError as error: + raise error + title = _("Authentication Test Succeeded!") + message = _("Everything seems properly set up!") + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": title, + "message": message, + "sticky": False, + }, + } diff --git a/google_api_auth/security/ir.model.access.csv b/google_api_auth/security/ir.model.access.csv new file mode 100644 index 00000000..e5a3e173 --- /dev/null +++ b/google_api_auth/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_google_application,access_google_application,model_google_application,base.group_system,1,1,1,1 diff --git a/google_api_auth/static/description/google_application_configuration.png b/google_api_auth/static/description/google_application_configuration.png new file mode 100644 index 00000000..75f701d6 Binary files /dev/null and b/google_api_auth/static/description/google_application_configuration.png differ diff --git a/google_api_auth/static/description/icon.png b/google_api_auth/static/description/icon.png new file mode 100644 index 00000000..92a86b10 Binary files /dev/null and b/google_api_auth/static/description/icon.png differ diff --git a/google_api_auth/views/google_application_views.xml b/google_api_auth/views/google_application_views.xml new file mode 100644 index 00000000..daf12b56 --- /dev/null +++ b/google_api_auth/views/google_application_views.xml @@ -0,0 +1,60 @@ + + + + + google.application.view.tree + google.application + + + + + + + + + + + + google.application.view.form + google.application + +
+ + + + + + + + + + + + + + + +