Skip to content

Commit

Permalink
TA#65093 [ADD] google_api_auth (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda authored Jun 27, 2024
1 parent 69e70ae commit 981d62a
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 1 deletion.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"web_email_field_new_tab",
"dms_document_url",
"event_allowed_ceu",
"google_api_auth",
"web_base_url_freeze",
],
"installable": True,
Expand Down
5 changes: 4 additions & 1 deletion .docker_files/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ddt==1.2.1
PyJWT==2.4.0
PyJWT==2.4.0
google-api-python-client==2.134.0
google-auth-httplib2==0.2.0
google-auth-oauthlib==1.2.0
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions google_api_auth/README.rst
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions google_api_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions google_api_auth/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
135 changes: 135 additions & 0 deletions google_api_auth/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions google_api_auth/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions google_api_auth/models/google_application.py
Original file line number Diff line number Diff line change
@@ -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,
},
}
2 changes: 2 additions & 0 deletions google_api_auth/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added google_api_auth/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions google_api_auth/views/google_application_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="google_application_view_tree" model="ir.ui.view">
<field name="name">google.application.view.tree</field>
<field name="model">google.application</field>
<field name="arch" type="xml">
<tree string="Google Applications">
<field name="name"/>
<field name="project_id"/>
<field name="scope"/>
<field name="active"/>
</tree>
</field>
</record>

<record id="google_application_view_form" model="ir.ui.view">
<field name="name">google.application.view.form</field>
<field name="model">google.application</field>
<field name="arch" type="xml">
<form string="Google Application">
<sheet>
<group>
<group>
<field name="name" />
<field name="project_id" />
<field name="auth_type" />
<field name="active" widget="boolean_toggle"/>
</group>
<group>
<field name="json_file" filename="filename"/>
<field name="filename" invisible="1"/>
<field name="scope" />
</group>
</group>
<group name="test_cnx" string="Test Google API Auth">
<button name="test_google_api_auth" type="object" string="Test Google API Auth" icon="fa-television"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="google_application_action" model="ir.actions.act_window">
<field name="name">Google Applications</field>
<field name="res_model">google.application</field>
<field name="view_id" ref="google_application_view_tree" />
</record>

<menuitem id="google_application_main"
name="Google API"
parent="base.menu_custom"
sequence="10" />

<menuitem id="google_application_menu"
name="Google Applications"
parent="google_api_auth.google_application_main"
sequence="1"
action="google_application_action" />
</odoo>

0 comments on commit 981d62a

Please sign in to comment.