From fb5869758d7a19bc634e58474dfd9e613528ac3b Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Tue, 26 May 2020 16:12:51 +0200 Subject: [PATCH] [IMP] emc_api: generate api key --- easy_my_coop_api/README.rst | 16 ++++++++ easy_my_coop_api/__init__.py | 1 + easy_my_coop_api/models/__init__.py | 1 + easy_my_coop_api/models/auth_api_key.py | 34 +++++++++++++++ easy_my_coop_api/readme/USAGE.rst | 12 ++++++ .../static/description/index.html | 41 +++++++++++++------ 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 easy_my_coop_api/models/__init__.py create mode 100644 easy_my_coop_api/models/auth_api_key.py create mode 100644 easy_my_coop_api/readme/USAGE.rst diff --git a/easy_my_coop_api/README.rst b/easy_my_coop_api/README.rst index 4eb4cb6..f6ee9ae 100644 --- a/easy_my_coop_api/README.rst +++ b/easy_my_coop_api/README.rst @@ -26,6 +26,22 @@ Open Easy My Coop to the world: RESTful API. .. contents:: :local: +Usage +===== + +To give access to the API to a structure, go to + +- Settings > Technical (debug mode) > Auth API Key +- click create and select a user, save. +- communicate the API-KEY to the structure. + +It is recommended to create a technical user for the structure belonging to the group "Easy My Coop User". +For example, for the structure Coop IT Easy, create partner with + +- name = coopiteasy-api-user +- Application Accesses = Cooperative Management / User +- Platform Structure = Coop IT Easy + Known issues / Roadmap ====================== diff --git a/easy_my_coop_api/__init__.py b/easy_my_coop_api/__init__.py index d6d6244..c312a84 100644 --- a/easy_my_coop_api/__init__.py +++ b/easy_my_coop_api/__init__.py @@ -1,2 +1,3 @@ from . import controllers +from . import models from . import services diff --git a/easy_my_coop_api/models/__init__.py b/easy_my_coop_api/models/__init__.py new file mode 100644 index 0000000..6dfe3f7 --- /dev/null +++ b/easy_my_coop_api/models/__init__.py @@ -0,0 +1 @@ +from . import auth_api_key diff --git a/easy_my_coop_api/models/auth_api_key.py b/easy_my_coop_api/models/auth_api_key.py new file mode 100644 index 0000000..0db7834 --- /dev/null +++ b/easy_my_coop_api/models/auth_api_key.py @@ -0,0 +1,34 @@ +# Copyright 2020 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import uuid + +from odoo import api, fields, models + + +class AuthApiKey(models.Model): + _inherit = "auth.api.key" + + def _default_key(self): + return uuid.uuid4() + + # overloaded fields + # required is set to false to allow for a computed field, + # it will always be set. + name = fields.Char(required=False, compute="_compute_name", store=True) + key = fields.Char(default=_default_key) + + @api.multi + @api.depends("user_id") + def _compute_name(self): + for key in self: + if key.user_id: + now = fields.Datetime.now() + + key.name = "{login}-{now}".format( + now=fields.Datetime.to_string(now), + login=key.user_id.login, + ) + else: + key.name = "no-user" diff --git a/easy_my_coop_api/readme/USAGE.rst b/easy_my_coop_api/readme/USAGE.rst new file mode 100644 index 0000000..ee1feef --- /dev/null +++ b/easy_my_coop_api/readme/USAGE.rst @@ -0,0 +1,12 @@ +To give access to the API to a structure, go to + +- Settings > Technical (debug mode) > Auth API Key +- click create and select a user, save. +- communicate the API-KEY to the structure. + +It is recommended to create a technical user for the structure belonging to the group "Easy My Coop User". +For example, for the structure Coop IT Easy, create partner with + +- name = coopiteasy-api-user +- Application Accesses = Cooperative Management / User +- Platform Structure = Coop IT Easy diff --git a/easy_my_coop_api/static/description/index.html b/easy_my_coop_api/static/description/index.html index bc922dd..81a2b67 100644 --- a/easy_my_coop_api/static/description/index.html +++ b/easy_my_coop_api/static/description/index.html @@ -372,18 +372,35 @@ ul.auto-toc {

Table of contents

+
+

Usage

+

To give access to the API to a structure, go to

+
    +
  • Settings > Technical (debug mode) > Auth API Key
  • +
  • click create and select a user, save.
  • +
  • communicate the API-KEY to the structure.
  • +
+

It is recommended to create a technical user for the structure belonging to the group “Easy My Coop User”. +For example, for the structure Coop IT Easy, create partner with

+
    +
  • name = coopiteasy-api-user
  • +
  • Application Accesses = Cooperative Management / User
  • +
  • Platform Structure = Coop IT Easy
  • +
+
-

Known issues / Roadmap

+

Known issues / Roadmap

The API should generate and use an external id for records instead of odoo’s generated id. It would make importing and export data as well as migrating across versions easier.

@@ -392,7 +409,7 @@ routes would need to be rewritten: they only take integer as ids. Another way is to define a sequence per model.

-

Bug Tracker

+

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 smashing it by providing a detailed and welcomed @@ -400,22 +417,22 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Coop IT Easy SCRLfs
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is part of the coopiteasy/vertical-cooperative project on GitHub.

You are welcome to contribute.