Skip to content

Commit

Permalink
Current
Browse files Browse the repository at this point in the history
  • Loading branch information
lasley committed Apr 19, 2017
1 parent 140748f commit f55b4f4
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 20 deletions.
2 changes: 1 addition & 1 deletion red_october/fields/red_october_char.py
Expand Up @@ -34,7 +34,7 @@ def read(self, records):
data = {att.res_id: att.datas for att in attachments}
_logger.debug(data)
for record in records:
record._cache[self.name] = data.get(record.id, False)
record._cache[self.name] = data.get(record.id, self.null())

def write(self, records, value):
# retrieve the attachments that stores the value, and adapt them
Expand Down
87 changes: 87 additions & 0 deletions red_october/static/src/js/dialog_vault_new.js
@@ -0,0 +1,87 @@
/* Copyright 2016-2017 LasLabs Inc.
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
*/

odoo.define('red_october.DialogVaultNew', function (require) {
"use strict";

var core = require('web.core');
var Dialog = require('web.Dialog');
var mixins = require('red_october.mixins');
var Model = require('web.DataModel');

var _t = core._t;

/* It allows a user to get their profile password.
Attributes:
*/
var DialogVaultNew = Dialog.extend(
mixins.dialogMixin,
mixins.formMixin,
{

templateInner: 'red_october.FormVaultNew',

options: {
title: _t('Enter Vault Info'),
buttons: [
{
text: _t('Submit'),
classes: 'btn btn-primary',
close: true,
click: function(event){
this.$form.submit();
},
},
{
text: _t('Cancel'),
classes: 'btn btn-default',
close: true,
click: function () {
this.resetUI();
}
},
],
},

handleSubmit: function (event) {

event.preventDefault();

var $target = $(event.target);
var $parent = this.getParent();
var arrData = $target.serializeArray();
var objData = {};
var Vaults = new Model('red.october.vault');

_.each(arrData, function(data) {
objData[data.name] = data.value;
})

var vault = Vaults.call(
'create',
[{
'host': objData.host,
'port': objData.port,
'verify_cert': objData.verify_cert || false,
}]
);
vault.done(
this.proxy(function (record) {
$parent.$el.trigger(
'activateVault',
record,
objData.is_active
);
})
);
return vault;
},

}
);

return DialogVaultNew;

});
31 changes: 31 additions & 0 deletions red_october/static/src/js/widget_profile_manage.js
Expand Up @@ -14,6 +14,7 @@ odoo.define('red_october.WidgetProfileManage', function (require) {
var DialogPasswordChange = require('red_october.DialogPasswordChange');
var DialogPasswordGet = require('red_october.DialogPasswordGet');
var DialogVaultDelegate = require('red_october.DialogVaultDelegate');
var DialogVaultNew = require('red_october.DialogVaultNew');

var ERROR_PASSWORD = 'Wrong Password';

Expand All @@ -35,6 +36,7 @@ odoo.define('red_october.WidgetProfileManage', function (require) {
'decrypt': 'doDecrypt',
'encrypt': 'doEncrypt',
'decrementDelegation': 'decrementDelegation',
'activateVault': 'activateVault',
},

/* It sets the widget properties */
Expand Down Expand Up @@ -64,6 +66,9 @@ odoo.define('red_october.WidgetProfileManage', function (require) {
this.$el.find('#roProfilePasswordGet').click(
this.proxy(this.clickProfilePasswordGet)
);
this.$el.find('#roVaultNew').click(
this.proxy(this.clickVaultNew)
);
},

/* Load user profiles from the server, add them to the instance, then re-render. */
Expand Down Expand Up @@ -138,6 +143,10 @@ odoo.define('red_october.WidgetProfileManage', function (require) {
new DialogPasswordGet(this).open();
},

clickVaultNew: function (event) {
new DialogVaultNew(this).open();
},

clickVaultDelegate: function (event) {
var dialog = new DialogVaultDelegate(
this,
Expand Down Expand Up @@ -197,6 +206,28 @@ odoo.define('red_october.WidgetProfileManage', function (require) {
return delegations;
},

activateVault: function (event, record, is_active) {
var Wizards = new Model('red.october.vault.activate');
Wizards.call(
'create',
[{
'is_active': is_active || false,
'vault_ids': [[(6, 0, [record])]],
'admin_user_id':
}]
)
},

upsertProfile: function (user, vaults) {
var Users = new Model('red.october.user');
Users.call(
'create',
[{

}]
)
},

loadDelegations: function(records) {
_.each(
records,
Expand Down
75 changes: 75 additions & 0 deletions red_october/static/src/xml/form_vault_new.xml
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2016-2017 LasLabs Inc.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
-->

<template>

<t t-name="red_october.FormVaultNew">
<form id="roVaultNewForm"
method="POST"
>
<input type="hidden"
name="csrf_token"
t-att-value="csrf_token" />
<div class="form-group">
<label for="host">
Host
</label>
<input type="text"
name="host"
class="form-control"
required="" />
</div>
<div class="form-group">
<label for="port">
Port
</label>
<input type="number"
name="port"
class="form-control"
value="8080"
required="" />
</div>
<div class="form-group">
<label for="verify_cert">
Verify Cert
</label>
<input type="checkbox"
name="verify_cert"
class="form-control"
checked="" />
</div>
<div class="form-group">
<label for="is_active">
Is Active
</label>
<input type="checkbox"
name="is_active"
class="form-control" />
</div>
<div class="form-group">
<label for="password">
Password
</label>
<input type="password"
name="password"
class="form-control"
required="" />
</div>
<div class="form-group">
<label for="password">
Confirm Password
</label>
<input type="password"
name="confirm_password"
class="form-control"
required="" />
</div>
<div class="form_result text-center" />
</form>
</t>

</template>
3 changes: 3 additions & 0 deletions red_october/static/src/xml/widget_profile_choose.xml
Expand Up @@ -25,6 +25,9 @@
<a href="#">Change Password</a>
</li>
<li class="divider" />
<li id="roVaultNew" class="text-center">
<a href="#">New Vault</a>
</li>
<li class="dropdown-header" id="roVaultDelegateHeader">
Delegate Rights
</li>
Expand Down
2 changes: 2 additions & 0 deletions red_october/views/assets.xml
Expand Up @@ -25,6 +25,8 @@
src="/red_october/static/src/js/dialog_password_get.js" />
<script type="application/javascript"
src="/red_october/static/src/js/dialog_vault_delegate.js" />
<script type="application/javascript"
src="/red_october/static/src/js/dialog_vault_new.js" />

</xpath>

Expand Down
2 changes: 1 addition & 1 deletion red_october/views/red_october_vault.xml
Expand Up @@ -11,7 +11,7 @@
<field name="name">red.october.vault.tree</field>
<field name="model">red.october.vault</field>
<field name="arch" type="xml">
<tree string="Crypto Vaults">
<tree string="Crypto Vaults" create="false">
<field name="name" />
<field name="host" />
<field name="port" />
Expand Down
32 changes: 14 additions & 18 deletions red_october/wizards/red_october_vault_activate.py
Expand Up @@ -51,37 +51,33 @@ def _default_vault_ids(self):

@api.multi
def _check_vault_ids(self):
""" It should not allow active vaults. """
""" Do not allow active vaults. """
for record in self:
if len(record.vault_ids.filtered(lambda r: r.is_active)):
raise ValidationError(_(
'Cannot reinitialize a vault.'
))

@api.multi
def action_save(self):
for record in self:
if not record.is_active:
record.activate_vault()
if self.env.user != record.admin_user_id.user_id:
self.env['red.october.user'].upsert_by_user(
vaults=record.vault_ids,
)
def activate_vault(self, admin_password, admin_password_confirm):
""" Activate a vault with the admin user and given password. """

@api.multi
def activate_vault(self):
""" It activates a vault with the given admin user and password. """
self.ensure_one()
if self.admin_password != self.admin_password_confirm:

if admin_password != admin_password_confirm:
raise ValidationError(_(
'Passwords do not match.',
))

if self.is_active:
self.vault_ids.write({
'is_active': True,
})
self.unlink()
return
for vault in self.vault_ids:
vault.activate(self.admin_user_id, self.admin_password)
self.unlink()
else:
for vault in self.vault_ids:
vault.activate(self.admin_user_id, admin_password)

if self.env.user != self.admin_user_id.user_id:
self.env['red.october.user'].upsert_by_user(
vaults=self.vault_ids,
)

0 comments on commit f55b4f4

Please sign in to comment.