Skip to content

Commit

Permalink
Added encryption and decryption in documents
Browse files Browse the repository at this point in the history
  • Loading branch information
vin0dkhichar committed Dec 17, 2024
1 parent 41d0106 commit 6ed5969
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
15 changes: 14 additions & 1 deletion g2p_registry_documents/models/document_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
from odoo import fields, models
from odoo import api, fields, models


class G2PDocumentRegistry(models.Model):
_inherit = "storage.file"

registrant_id = fields.Many2one("res.partner")

is_encrypted = fields.Boolean(string="Encrypted", default=False)

@api.model
def create(self, vals):
is_encrypt_fields = (
self.env["ir.config_parameter"]
.sudo()
.get_param("g2p_registry_encryption.encrypt_registry", default=False)
)
if is_encrypt_fields:
vals["is_encrypted"] = True
return super().create(vals)

def get_record(self):
for record in self:
return {
Expand Down
37 changes: 35 additions & 2 deletions g2p_registry_documents/static/src/js/preview_document.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
/** @odoo-module **/
import {Component, xml} from "@odoo/owl";
import {Component, onWillStart, xml} from "@odoo/owl";
import {registry} from "@web/core/registry";
import {useFileViewer} from "@web/core/file_viewer/file_viewer_hook";
import {useService} from "@web/core/utils/hooks";

class Widgetpreview extends Component {
static template = xml`<button class="btn btn-primary" icon="fa-file-text-o" t-on-click="clickPreview">Preview</button>`;
static template = xml`
<t>
<button
class="btn btn-primary"
icon="fa-file-text-o"
t-on-click="clickPreview"
t-if="canPreview"
>
Preview
</button>
<span t-else="">Encrypted</span>
</t>
`;

setup() {
super.setup();
this.fileViewer = useFileViewer();
this.store = useService("mail.store");
this.rpc = useService("rpc");

onWillStart(async () => {
this.decryptRegistry = await this._getDecryptRegistryValue();
this.canPreview = this._checkPreviewConditions();
});
}

async _getDecryptRegistryValue() {
const result = await this.rpc("/web/dataset/call_kw/ir.config_parameter/get_param", {
model: "ir.config_parameter",
method: "get_param",
args: ["g2p_registry_encryption.decrypt_registry"],
kwargs: {},
});
return result === "True";
}

_checkPreviewConditions() {
const is_encrypted = this.props.record.data.is_encrypted;
const decrypt_registry = this.decryptRegistry;
return !is_encrypted || (is_encrypted && decrypt_registry);
}

clickPreview(ev) {
Expand Down
2 changes: 2 additions & 0 deletions g2p_registry_documents/views/registrant_document_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<field name="slug" string="Name" />
<field name="file_size" />
<field name="file_type" />
<field name="is_encrypted" column_invisible="True" />
<widget name="action_preview" />
</tree>
</field>
Expand All @@ -34,6 +35,7 @@
<field name="slug" string="Name" />
<field name="file_size" />
<field name="file_type" />
<field name="is_encrypted" column_invisible="True" />
<widget name="action_preview" />
</tree>
</field>
Expand Down

0 comments on commit 6ed5969

Please sign in to comment.