Skip to content

Commit

Permalink
[MIG] auth_oauth_multi_token: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Miku Laitinen authored and ChrisOForgeFlow committed Dec 8, 2023
1 parent acb2994 commit 594b6e1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion auth_oauth_multi_token/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "OAuth Multi Token",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Florent de Labarre, Camptocamp, Odoo Community Association (OCA)",
"summary": """Allow multiple connection with the same OAuth account""",
Expand Down
18 changes: 8 additions & 10 deletions auth_oauth_multi_token/i18n/auth_oauth_multi_token.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-14 09:02+0000\n"
"PO-Revision-Date: 2023-05-14 09:02+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -55,7 +57,7 @@ msgstr ""

#. module: auth_oauth_multi_token
#: model_terms:ir.ui.view,arch_db:auth_oauth_multi_token.view_users_form
msgid "Latest tokens"
msgid "Latest Tokens"
msgstr ""

#. module: auth_oauth_multi_token
Expand All @@ -65,7 +67,7 @@ msgstr ""

#. module: auth_oauth_multi_token
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_max_token
msgid "Max number of simultaneous connections"
msgid "Max Number of Simultaneous Connections"
msgstr ""

#. module: auth_oauth_multi_token
Expand All @@ -75,20 +77,16 @@ msgstr ""

#. module: auth_oauth_multi_token
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_token_ids
msgid "OAuth tokens"
msgid "OAuth Tokens"
msgstr ""

#. module: auth_oauth_multi_token
#: model:ir.model,name:auth_oauth_multi_token.model_auth_oauth_multi_token
msgid "OAuth2 token"
msgid "OAuth2 Token"
msgstr ""

#. module: auth_oauth_multi_token
#: model:ir.model,name:auth_oauth_multi_token.model_res_users
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__user_id
msgid "User"
msgstr ""

#. module: auth_oauth_multi_token
#: model:ir.model,name:auth_oauth_multi_token.model_res_users
msgid "Users"
msgstr ""
23 changes: 12 additions & 11 deletions auth_oauth_multi_token/models/auth_oauth_multi_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AuthOauthMultiToken(models.Model):
"""Define a set of tokens."""

_name = "auth.oauth.multi.token"
_description = "OAuth2 token"
_description = "OAuth2 Token"
_order = "id desc"

oauth_access_token = fields.Char(
Expand All @@ -25,12 +25,12 @@ class AuthOauthMultiToken(models.Model):
ondelete="cascade",
)

@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
"""Override to validate tokens."""
token = super().create(vals)
token._oauth_validate_multi_token()
return token
tokens = super().create(vals_list)
tokens._oauth_validate_multi_token()
return tokens

@api.model
def _oauth_user_tokens(self, user_id):
Expand All @@ -42,11 +42,12 @@ def _oauth_user_tokens(self, user_id):

def _oauth_validate_multi_token(self):
"""Check current user's token and clear them if max number reached."""
user_tokens = self._oauth_user_tokens(self.user_id.id)
max_token = self.user_id.oauth_access_max_token
if user_tokens and len(user_tokens) > max_token:
# clear last token
user_tokens[max_token - 1]._oauth_clear_token()
for token in self:
user_tokens = self._oauth_user_tokens(token.user_id.id)
max_token = token.user_id.oauth_access_max_token
if user_tokens and len(user_tokens) > max_token:
# clear last token
user_tokens[max_token - 1]._oauth_clear_token()

def _oauth_clear_token(self):
"""Disable current token records."""
Expand Down
4 changes: 2 additions & 2 deletions auth_oauth_multi_token/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def _generate_oauth_master_uuid(self):
oauth_access_token_ids = fields.One2many(
comodel_name="auth.oauth.multi.token",
inverse_name="user_id",
string="OAuth tokens",
string="OAuth Tokens",
copy=False,
readonly=True,
groups="base.group_system",
)
oauth_access_max_token = fields.Integer(
string="Max number of simultaneous connections", default=10, required=True
string="Max Number of Simultaneous Connections", default=10, required=True
)
oauth_master_uuid = fields.Char(
string="Master UUID",
Expand Down
1 change: 1 addition & 0 deletions auth_oauth_multi_token/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

* Stéphane Bidoul <[email protected]>
* Dan Tillinghast
* Miku Laitinen
2 changes: 1 addition & 1 deletion auth_oauth_multi_token/tests/test_multi_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json

from odoo import exceptions
from odoo.tests import TransactionCase
from odoo.tests.common import TransactionCase


class TestMultiToken(TransactionCase):
Expand Down
3 changes: 2 additions & 1 deletion auth_oauth_multi_token/views/res_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<field name="oauth_access_max_token" />
</field>
<xpath expr="//field[@name='oauth_provider_id']/.." position="after">
<group name="multi_token_info" string="Latest tokens">
<group name="multi_token_info" string="Latest Tokens">
<label for="oauth_access_token_ids" />
<field
name="oauth_access_token_ids"
nolabel="1"
Expand Down

0 comments on commit 594b6e1

Please sign in to comment.