Browse Source

Merge d08cb459f4 into ad79aa45cf

pull/728/merge
Sudhir Arya 5 years ago
committed by GitHub
parent
commit
9efe82b375
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 76
      web_validation_dialog/README.rst
  2. 4
      web_validation_dialog/__init__.py
  3. 25
      web_validation_dialog/__manifest__.py
  4. 4
      web_validation_dialog/models/__init__.py
  5. 17
      web_validation_dialog/models/res_company.py
  6. BIN
      web_validation_dialog/static/description/icon.png
  7. BIN
      web_validation_dialog/static/description/img/click_invoice.png
  8. BIN
      web_validation_dialog/static/description/img/dialog.png
  9. BIN
      web_validation_dialog/static/description/img/res_company.png
  10. 132
      web_validation_dialog/static/src/js/web_validation_dialog.js
  11. 17
      web_validation_dialog/static/src/xml/web_validation_dialog.xml
  12. 4
      web_validation_dialog/tests/__init__.py
  13. 30
      web_validation_dialog/tests/test_web_validation_dialog.py
  14. 15
      web_validation_dialog/views/res_company.xml
  15. 22
      web_validation_dialog/views/res_users.xml
  16. 12
      web_validation_dialog/views/templates.xml

76
web_validation_dialog/README.rst

@ -0,0 +1,76 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=====================
Web Validation Dialog
=====================
This module provides the functionality to generalize validation on any type of button.
* Offers company level validation & restricted access.
* Enhances webpage validation at the interface level.
Configuration
=============
To configure this module, you need to:
* Configure the *Security Code* in Company record.
Usage
=====
* Configure security code to buttons from company configuration menu.
.. image:: /web_validation_dialog/static/description/img/res_company.png
:width: 70%
* Pass the options and confirm attributes inside the button as below:
* ``<button name="method_name" type="object" string="Create Invoice" options='{"security": "security_field"}'/>``
* As shown in the image, here options attribute is passed to "Create Invoice" button.
.. image:: /web_validation_dialog/static/description/img/click_invoice.png
:width: 70%
* So on clicking **"Create Invoice"** button a dialog box will open that will ask for Security Code.
* On entering correct Security Code, user will be redirected to next step.
.. image:: /web_validation_dialog/static/description/img/dialog.png
:width: 70%
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

4
web_validation_dialog/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

25
web_validation_dialog/__manifest__.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2017 Serpent Consulting Services Pvt. Ltd. (http://www.serpentcs.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Web Validation Dialog',
'version': '10.0.1.0.0',
'category': 'Web',
'summary': 'Web Validation Dialog',
'author': 'Serpent Consulting Services Pvt. Ltd., '
'Odoo Community Association (OCA)',
'license': 'LGPL-3',
'website': 'https://github.com/OCA/web',
'depends': [
'web',
],
'data': [
'views/res_company.xml',
'views/res_users.xml',
'views/templates.xml',
],
'qweb': [
'static/src/xml/web_validation_dialog.xml',
],
'installable': True,
}

4
web_validation_dialog/models/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_company

17
web_validation_dialog/models/res_company.py

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# © 2017 Serpent Consulting Services Pvt. Ltd. (http://www.serpentcs.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
security_code = fields.Char('Security Code')
@api.model
def check_security(self, vals):
fields = vals.get('field').encode('ascii', 'ignore')
company_id = vals.get('companyId')
return company_id and\
self.browse(company_id)[fields] == vals.get('password') or False

BIN
web_validation_dialog/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

BIN
web_validation_dialog/static/description/img/click_invoice.png

After

Width: 1315  |  Height: 659  |  Size: 74 KiB

BIN
web_validation_dialog/static/description/img/dialog.png

After

Width: 1214  |  Height: 284  |  Size: 43 KiB

BIN
web_validation_dialog/static/description/img/res_company.png

After

Width: 1183  |  Height: 492  |  Size: 54 KiB

132
web_validation_dialog/static/src/js/web_validation_dialog.js

@ -0,0 +1,132 @@
odoo.define("web_validation_dialog.ValidationDialog", function (require) {
"use strict";
var core = require('web.core');
var FormWidget = require('web.form_widgets');
var Dialog = require('web.Dialog');
var Model = require('web.DataModel');
var framework = require('web.framework');
var pyeval = require('web.pyeval');
var QWeb = core.qweb;
var _t = core._t;
FormWidget.WidgetButton.include({
/*
* @param field_manager: get field Value
* @param node: get node value
*/
init: function (field_manager, node) {
this._super(field_manager, node);
this.options = pyeval.py_eval(this.node.attrs.options || '{}');
this.is_dialog_security =
this.options.security ? this.options.security : false;
},
/*
* @return this function return on_confirmed method
*/
exec_action: function () {
var self = this;
if (self.node.attrs.confirm && self.is_dialog_security) {
Dialog.confirm(self, self.node.attrs.confirm, {
buttons: [
{
text: _t("Ok"),
classes: 'btn-primary',
click: function () {
this.close();
self.open_pincode_dialog();
},
},
{
text: _t('Cancel'),
close: true,
},
],
});
} else if (self.node.attrs.confirm) {
var def = $.Deferred();
Dialog.confirm(self,
self.node.attrs.confirm,
{
confirm_callback: self.on_confirmed,
}
).on("closed", null, function () {
def.resolve();
});
return def.promise();
} else {
return self.on_confirmed();
}
},
execute_action: function () {
var self = this;
if (!this.node.attrs.special) {
return this.view.recursive_save().then(self.exec_action());
}
return self.exec_action();
},
open_pincode_dialog : function () {
var self = this;
new Dialog(self, {
title: _t('Validation'),
size : "small",
$content: QWeb.render('DialogValidation'),
buttons: [
{
text: _t("Ok"),
classes: 'btn-primary',
click: function () {
var curr_obj = this;
var password = this.$el.find("#pincode").val();
if (password) {
framework.blockUI();
var check_pincode =
self.validate_pincode(
self.is_dialog_security, password);
check_pincode.done(function (result) {
framework.unblockUI();
if (result) {
curr_obj.close();
self.on_confirmed();
} else {
Dialog.alert(
self, _t("Invalid or Wrong" +
"Password! Contact your" +
"Administrator."));
}
}).fail(function () {
framework.unblockUI();
Dialog.alert(
self, _t("Either the password is" +
"wrong or the connection is lost!" +
"Contact your Administrator."));
});
} else {
Dialog.alert(
self, _t("Please Enter the Password."));
}
},
},
{
text: _t('Cancel'), close: true,
},
],
}).open();
},
validate_pincode : function (field, value) {
var self = this;
var data_vals = {
"field": field,
"password": value,
"companyId": self.session.company_id,
};
return new Model("res.company").call("check_security", [data_vals]);
},
});
});

17
web_validation_dialog/static/src/xml/web_validation_dialog.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="DialogValidation">
<div class="container">
<div class="col-md-3">
<div class="form-group">
<label class="control-label col-md-2" for="pincode"
style="margin-left:-13px;">Password:</label>
<input name="password" type="password" class="form-control" id="pincode"
autofocus="autofocus"/>
</div>
</div>
</div>
</t>
</templates>

4
web_validation_dialog/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Serpent Consulting Services Pvt. Ltd. (http://www.serpentcs.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_web_validation_dialog

30
web_validation_dialog/tests/test_web_validation_dialog.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# © 2017 Serpent Consulting Services Pvt. Ltd. (http://www.serpentcs.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
class TestWebValidationDialog(common.TransactionCase):
def setUp(self):
super(TestWebValidationDialog, self).setUp()
self.company = self.env.ref('base.main_company')
self.company.security_code = 'pwd'
def test_check_security(self):
res = self.company.check_security({
'companyId': self.company.id,
'password': 'pwd',
'field': 'security_code',
})
self.assertTrue(res)
def test_invalid_check_security(self):
self.company.security_code = '12345'
res = self.company.check_security({
'companyId': self.company.id,
'password': '123',
'field': 'security_code',
})
self.assertFalse(
res, 'Invalid or Wrong Password! Contact your Administrator.')

15
web_validation_dialog/views/res_company.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_res_company_validation_dialog_form" model="ir.ui.view">
<field name="name">res.company.form.validation</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<field name="website" position="after">
<field name="security_code" password="True"/>
</field>
</field>
</record>
</odoo>

22
web_validation_dialog/views/res_users.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_res_users_validation_form" model="ir.ui.view">
<field name="name">res.users.validation.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<button name="%(base.change_password_wizard_action)d" position="attributes">
<attribute name="invisible">1</attribute>
</button>
<button name="%(base.change_password_wizard_action)d" position="after">
<button string="Change Password" type="action"
confirm="Do you want to Change your password?"
name="%(base.change_password_wizard_action)d"
help="Change the user password."
options='{"security": "security_code"}'/>
</button>
</field>
</record>
</odoo>

12
web_validation_dialog/views/templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="web_validation_dialog_assets_backend" name="Web Validation Dialog Assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_validation_dialog/static/src/js/web_validation_dialog.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save