[ADD] Online delayed release support

This commit is contained in:
Hiren Jungi 2018-11-05 16:15:06 +05:30
parent 0f3b6cc58a
commit 091dbcc487
6 changed files with 83 additions and 22 deletions

View File

@ -134,7 +134,7 @@ class ResConfigSettings(models.TransientModel):
if self.activator_key and self.contract_id:
try:
set_param = self.env['ir.config_parameter'].sudo().set_param
binary = json.loads(base64.decodestring(self.activator_key)).encode('ascii')
binary = json.loads(base64.decodestring(self.activator_key).decode('utf-8')).encode('ascii')
binary = base64.decodestring(binary)
enc = json.dumps(decrypt(binary, self.contract_id))
if enc:

View File

@ -1867,13 +1867,44 @@ class ReportController(http.Controller):
class LicensingController(http.Controller):
@http.route('/flectra/licensing', type='http', auth="user")
def download(self, binary='', **kwargs):
filename = '%s.%s' % (FILENAME, EXT)
content = binary
return request.make_response(
content,
headers=[
('Content-Type', 'plain/text' or 'application/octet-stream'),
('Content-Disposition', content_disposition(filename))
]
)
def download(self, contract_id=None, type=None, binary='', **kwargs):
if type == 'offline':
filename = '%s.%s' % (FILENAME, EXT)
content = binary
return request.make_response(
content,
headers=[
('Content-Type', 'plain/text' or 'application/octet-stream'),
('Content-Disposition', content_disposition(filename))
]
)
elif type == 'online':
error = {
'code': 200,
'message': "Invalid License Key",
'data': ''
}
try:
if contract_id:
data = {
'data': binary,
'contract_id': contract_id
}
p = requests.post(
server_url + '/my/contract/validate/online',
params=data,
headers={'Content-type': 'plain/text' or 'application/octet-stream'})
content = json.loads(p.content.decode('utf-8'))
if 'activation_key' in content:
date = datetime.datetime.now() + datetime.timedelta(days=(12 * 30 * 1))
set_param = request.env['ir.config_parameter'].sudo().set_param
set_param('database.expiration_date', date)
set_param('contract.validity',
base64.encodestring(
encrypt(json.dumps(str(date)),str(date))))
if 'error_in_key' in content:
return request.make_response(html_escape(json.dumps(error)))
except Exception as e:
error['code'] = 400
error['message'] = 'Flectra Error!'
return request.make_response(html_escape(json.dumps(error)))

View File

@ -61,17 +61,28 @@ class Http(models.AbstractModel):
currencies = Currency.search([]).read(['symbol', 'position', 'decimal_places'])
return { c['id']: {'symbol': c['symbol'], 'position': c['position'], 'digits': [69,c['decimal_places']]} for c in currencies}
def get_contracted_modules(self, contract_key='', ir_module_module_ids=None):
def get_contracted_modules(self, type=None, contract_key=None, ir_module_module_ids=None):
if ir_module_module_ids:
contract_key = contract_key or ''
contracted_module_list = ir_module_module_ids.mapped('name')
contracts = encrypt(json.dumps(contracted_module_list), contract_key)
warrant = self.env['publisher_warranty.contract'].sudo()._get_message()
warrant.update({
'contracts': contracted_module_list,
'contract_id': contract_key
})
if type != 'online':
contracts = encrypt(json.dumps(warrant), contract_key)
else:
contracts = str.encode(json.dumps(warrant))
return contracts
@api.model
def contract_validate_file(self, contract_id):
ir_module_module_ids = self.env['ir.module.module'].sudo().search(
[('contract_certificate', '!=', False), ('state', '=', 'installed')])
contracts = self.get_contracted_modules(contract_id,ir_module_module_ids)
def contract_validate_file(self, contract_id, type):
contracts = []
if contract_id:
ir_module_module_ids = self.env['ir.module.module'].sudo().search(
[('contract_certificate', '!=', False), ('state', '=', 'installed')])
contracts = self.get_contracted_modules(type, contract_id, ir_module_module_ids)
return json.dumps(base64.encodestring(contracts).decode('ascii'))
def check_validate_date(self, config):

View File

@ -24,15 +24,16 @@ flectra.define('FlectraLicensing.DialogRegisterContract', function (require) {
save: function () {
var contract_id = this.$el.find('#contract_id').val();
var self = this;
if (!contract_id) {
var type = this.$el.find("input[name='activate']:checked").val();
if (!contract_id || !type) {
return;
}
rpc.query({
model: 'ir.http',
method: 'contract_validate_file',
args: [contract_id]
args: [contract_id,type]
}).done(function (bin) {
self.trigger('get_key', {'key': contract_id, 'binary': bin});
self.trigger('get_key', {'key': contract_id, 'binary': bin, 'type': type});
self.close();
});
}

View File

@ -244,7 +244,17 @@ return AbstractWebClient.extend({
session.get_file({
url: '/flectra/licensing',
data: {
'binary': key['binary']
'binary': key['binary'],
'type': key['type'],
'contract_id': key['key']
},
error: function (err) {
new require('web.Dialog').alert(null,err['message']);
},
success:function () {
if (key['type'] === 'online') {
window.location.reload();
}
}
});
});
@ -291,7 +301,7 @@ return AbstractWebClient.extend({
overlayCSS: {cursor: 'auto'}
});
self.contract_expired();
}, 15000);
}, 150000);
},
});

View File

@ -122,6 +122,14 @@
<div t-name="FlectraLicense.dialog_contract_registration" >
<div id="register_contract_form">
<div class="form-group">
<div>
<label for="activate_online">
<input id="activate_online" type="radio" name="activate" value="online">Online</input>
</label>
<label for="activate_offline">
<input id="activate_offline" type="radio" name="activate" value="offline" checked="">Offline</input>
</label>
</div>
<label for="contract_id">Contract ID</label>
<input type="text" class="form-control" id="contract_id" placeholder="Contract ID"/>
<input type="hidden" value=""/>