Skip to content

Commit

Permalink
Merge pull request #200 from lalithkota/15.0-develop
Browse files Browse the repository at this point in the history
Payment Files: Removed crypto key set in favour of encryption provide…
  • Loading branch information
shibu-narayanan authored Mar 1, 2024
2 parents fb87ec8 + 5e81bbe commit b961678
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 267 deletions.
19 changes: 1 addition & 18 deletions g2p_entitlement_voucher/models/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
_logger = logging.getLogger(__name__)


class G2PCryptoKeySet(models.Model):
_inherit = "g2p.crypto.key.set"

voucher_manager_id = fields.Many2one(
"g2p.program.entitlement.manager.voucher", ondelete="cascade"
)


class EntitlementManager(models.Model):
_inherit = "g2p.program.entitlement.manager"

Expand All @@ -33,21 +25,12 @@ class G2PVoucherEntitlementManager(models.Model):
_inherit = "g2p.program.entitlement.manager.default"
_description = "Voucher Entitlement Manager"

# This is a one2one relation
crypto_key_set = fields.One2many("g2p.crypto.key.set", "voucher_manager_id")

auto_generate_voucher_on_approval = fields.Boolean(default=True)

voucher_file_config = fields.Many2one("g2p.payment.file.config")

voucher_document_store = fields.Many2one("storage.backend", required=True)

@api.model
def create(self, values):
if not values.get("crypto_key_set", None):
values["crypto_key_set"] = [(0, 0, {})]
return super(G2PVoucherEntitlementManager, self).create(values)

def open_voucher_config_form(self):
if self.voucher_file_config:
return {
Expand Down Expand Up @@ -137,7 +120,7 @@ def _generate_vouchers(self, entitlements):
qrcode_config.render_datas_and_store(
"g2p.entitlement",
entitlements.ids,
self.crypto_key_set[0],
self.get_encryption_provider(),
res_id_field_in_qrcode_model="entitlement_id",
)

Expand Down
4 changes: 0 additions & 4 deletions g2p_entitlement_voucher/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

g2p_payment_files.access_crypto_key_set_admin,access_crypto_key_set_admin,g2p_payment_files.model_g2p_crypto_key_set,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_payment_files.access_crypto_key_set_manager,access_crypto_key_set_manager,g2p_payment_files.model_g2p_crypto_key_set,g2p_programs.g2p_program_manager,1,1,1,0
g2p_payment_files.access_crypto_key_set_validator,access_crypto_key_set_validator,g2p_payment_files.model_g2p_crypto_key_set,g2p_programs.g2p_program_validator,1,0,0,0

g2p_entitlement_voucher.access_entitlement_manager_voucher_admin,access_entitlement_manager_voucher_admin,g2p_entitlement_voucher.model_g2p_program_entitlement_manager_voucher,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_entitlement_voucher.access_entitlement_manager_voucher_manager,access_entitlement_manager_voucher_manager,g2p_entitlement_voucher.model_g2p_program_entitlement_manager_voucher,g2p_programs.g2p_program_manager,1,1,1,0
g2p_entitlement_voucher.access_entitlement_manager_voucher_validator,access_entitlement_manager_voucher_validator,g2p_entitlement_voucher.model_g2p_program_entitlement_manager_voucher,g2p_programs.g2p_program_validator,1,0,0,0
1 change: 0 additions & 1 deletion g2p_import_dci_api/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"version": "15.0.1.1.0",
"author": "OpenG2P",
"development_status": "Alpha",
"external_dependencies": {"python": ["PyLD", "pyjwt>=2.4.0"]},
"website": "https://openg2p.org",
"license": "Other OSI approved licence",
"depends": [
Expand Down
11 changes: 0 additions & 11 deletions g2p_payment_cash/models/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ def _selection_manager_ref_id(self):
return selection


class G2PCryptoKeySet(models.Model):
_inherit = "g2p.crypto.key.set"

cash_payment_manager_id = fields.Many2one(
"g2p.program.payment.manager.cash", ondelete="cascade"
)


class G2PPaymentManagerCash(models.Model):
_name = "g2p.program.payment.manager.cash"
_inherit = "g2p.program.payment.manager.file"
Expand All @@ -42,9 +34,6 @@ class G2PPaymentManagerCash(models.Model):
ondelete="cascade",
)

# This is a one2one relation
crypto_key_set = fields.One2many("g2p.crypto.key.set", "cash_payment_manager_id")

# This will just mark all the payments as done when then cash is given out
def _send_payments(self, batches):
if not batches:
Expand Down
2 changes: 0 additions & 2 deletions g2p_payment_files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.
from . import models
from . import controllers
from . import services
4 changes: 1 addition & 3 deletions g2p_payment_files/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
"depends": [
"g2p_programs",
"g2p_program_documents",
"g2p_programs_rest_api",
"g2p_encryption",
"mail",
],
"external_dependencies": {
"python": [
"base45",
"cryptography",
"cose",
"python-jose",
"python-barcode",
"pdfkit",
"qrcode",
Expand Down
1 change: 0 additions & 1 deletion g2p_payment_files/controllers/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions g2p_payment_files/controllers/payments.py

This file was deleted.

1 change: 0 additions & 1 deletion g2p_payment_files/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import payment_key_set
from . import payment_file_config
from . import payment_file_qrcode_config
from . import payment_manager
Expand Down
13 changes: 4 additions & 9 deletions g2p_payment_files/models/payment_file_qrcode_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import qrcode
import qrcode.image.svg
from barcode import Code128 # pylint: disable=[W7936]
from jose import jwt # pylint: disable=[W7936]

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
Expand Down Expand Up @@ -64,7 +63,7 @@ def render_datas_and_store(
self,
res_model,
res_ids,
crypto_ket_set_id,
encryption_provider,
res_id_field_in_qrcode_model=None,
template_engine="inline_template",
):
Expand All @@ -73,7 +72,7 @@ def render_datas_and_store(
self.body_string,
res_model,
res_ids,
crypto_ket_set_id,
encryption_provider,
template_engine=template_engine,
)
create_vals = []
Expand All @@ -95,7 +94,7 @@ def _render_data(
template_src,
res_model,
res_ids,
key_set,
encryption_provider,
template_engine="inline_template",
):
RenderMixin = self.env["mail.render.mixin"]
Expand All @@ -112,13 +111,9 @@ def _render_data(
# the following should throw exception if not json
json.loads(datas[res_id])
elif data_type == "jwt":
kid = key_set.name
priv_key = key_set.priv_key.encode()
for res_id in res_ids:
payload = json.loads(datas[res_id])
datas[res_id] = jwt.encode(
payload, priv_key, algorithm="RS256", headers={"kid": kid}
)
datas[res_id] = encryption_provider.jwt_sign(payload)
return datas


Expand Down
146 changes: 0 additions & 146 deletions g2p_payment_files/models/payment_key_set.py

This file was deleted.

20 changes: 10 additions & 10 deletions g2p_payment_files/models/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ class G2PFilesPaymentManager(models.Model):

payment_file_config_ids = fields.Many2many("g2p.payment.file.config")

# This is a one2one relation
crypto_key_set = fields.One2many("g2p.crypto.key.set", "file_payment_manager_id")

@api.model
def create(self, values):
if not values.get("crypto_key_set", None):
values["crypto_key_set"] = [(0, 0, {})]
return super(G2PFilesPaymentManager, self).create(values)
encryption_provider_id = fields.Many2one("g2p.encryption.provider")

batch_tag_ids = fields.Many2many(
"g2p.payment.batch.tag",
Expand Down Expand Up @@ -83,7 +76,7 @@ def _prepare_payments(self, cycle, entitlements):
qrcode_config.render_datas_and_store(
render_res_model,
render_res_ids,
self.crypto_key_set[0],
self.get_encryption_provider(),
res_id_field_in_qrcode_model,
)

Expand All @@ -106,7 +99,7 @@ def _prepare_payments(self, cycle, entitlements):
qrcode_config.render_datas_and_store(
"g2p.payment",
payments.ids,
self.crypto_key_set[0],
self.get_encryption_provider(),
res_id_field_in_qrcode_model="payment_id",
)

Expand All @@ -122,6 +115,13 @@ def _prepare_payments(self, cycle, entitlements):
def _send_payments(self, batches):
raise NotImplementedError()

def get_encryption_provider(self):
self.ensure_one()
prov = self.encryption_provider_id
if not prov:
prov = self.env.ref("g2p_encryption.encryption_provider_default")
return prov


class G2PPaymentBatchTag(models.Model):
_inherit = "g2p.payment.batch.tag"
Expand Down
4 changes: 0 additions & 4 deletions g2p_payment_files/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

g2p_payment_files.access_crypto_key_set_admin,access_crypto_key_set_admin,g2p_payment_files.model_g2p_crypto_key_set,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_payment_files.access_crypto_key_set_manager,access_crypto_key_set_manager,g2p_payment_files.model_g2p_crypto_key_set,g2p_programs.g2p_program_manager,1,1,1,0
g2p_payment_files.access_crypto_key_set_user,access_crypto_key_set_user,g2p_payment_files.model_g2p_crypto_key_set,base.group_user,1,0,0,0

g2p_payment_files.access_file_config_admin,access_file_config_admin,g2p_payment_files.model_g2p_payment_file_config,g2p_registry_base.group_g2p_admin,1,1,1,1
g2p_payment_files.access_file_config_manager,access_file_config_manager,g2p_payment_files.model_g2p_payment_file_config,g2p_programs.g2p_program_manager,1,1,1,0
g2p_payment_files.access_file_config_user,access_file_config_user,g2p_payment_files.model_g2p_payment_file_config,base.group_user,1,0,0,0
Expand Down
1 change: 0 additions & 1 deletion g2p_payment_files/services/__init__.py

This file was deleted.

Loading

0 comments on commit b961678

Please sign in to comment.