Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added openapi/models/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added openapi/models/__pycache__/base.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file added openapi/models/__pycache__/ir_model.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions openapi/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class Base(models.AbstractModel):
_inherit = "base"



@api.model
def search_or_create(self, vals, active_test=True):
domain = [(k, "=", v) for k, v in vals.items()]
Expand All @@ -15,3 +17,4 @@ def search_or_create(self, vals, active_test=True):
is_new = True
records = self.create(vals)
return (is_new, records.ids)

2 changes: 2 additions & 0 deletions openapi/models/ir_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
class IrModel(models.Model):
_inherit = "ir.model"


api_access_ids = fields.One2many("openapi.access", "model_id", "Access via API")
api_accesses_count = fields.Integer(
compute="_compute_related_accesses_count",
string="Related openapi accesses count",
store=False,
)


@api.multi
def _compute_related_accesses_count(self):
for record in self:
Expand Down
4 changes: 4 additions & 0 deletions openapi/models/openapi_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Namespace(models.Model):
_name = "openapi.namespace"
_description = "Integration"



active = fields.Boolean("Active", default=True)
name = fields.Char(
"Name",
Expand Down Expand Up @@ -256,6 +258,8 @@ def _compute_last_used(self):
.create_date
)



def _compute_log_count(self):
self._cr.execute(
"SELECT COUNT(*) FROM openapi_log WHERE namespace_id=(%s);", [str(self.id)]
Expand Down
17 changes: 16 additions & 1 deletion openapi/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
# Copyright 2018 Rafis Bikbov <https://it-projects.info/team/bikbov>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import uuid

import wdb
from odoo import api, fields, models



class ResUsers(models.Model):
_inherit = "res.users"

namespace_ids = fields.Many2many("openapi.namespace", string="Allowed Integrations")
is_same_user = fields.Boolean(
compute='is_the_same_user',
store=False,
string='Same User'
)
openapi_token = fields.Char(
"OpenAPI Token",
default=lambda self: self._get_unique_openapi_token(),
Expand All @@ -29,6 +35,15 @@ def _get_unique_openapi_token(self):
openapi_token = str(uuid.uuid4())
return openapi_token

def is_the_same_user(self):
for record in self:
record.is_same_user = self.id == self.env.uid

@api.model
def reset_all_openapi_tokens(self):
self.search([]).reset_openapi_token()





1 change: 1 addition & 0 deletions openapi/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ manager_access_openapi_log,access_openapi_log,model_openapi_log,openapi.group_ma
manager_access_openapi_namespace,access_openapi_namespace,model_openapi_namespace,openapi.group_manager,1,1,1,1
manager_access_openapi_access,access_openapi_access,model_openapi_access,openapi.group_manager,1,1,1,1
manager_access_openapi_access_create_context,access_openapi_access_create_context,model_openapi_access_create_context,openapi.group_manager,1,1,1,1
manager_access_openapi_user_token,access_openapi_user_token,base.view_users_simple_form,openapi.group_manager,0,0,0,0
29 changes: 29 additions & 0 deletions openapi/views/openapi_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- <record id="view_managers_simple_form" model="ir.ui.view">
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_managers_simple_form"></field>
<field name="arch" type="xml">
<xpath expr="//field[@name='mobile']" position="after">
<field name="name"/>
<field name="is_same_user" invisible="1"/>
<field name="openapi_token" attrs="{'invisible': [('is_same_user', '=', False)]}"/>
</xpath>
</field>
</record> -->

<record model="ir.ui.view" id="ir_exports_form_view">
<field name="name">ir.exports.form</field>
<field name="model">ir.exports</field>
Expand Down Expand Up @@ -217,13 +229,30 @@
<tree>
<field name="name" />
</tree>
<form>
<field name="name"/>
<field name="is_same_user" invisible="1"/>
<field name="openapi_token" attrs="{'invisible': [('is_same_user', '=', False)]}"/>
</form>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="view_users_manager_form" model="ir.ui.view">
<field name="name">openapi.namespace.managerview</field>
<field name="model">openapi.namespace</field>
<field name="inherit_id" ref="openapi.namespace_form_view"></field>
<field name="group_ids" eval="[(4, ref('openapi.group_manager'))]"></field>
<field name="arch" type="xml">
<!-- <xpath expr="//notebook/page/field[@name='user_ids']/form/field[@name='openapi_token']" position="attributes"> -->
<xpath expr="//field[@name='is_same_user']" position="after">
<field name="openapi_token" groups='openapi.group_manager' attrs="{'invisible': [('is_same_user', '=', True)]}"/>
</xpath>
</field>
</record>
<record id='openapi_namespace_model_view_tree' model='ir.ui.view'>
<field name="name">openapi.namespace.tree</field>
<field name="model">openapi.namespace</field>
Expand Down