-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#65093 [ADD] google_api_auth (#142)
- Loading branch information
Showing
13 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+68.4 KB
google_api_auth/static/description/google_application_configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |