Skip to content

Commit

Permalink
Merge PR #701 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rousseldenis
  • Loading branch information
OCA-git-bot committed May 13, 2024
2 parents a7fcec5 + 0194333 commit 114c007
Show file tree
Hide file tree
Showing 22 changed files with 893 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/shopfloor_mobile_base_auth_api_key/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
84 changes: 84 additions & 0 deletions shopfloor_mobile_base_auth_api_key/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/wms/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 <https://github.com/OCA/wms/issues/new?body=module:%20shopfloor_mobile_base_auth_api_key%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Simone Orsi <[email protected]>
* Juan Miguel Sánchez Arce <[email protected]>

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 <https://github.com/OCA/wms/tree/16.0/shopfloor_mobile_base_auth_api_key>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions shopfloor_mobile_base_auth_api_key/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import services
25 changes: 25 additions & 0 deletions shopfloor_mobile_base_auth_api_key/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021 Camptocamp SA (http://www.camptocamp.com)
# @author Simone Orsi <[email protected]>
# 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",
],
}
7 changes: 7 additions & 0 deletions shopfloor_mobile_base_auth_api_key/demo/auth_api_key_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo noupdate="1">
<record id="api_key_demo" model="auth.api.key">
<field name="name">Shopfloor Demo</field>
<field name="user_id" ref="base.user_demo" />
<field name="key">72B044F7AC780DAC</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">

<record id="auth_api_key_group" model="auth.api.key.group">
<field name="name">Shopfloor Demo</field>
<field name="code">shopfloor_demo</field>
<field
name="auth_api_key_ids"
eval="[
(4, ref('api_key_demo')),
]"
/>
</record>

</odoo>
14 changes: 14 additions & 0 deletions shopfloor_mobile_base_auth_api_key/demo/shopfloor_app_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo noupdate="1">
<record id="app_demo1" model="shopfloor.app">
<field name="name">Shopfloor Demo (api key auth)</field>
<field name="short_name">demo api key</field>
<field name="tech_name">demo_api_key</field>
<field name="auth_type">api_key</field>
<field
name="auth_api_key_group_ids"
eval="[
(4, ref('auth_api_key_group')),
]"
/>
</record>
</odoo>
54 changes: 54 additions & 0 deletions shopfloor_mobile_base_auth_api_key/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -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 ""
Original file line number Diff line number Diff line change
@@ -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 ""
1 change: 1 addition & 0 deletions shopfloor_mobile_base_auth_api_key/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import shopfloor_app
29 changes: 29 additions & 0 deletions shopfloor_mobile_base_auth_api_key/models/shopfloor_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021 Camptcamp SA
# @author: Simone Orsi <[email protected]>
# 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
2 changes: 2 additions & 0 deletions shopfloor_mobile_base_auth_api_key/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Simone Orsi <[email protected]>
* Juan Miguel Sánchez Arce <[email protected]>
3 changes: 3 additions & 0 deletions shopfloor_mobile_base_auth_api_key/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Financial support**

* Camptocamp R&D
1 change: 1 addition & 0 deletions shopfloor_mobile_base_auth_api_key/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provide Shopfloor mobile base authentication via API key.
1 change: 1 addition & 0 deletions shopfloor_mobile_base_auth_api_key/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import service
31 changes: 31 additions & 0 deletions shopfloor_mobile_base_auth_api_key/services/service.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 114c007

Please sign in to comment.