Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the encryption and decryption in documents #219

Closed
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
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
17 changes: 9 additions & 8 deletions g2p_registry_encryption/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ def _fetch_query(self, query, fields):
)
if not is_decrypt_fields:
return res
for record in self:
is_encrypted, encrypted_val = record.get_encrypted_val()[0]
if is_encrypted and encrypted_val:
decrypted_vals = json.loads(prov.decrypt_data(encrypted_val).decode())

for field_name in enc_fields_set:
if field_name in decrypted_vals and field_name in record and record[field_name]:
self.env.cache.set(record, self._fields[field_name], decrypted_vals[field_name])
if len(self) == 1 and self.is_registrant:
for record in self:
is_encrypted, encrypted_val = record.get_encrypted_val()[0]
if is_encrypted and encrypted_val:
decrypted_vals = json.loads(prov.decrypt_data(encrypted_val).decode())

for field_name in enc_fields_set:
if field_name in decrypted_vals and field_name in record and record[field_name]:
self.env.cache.set(record, self._fields[field_name], decrypted_vals[field_name])
return res

def get_encrypted_val(self):
Expand Down
2 changes: 1 addition & 1 deletion g2p_registry_encryption/views/res_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</setting>
<setting
string="Decrypt Registry Config"
help="By choosing this, you are consenting to decrypting fields on registry. So be careful"
help="By choosing this, you are consenting to display the decrypted fields of registrant. So be careful"
>
<field name="decrypt_registry" />
</setting>
Expand Down
Loading