Browse Source

[IMP] emc_api: generate api key

pull/71/head
robin.keunen 5 years ago
parent
commit
fb5869758d
  1. 16
      easy_my_coop_api/README.rst
  2. 1
      easy_my_coop_api/__init__.py
  3. 1
      easy_my_coop_api/models/__init__.py
  4. 34
      easy_my_coop_api/models/auth_api_key.py
  5. 12
      easy_my_coop_api/readme/USAGE.rst
  6. 41
      easy_my_coop_api/static/description/index.html

16
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
======================

1
easy_my_coop_api/__init__.py

@ -1,2 +1,3 @@
from . import controllers
from . import models
from . import services

1
easy_my_coop_api/models/__init__.py

@ -0,0 +1 @@
from . import auth_api_key

34
easy_my_coop_api/models/auth_api_key.py

@ -0,0 +1,34 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Robin Keunen <robin@coopiteasy.be>
# 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"

12
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

41
easy_my_coop_api/static/description/index.html

@ -372,18 +372,35 @@ ul.auto-toc {
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#known-issues-roadmap" id="id1">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To give access to the API to a structure, go to</p>
<ul class="simple">
<li>Settings &gt; Technical (debug mode) &gt; Auth API Key</li>
<li>click create and select a user, save.</li>
<li>communicate the API-KEY to the structure.</li>
</ul>
<p>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</p>
<ul class="simple">
<li>name = coopiteasy-api-user</li>
<li>Application Accesses = Cooperative Management / User</li>
<li>Platform Structure = Coop IT Easy</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id1">Known issues / Roadmap</a></h1>
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
<p>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.</p>
@ -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.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/issues">GitHub Issues</a>.
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
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
<li>Robin Keunen &lt;<a class="reference external" href="mailto:robin&#64;coopiteasy.be">robin&#64;coopiteasy.be</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/tree/12.0/easy_my_coop_api">coopiteasy/vertical-cooperative</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>

Loading…
Cancel
Save