diff --git a/setup/shopfloor_mobile_base_auth_api_key/odoo/addons/shopfloor_mobile_base_auth_api_key b/setup/shopfloor_mobile_base_auth_api_key/odoo/addons/shopfloor_mobile_base_auth_api_key new file mode 120000 index 0000000000..9681aad6ac --- /dev/null +++ b/setup/shopfloor_mobile_base_auth_api_key/odoo/addons/shopfloor_mobile_base_auth_api_key @@ -0,0 +1 @@ +../../../../shopfloor_mobile_base_auth_api_key \ No newline at end of file diff --git a/setup/shopfloor_mobile_base_auth_api_key/setup.py b/setup/shopfloor_mobile_base_auth_api_key/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopfloor_mobile_base_auth_api_key/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopfloor_mobile_base_auth_api_key/README.rst b/shopfloor_mobile_base_auth_api_key/README.rst new file mode 100644 index 0000000000..e77a485269 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/README.rst @@ -0,0 +1,84 @@ +====================================== +Shopfloor Mobile Base auth via API key +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8d2fe59374041f7c6dee89f0d3260999918aa16ea9a4ec72fd062551eae65d0d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwms-lightgray.png?logo=github + :target: https://github.com/OCA/wms/tree/16.0/shopfloor_mobile_base_auth_api_key + :alt: OCA/wms +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/wms-16-0/wms-16-0-shopfloor_mobile_base_auth_api_key + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/wms&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Provide Shopfloor mobile base authentication via API key. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Simone Orsi +* Juan Miguel Sánchez Arce + +Other credits +~~~~~~~~~~~~~ + +**Financial support** + +* Camptocamp R&D + +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/wms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/shopfloor_mobile_base_auth_api_key/__init__.py b/shopfloor_mobile_base_auth_api_key/__init__.py new file mode 100644 index 0000000000..71a02422d5 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import services diff --git a/shopfloor_mobile_base_auth_api_key/__manifest__.py b/shopfloor_mobile_base_auth_api_key/__manifest__.py new file mode 100644 index 0000000000..1c51839255 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2021 Camptocamp SA (http://www.camptocamp.com) +# @author Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Shopfloor Mobile Base auth via API key", + "summary": "Provides authentication via API key to Shopfloor base mobile app", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Inventory", + "website": "https://github.com/OCA/wms", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainer": ["simahawk"], + "license": "LGPL-3", + "depends": [ + "shopfloor_mobile_base", + "auth_api_key_group", + ], + "data": ["templates/assets.xml", "views/shopfloor_app.xml"], + "demo": [ + "demo/auth_api_key_demo.xml", + "demo/auth_api_key_group_demo.xml", + "demo/shopfloor_app_demo.xml", + ], +} diff --git a/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_demo.xml b/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_demo.xml new file mode 100644 index 0000000000..d23a641c60 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_demo.xml @@ -0,0 +1,7 @@ + + + Shopfloor Demo + + 72B044F7AC780DAC + + diff --git a/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_group_demo.xml b/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_group_demo.xml new file mode 100644 index 0000000000..f6728ed4bb --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/demo/auth_api_key_group_demo.xml @@ -0,0 +1,15 @@ + + + + + Shopfloor Demo + shopfloor_demo + + + + diff --git a/shopfloor_mobile_base_auth_api_key/demo/shopfloor_app_demo.xml b/shopfloor_mobile_base_auth_api_key/demo/shopfloor_app_demo.xml new file mode 100644 index 0000000000..e4b26d09db --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/demo/shopfloor_app_demo.xml @@ -0,0 +1,14 @@ + + + Shopfloor Demo (api key auth) + demo api key + demo_api_key + api_key + + + diff --git a/shopfloor_mobile_base_auth_api_key/i18n/pt_BR.po b/shopfloor_mobile_base_auth_api_key/i18n/pt_BR.po new file mode 100644 index 0000000000..942701c16a --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/i18n/pt_BR.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model,name:shopfloor_mobile_base_auth_api_key.model_shopfloor_app +msgid "A Shopfloor application" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__auth_api_key_group_ids +msgid "Allowed API key groups" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__display_name +msgid "Display Name" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__id +msgid "ID" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app____last_update +msgid "Last Modified on" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model_terms:ir.ui.view,arch_db:shopfloor_mobile_base_auth_api_key.shopfloor_app_form_view +msgid "Manage groups" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:shopfloor.app,name:shopfloor_mobile_base_auth_api_key.app_demo1 +msgid "Shopfloor Demo (api key auth)" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:shopfloor.app,short_name:shopfloor_mobile_base_auth_api_key.app_demo1 +msgid "demo api key" +msgstr "" diff --git a/shopfloor_mobile_base_auth_api_key/i18n/shopfloor_mobile_base_auth_api_key.pot b/shopfloor_mobile_base_auth_api_key/i18n/shopfloor_mobile_base_auth_api_key.pot new file mode 100644 index 0000000000..1b4a499ff3 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/i18n/shopfloor_mobile_base_auth_api_key.pot @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * shopfloor_mobile_base_auth_api_key +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \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: shopfloor_mobile_base_auth_api_key +#: model:ir.model,name:shopfloor_mobile_base_auth_api_key.model_shopfloor_app +msgid "A Shopfloor application" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__auth_api_key_group_ids +msgid "Allowed API key groups" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__display_name +msgid "Display Name" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app__id +msgid "ID" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:ir.model.fields,field_description:shopfloor_mobile_base_auth_api_key.field_shopfloor_app____last_update +msgid "Last Modified on" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model_terms:ir.ui.view,arch_db:shopfloor_mobile_base_auth_api_key.shopfloor_app_form_view +msgid "Manage groups" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:shopfloor.app,name:shopfloor_mobile_base_auth_api_key.app_demo1 +msgid "Shopfloor Demo (api key auth)" +msgstr "" + +#. module: shopfloor_mobile_base_auth_api_key +#: model:shopfloor.app,short_name:shopfloor_mobile_base_auth_api_key.app_demo1 +msgid "demo api key" +msgstr "" diff --git a/shopfloor_mobile_base_auth_api_key/models/__init__.py b/shopfloor_mobile_base_auth_api_key/models/__init__.py new file mode 100644 index 0000000000..928c5bb7dd --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/models/__init__.py @@ -0,0 +1 @@ +from . import shopfloor_app diff --git a/shopfloor_mobile_base_auth_api_key/models/shopfloor_app.py b/shopfloor_mobile_base_auth_api_key/models/shopfloor_app.py new file mode 100644 index 0000000000..063fce9719 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/models/shopfloor_app.py @@ -0,0 +1,29 @@ +# Copyright 2021 Camptcamp SA +# @author: Simone Orsi +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class ShopfloorApp(models.Model): + + # TODO: consider splitting this to new module shopfloor_base_auth_api_key + _inherit = "shopfloor.app" + + def _selection_auth_type(self): + return super()._selection_auth_type() + [("api_key", "API key")] + + # Borrowed from `endpoint_auth_api_key`: shall we define a mixin? + auth_api_key_group_ids = fields.Many2many( + comodel_name="auth.api.key.group", + string="Allowed API key groups", + ) + + def _allowed_api_key_ids(self): + return self.auth_api_key_group_ids.auth_api_key_ids.ids + + def action_manage_api_key_groups(self): + xid = "auth_api_key_group.auth_api_key_group_act_window" + action = self.env["ir.actions.act_window"]._for_xml_id(xid) + action["domain"] = [("id", "in", self.auth_api_key_group_ids.ids)] + return action diff --git a/shopfloor_mobile_base_auth_api_key/readme/CONTRIBUTORS.rst b/shopfloor_mobile_base_auth_api_key/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..97a2f863bf --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Simone Orsi +* Juan Miguel Sánchez Arce diff --git a/shopfloor_mobile_base_auth_api_key/readme/CREDITS.rst b/shopfloor_mobile_base_auth_api_key/readme/CREDITS.rst new file mode 100644 index 0000000000..a9b11d87a7 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/readme/CREDITS.rst @@ -0,0 +1,3 @@ +**Financial support** + +* Camptocamp R&D diff --git a/shopfloor_mobile_base_auth_api_key/readme/DESCRIPTION.rst b/shopfloor_mobile_base_auth_api_key/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..3107ef85cd --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Provide Shopfloor mobile base authentication via API key. diff --git a/shopfloor_mobile_base_auth_api_key/services/__init__.py b/shopfloor_mobile_base_auth_api_key/services/__init__.py new file mode 100644 index 0000000000..72d6086eee --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/services/__init__.py @@ -0,0 +1 @@ +from . import service diff --git a/shopfloor_mobile_base_auth_api_key/services/service.py b/shopfloor_mobile_base_auth_api_key/services/service.py new file mode 100644 index 0000000000..65ce217500 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/services/service.py @@ -0,0 +1,31 @@ +# Copyright 2021 Camptocamp SA (http://www.camptocamp.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +import logging + +from werkzeug.exceptions import Forbidden + +from odoo.addons.component.core import AbstractComponent + +_logger = logging.getLogger(__name__) + + +class BaseShopfloorService(AbstractComponent): + _inherit = "base.shopfloor.service" + + def dispatch(self, method_name, *args, params=None): + self._validate_request(self.request) + return super().dispatch(method_name, *args, params=params) + + def _validate_request(self, request): + if self.collection.auth_type == "api_key": + # request api key is already validated when we reach this point + # Now let's validate it at app level. + if ( + self.request.auth_api_key_id + not in self.collection.sudo()._allowed_api_key_ids() + ): + _logger.error( + "API key not allowed on app '%s'", self.collection.tech_name + ) + raise Forbidden() diff --git a/shopfloor_mobile_base_auth_api_key/static/description/icon.png b/shopfloor_mobile_base_auth_api_key/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopfloor_mobile_base_auth_api_key/static/description/icon.png differ diff --git a/shopfloor_mobile_base_auth_api_key/static/description/index.html b/shopfloor_mobile_base_auth_api_key/static/description/index.html new file mode 100644 index 0000000000..de00a4160c --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Shopfloor Mobile Base auth via API key + + + +
+

Shopfloor Mobile Base auth via API key

+ + +

Beta License: LGPL-3 OCA/wms Translate me on Weblate Try me on Runboat

+

Provide Shopfloor mobile base authentication via API key.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

Financial support

+
    +
  • Camptocamp R&D
  • +
+
+
+

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/wms project on GitHub.

+

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

+
+
+
+ + diff --git a/shopfloor_mobile_base_auth_api_key/static/wms/src/login.js b/shopfloor_mobile_base_auth_api_key/static/wms/src/login.js new file mode 100644 index 0000000000..24bad64876 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/static/wms/src/login.js @@ -0,0 +1,85 @@ +/** + * @author Simone Orsi + * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + */ + +import {translation_registry} from "/shopfloor_mobile_base/static/wms/src/services/translation_registry.js"; +import { + AuthHandlerMixin, + auth_handler_registry, +} from "/shopfloor_mobile_base/static/wms/src/services/auth_handler_registry.js"; +import {config_registry} from "/shopfloor_mobile_base/static/wms/src/services/config_registry.js"; + +// Register apikey storage +config_registry.add("apikey", {default: "", reset_on_clear: true}); + +// Provide auth handle for Odoo calls +export class ApiKeyAuthHandler extends AuthHandlerMixin { + get_params() { + return { + headers: { + "API-KEY": this.$root.apikey, + }, + }; + } + + // on_login($root, evt, data) { + // No need for a handler as we set the api_key inside the login method + // } + + // on_logout($root) { + // No need for a handler as the reset_on_clear flag in the config_registry + // is going to flush the api_key on appdata cleanup + // } +} + +auth_handler_registry.add("api_key", ApiKeyAuthHandler); + +/** + * Handle loging via API key. + * + * Conventional name: `login-` + auth_type (from app config) + */ +Vue.component("login-api_key", { + data: function () { + return { + apikey: "", + }; + }, + methods: { + login: function (evt) { + this.$root.apikey = this.apikey; + this.$root.login(evt); + }, + }, + template: ` + + +
+ + + {{ $t('screen.login.action.login') }} + + +
+
+ `, +}); + +translation_registry.add("en-US.screen.login.api_key_label", "API key"); +translation_registry.add("fr-FR.screen.login.api_key_label", "Clé API"); +translation_registry.add("de-DE.screen.login.api_key_label", "API-Schlüssel"); + +translation_registry.add("en-US.screen.login.api_key_placeholder", "YOUR_API_KEY_HERE"); +translation_registry.add("fr-FR.screen.login.api_key_placeholder", "VOTRE_CLE_API_ICI"); +translation_registry.add( + "de-DE.screen.login.api_key_placeholder", + "DEIN_API-SCHLÜSSEL_HIER" +); diff --git a/shopfloor_mobile_base_auth_api_key/templates/assets.xml b/shopfloor_mobile_base_auth_api_key/templates/assets.xml new file mode 100644 index 0000000000..7c765ebcf5 --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/templates/assets.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/shopfloor_mobile_base_auth_api_key/views/shopfloor_app.xml b/shopfloor_mobile_base_auth_api_key/views/shopfloor_app.xml new file mode 100644 index 0000000000..72e0954c9d --- /dev/null +++ b/shopfloor_mobile_base_auth_api_key/views/shopfloor_app.xml @@ -0,0 +1,25 @@ + + + + shopfloor app form + shopfloor.app + + + + +