-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from dibik96/17.0-develop
SR-123: ODK app user listed in registration portal user view
- Loading branch information
Showing
18 changed files
with
702 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
======================== | ||
Registration Portal User | ||
======================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:925a4bc0a62b70aa19178851792a6a4900f707189dd64fbe37d9323cf52de1d7 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/github-OpenG2P%2Fopeng2p--social--registry-lightgray.png?logo=github | ||
:target: https://github.com/OpenG2P/openg2p-social-registry/tree/17.0-develop/g2p_registration_portal_user | ||
:alt: OpenG2P/openg2p-social-registry | ||
|
||
|badge1| |badge2| | ||
|
||
G2P Registration Portal User | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OpenG2P/openg2p-social-registry/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/OpenG2P/openg2p-social-registry/issues/new?body=module:%20g2p_registration_portal_user%0Aversion:%2017.0-develop%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 | ||
~~~~~~~ | ||
|
||
* OpenG2P | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
`OpenG2P <https://openg2p.org>`__ donated the original code to the project. | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `OpenG2P/openg2p-social-registry <https://github.com/OpenG2P/openg2p-social-registry/tree/17.0-develop/g2p_registration_portal_user>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "Registration Portal User", | ||
"category": "G2P", | ||
"version": "17.0.1.0.0", | ||
"sequence": 1, | ||
"author": "OpenG2P", | ||
"website": "https://openg2p.org", | ||
"license": "Other OSI approved licence", | ||
"depends": ["g2p_service_provider_portal_base", "g2p_odk_importer"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/registration_user_view.xml", | ||
"views/odk_app_user.xml", | ||
], | ||
"assets": { | ||
"web.assets_frontend": [], | ||
"web.assets_common": [], | ||
"website.assets_wysiwyg": [], | ||
}, | ||
"application": True, | ||
"installable": True, | ||
"auto_install": False, | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import res_partner | ||
from . import odk_app_user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ODKAppUser(models.Model): | ||
_name = "odk.app.user" | ||
_description = "ODK App User" | ||
|
||
name = fields.Char(string="ODK App User Name") | ||
odk_user_id = fields.Integer(string="ODK App User ID") | ||
partner_id = fields.Many2one("res.partner", string="Partner") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import json | ||
import logging | ||
|
||
import requests | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError, ValidationError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
odk_config_id = fields.Many2one("odk.config", string="ODK Config") | ||
odk_app_user = fields.Many2one("odk.app.user", string="ODK App User") | ||
session = fields.Char(string="Session Token", readonly=True) | ||
|
||
@api.onchange("odk_config_id") | ||
def _onchange_odk_config_id(self): | ||
self.odk_app_user = [ | ||
5, | ||
] | ||
if self.odk_config_id: | ||
base_url = self.odk_config_id.base_url | ||
project_id = self.odk_config_id.project | ||
username = self.odk_config_id.username | ||
password = self.odk_config_id.password | ||
self._login(base_url, username, password) | ||
if self.session: | ||
app_users = self._fetch_app_users(base_url, project_id) | ||
_logger.info( | ||
"LOG----->ODK APP USER:%s" | ||
% [f"{user['id']} -{user['displayName']}" for user in app_users] | ||
) | ||
return {"domain": {"odk_app_user": [("id", "in", [user["id"] for user in app_users])]}} | ||
else: | ||
return {"domain": {"odk_app_user": []}} | ||
|
||
def _login(self, base_url, username, password): | ||
login_url = f"{base_url}/v1/sessions" | ||
headers = {"Content-Type": "application/json"} | ||
data = json.dumps({"email": username, "password": password}) | ||
try: | ||
response = requests.post(login_url, headers=headers, data=data, timeout=10) | ||
response.raise_for_status() | ||
if response.status_code == 200: | ||
self.session = response.json()["token"] | ||
except Exception as e: | ||
_logger.exception("Login failed: %s", e) | ||
raise ValidationError(f"Login failed: {e}") from e | ||
|
||
def _fetch_app_users(self, base_url, project_id): | ||
url = f"{base_url}/v1/projects/{project_id}/app-users" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"X-Extended-Metadata": "true", | ||
"Authorization": f"Bearer {self.session}", | ||
} | ||
response = requests.get(url, headers=headers, timeout=10) | ||
|
||
if response.status_code == 200: | ||
app_users_data = response.json() | ||
query = """ | ||
DELETE FROM odk_app_user WHERE partner_id = %s | ||
""" | ||
self.env.cr.execute(query, (self.id.origin or self.id,)) | ||
|
||
for user in app_users_data: | ||
self.env["odk.app.user"].create( | ||
{"name": user["displayName"], "odk_user_id": user["id"], "partner_id": self.id.origin} | ||
) | ||
return app_users_data | ||
else: | ||
raise UserError(_("Failed to fetch app users")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`OpenG2P <https://openg2p.org>`__ donated the original code to the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
G2P Registration Portal User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_odk_app_user,odk_app_user_name,model_odk_app_user,,1,1,1,1 |
Oops, something went wrong.