[MIG] auditlog: Migrated to 10.0
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Audit Log",
|
'name': "Audit Log",
|
||||||
'version': "9.0.1.0.0",
|
'version': "10.0.1.0.0",
|
||||||
'author': "ABF OSIELL,Odoo Community Association (OCA)",
|
'author': "ABF OSIELL,Odoo Community Association (OCA)",
|
||||||
'license': "AGPL-3",
|
'license': "AGPL-3",
|
||||||
'website': "http://www.osiell.com",
|
'website': "http://www.osiell.com",
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
'views/http_session_view.xml',
|
'views/http_session_view.xml',
|
||||||
'views/http_request_view.xml',
|
'views/http_request_view.xml',
|
||||||
],
|
],
|
||||||
'images': [],
|
|
||||||
'application': True,
|
'application': True,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<openerp>
|
<odoo noupdate="1">
|
||||||
<data noupdate="1">
|
|
||||||
|
|
||||||
<record id="ir_cron_auditlog_autovacuum" model="ir.cron">
|
<record id="ir_cron_auditlog_autovacuum" model="ir.cron">
|
||||||
<field name='name'>Auto-vacuum audit logs</field>
|
<field name='name'>Auto-vacuum audit logs</field>
|
||||||
|
|
@ -14,5 +13,4 @@
|
||||||
<field name="args">(180,)</field>
|
<field name="args">(180,)</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</odoo>
|
||||||
</openerp>
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from openerp import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,17 @@
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp import models, fields, api
|
from odoo import models, fields, api
|
||||||
from openerp.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
|
|
||||||
class AuditlogHTTPRequest(models.Model):
|
class AuditlogHTTPRequest(models.Model):
|
||||||
_name = 'auditlog.http.request'
|
_name = 'auditlog.http.request'
|
||||||
_description = u"Auditlog - HTTP request log"
|
_description = u"Auditlog - HTTP request log"
|
||||||
_order = "create_date DESC"
|
_order = "create_date DESC"
|
||||||
_rec_name = 'display_name'
|
|
||||||
|
|
||||||
display_name = fields.Char(u"Name", compute="_compute_display_name")
|
display_name = fields.Char(
|
||||||
|
u"Name", compute="_compute_display_name", store=True)
|
||||||
name = fields.Char(u"Path")
|
name = fields.Char(u"Path")
|
||||||
root_url = fields.Char(u"Root URL")
|
root_url = fields.Char(u"Root URL")
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
|
|
@ -23,7 +23,7 @@ class AuditlogHTTPRequest(models.Model):
|
||||||
log_ids = fields.One2many(
|
log_ids = fields.One2many(
|
||||||
'auditlog.log', 'http_request_id', string=u"Logs")
|
'auditlog.log', 'http_request_id', string=u"Logs")
|
||||||
|
|
||||||
@api.multi
|
@api.depends('create_date', 'name')
|
||||||
def _compute_display_name(self):
|
def _compute_display_name(self):
|
||||||
for httprequest in self:
|
for httprequest in self:
|
||||||
create_date = fields.Datetime.from_string(httprequest.create_date)
|
create_date = fields.Datetime.from_string(httprequest.create_date)
|
||||||
|
|
@ -33,6 +33,10 @@ class AuditlogHTTPRequest(models.Model):
|
||||||
httprequest.name or '?',
|
httprequest.name or '?',
|
||||||
fields.Datetime.to_string(tz_create_date))
|
fields.Datetime.to_string(tz_create_date))
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def name_get(self):
|
||||||
|
return [(request.id, request.display_name) for request in self]
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def current_http_request(self):
|
def current_http_request(self):
|
||||||
"""Create a log corresponding to the current HTTP request, and returns
|
"""Create a log corresponding to the current HTTP request, and returns
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,24 @@
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp import models, fields, api
|
from odoo import models, fields, api
|
||||||
from openerp.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
|
|
||||||
class AuditlogtHTTPSession(models.Model):
|
class AuditlogtHTTPSession(models.Model):
|
||||||
_name = 'auditlog.http.session'
|
_name = 'auditlog.http.session'
|
||||||
_description = u"Auditlog - HTTP User session log"
|
_description = u"Auditlog - HTTP User session log"
|
||||||
_order = "create_date DESC"
|
_order = "create_date DESC"
|
||||||
_rec_name = 'display_name'
|
|
||||||
|
|
||||||
display_name = fields.Char(u"Name", compute="_compute_display_name")
|
display_name = fields.Char(
|
||||||
|
u"Name", compute="_compute_display_name", store=True)
|
||||||
name = fields.Char(u"Session ID", index=True)
|
name = fields.Char(u"Session ID", index=True)
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
'res.users', string=u"User", index=True)
|
'res.users', string=u"User", index=True)
|
||||||
http_request_ids = fields.One2many(
|
http_request_ids = fields.One2many(
|
||||||
'auditlog.http.request', 'http_session_id', string=u"HTTP Requests")
|
'auditlog.http.request', 'http_session_id', string=u"HTTP Requests")
|
||||||
|
|
||||||
@api.multi
|
@api.depends('create_date', 'user_id')
|
||||||
def _compute_display_name(self):
|
def _compute_display_name(self):
|
||||||
for httpsession in self:
|
for httpsession in self:
|
||||||
create_date = fields.Datetime.from_string(httpsession.create_date)
|
create_date = fields.Datetime.from_string(httpsession.create_date)
|
||||||
|
|
@ -29,6 +29,10 @@ class AuditlogtHTTPSession(models.Model):
|
||||||
httpsession.user_id and httpsession.user_id.name or '?',
|
httpsession.user_id and httpsession.user_id.name or '?',
|
||||||
fields.Datetime.to_string(tz_create_date))
|
fields.Datetime.to_string(tz_create_date))
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def name_get(self):
|
||||||
|
return [(session.id, session.display_name) for session in self]
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def current_http_session(self):
|
def current_http_session(self):
|
||||||
"""Create a log corresponding to the current HTTP user session, and
|
"""Create a log corresponding to the current HTTP user session, and
|
||||||
|
|
@ -39,7 +43,7 @@ class AuditlogtHTTPSession(models.Model):
|
||||||
"""
|
"""
|
||||||
if not request:
|
if not request:
|
||||||
return False
|
return False
|
||||||
httpsession = request.httpsession
|
httpsession = request.session
|
||||||
if httpsession:
|
if httpsession:
|
||||||
existing_session = self.search(
|
existing_session = self.search(
|
||||||
[('name', '=', httpsession.sid),
|
[('name', '=', httpsession.sid),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from openerp import models, fields
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
class AuditlogLog(models.Model):
|
class AuditlogLog(models.Model):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# © 2015 ABF OSIELL <http://osiell.com>
|
# © 2015 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp import models, fields, api, modules, _, SUPERUSER_ID, sql_db
|
from odoo import models, fields, api, modules, _, sql_db
|
||||||
|
|
||||||
FIELDS_BLACKLIST = [
|
FIELDS_BLACKLIST = [
|
||||||
'id', 'create_uid', 'create_date', 'write_uid', 'write_date',
|
'id', 'create_uid', 'create_date', 'write_uid', 'write_date',
|
||||||
|
|
@ -101,16 +101,16 @@ class AuditlogRule(models.Model):
|
||||||
"You cannot define another: please edit the existing one."))
|
"You cannot define another: please edit the existing one."))
|
||||||
]
|
]
|
||||||
|
|
||||||
def _register_hook(self, cr, ids=None):
|
def _register_hook(self):
|
||||||
"""Get all rules and apply them to log method calls."""
|
"""Get all rules and apply them to log method calls."""
|
||||||
super(AuditlogRule, self)._register_hook(cr)
|
super(AuditlogRule, self)._register_hook()
|
||||||
if not hasattr(self.pool, '_auditlog_field_cache'):
|
if not hasattr(self.pool, '_auditlog_field_cache'):
|
||||||
self.pool._auditlog_field_cache = {}
|
self.pool._auditlog_field_cache = {}
|
||||||
if not hasattr(self.pool, '_auditlog_model_cache'):
|
if not hasattr(self.pool, '_auditlog_model_cache'):
|
||||||
self.pool._auditlog_model_cache = {}
|
self.pool._auditlog_model_cache = {}
|
||||||
if ids is None:
|
if not self:
|
||||||
ids = self.search(cr, SUPERUSER_ID, [('state', '=', 'subscribed')])
|
self = self.search([('state', '=', 'subscribed')])
|
||||||
return self._patch_methods(cr, SUPERUSER_ID, ids)
|
return self._patch_methods()
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _patch_methods(self):
|
def _patch_methods(self):
|
||||||
|
|
@ -175,7 +175,7 @@ class AuditlogRule(models.Model):
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
"""Update the registry when a new rule is created."""
|
"""Update the registry when a new rule is created."""
|
||||||
new_record = super(AuditlogRule, self).create(vals)
|
new_record = super(AuditlogRule, self).create(vals)
|
||||||
if self._model._register_hook(self.env.cr, new_record.ids):
|
if new_record._register_hook():
|
||||||
modules.registry.RegistryManager.signal_registry_change(
|
modules.registry.RegistryManager.signal_registry_change(
|
||||||
self.env.cr.dbname)
|
self.env.cr.dbname)
|
||||||
return new_record
|
return new_record
|
||||||
|
|
@ -184,7 +184,7 @@ class AuditlogRule(models.Model):
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
"""Update the registry when existing rules are updated."""
|
"""Update the registry when existing rules are updated."""
|
||||||
super(AuditlogRule, self).write(vals)
|
super(AuditlogRule, self).write(vals)
|
||||||
if self._model._register_hook(self.env.cr, self.ids):
|
if self._register_hook():
|
||||||
modules.registry.RegistryManager.signal_registry_change(
|
modules.registry.RegistryManager.signal_registry_change(
|
||||||
self.env.cr.dbname)
|
self.env.cr.dbname)
|
||||||
return True
|
return True
|
||||||
|
|
@ -526,7 +526,7 @@ class AuditlogRule(models.Model):
|
||||||
to view logs on that model.
|
to view logs on that model.
|
||||||
"""
|
"""
|
||||||
act_window_model = self.env['ir.actions.act_window']
|
act_window_model = self.env['ir.actions.act_window']
|
||||||
model_data_model = self.env['ir.model.data']
|
model_ir_values = self.env['ir.values']
|
||||||
for rule in self:
|
for rule in self:
|
||||||
# Create a shortcut to view logs
|
# Create a shortcut to view logs
|
||||||
domain = "[('model_id', '=', %s), ('res_id', '=', active_id)]" % (
|
domain = "[('model_id', '=', %s), ('res_id', '=', active_id)]" % (
|
||||||
|
|
@ -541,10 +541,12 @@ class AuditlogRule(models.Model):
|
||||||
rule.write({'state': 'subscribed', 'action_id': act_window.id})
|
rule.write({'state': 'subscribed', 'action_id': act_window.id})
|
||||||
keyword = 'client_action_relate'
|
keyword = 'client_action_relate'
|
||||||
value = 'ir.actions.act_window,%s' % act_window.id
|
value = 'ir.actions.act_window,%s' % act_window.id
|
||||||
model_data_model.sudo().ir_set(
|
model_ir_values.sudo().set_action(
|
||||||
'action', keyword, 'View_log_' + rule.model_id.model,
|
'View_log_' + rule.model_id.model,
|
||||||
[rule.model_id.model], value, replace=True,
|
action_slot=keyword,
|
||||||
isobject=True, xml_id=False)
|
model=rule.model_id.model,
|
||||||
|
action=value)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 23 KiB |
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2015 Therp BV <http://therp.nl>
|
# © 2015 Therp BV <http://therp.nl>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from openerp.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestAuditlog(object):
|
class TestAuditlog(object):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from openerp.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestAuditlogAutovacuum(TransactionCase):
|
class TestAuditlogAutovacuum(TransactionCase):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<menuitem id="menu_audit" name="Audit"
|
<menuitem id="menu_audit" name="Audit"
|
||||||
parent="base.menu_custom" sequence="50"
|
parent="base.menu_custom" sequence="50"
|
||||||
groups="base.group_system"/>
|
groups="base.group_system"/>
|
||||||
|
|
@ -200,6 +198,4 @@
|
||||||
|
|
||||||
<menuitem id="menu_audit_logs" name="Logs"
|
<menuitem id="menu_audit_logs" name="Logs"
|
||||||
parent="menu_audit" action="action_auditlog_log_tree"/>
|
parent="menu_audit" action="action_auditlog_log_tree"/>
|
||||||
|
</odoo>
|
||||||
</data>
|
|
||||||
</openerp>
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<record id="view_auditlog_http_request_form" model="ir.ui.view">
|
<record id="view_auditlog_http_request_form" model="ir.ui.view">
|
||||||
<field name="name">auditlog.http.request.form</field>
|
<field name="name">auditlog.http.request.form</field>
|
||||||
<field name="model">auditlog.http.request</field>
|
<field name="model">auditlog.http.request</field>
|
||||||
|
|
@ -77,6 +75,4 @@
|
||||||
<menuitem id="menu_action_auditlog_http_request_tree"
|
<menuitem id="menu_action_auditlog_http_request_tree"
|
||||||
parent="menu_audit"
|
parent="menu_audit"
|
||||||
action="action_auditlog_http_request_tree"/>
|
action="action_auditlog_http_request_tree"/>
|
||||||
|
</odoo>
|
||||||
</data>
|
|
||||||
</openerp>
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<record id="view_auditlog_http_session_form" model="ir.ui.view">
|
<record id="view_auditlog_http_session_form" model="ir.ui.view">
|
||||||
<field name="name">auditlog.http.session.form</field>
|
<field name="name">auditlog.http.session.form</field>
|
||||||
<field name="model">auditlog.http.session</field>
|
<field name="model">auditlog.http.session</field>
|
||||||
|
|
@ -64,6 +62,4 @@
|
||||||
<menuitem id="menu_action_auditlog_http_session_tree"
|
<menuitem id="menu_action_auditlog_http_session_tree"
|
||||||
parent="menu_audit"
|
parent="menu_audit"
|
||||||
action="action_auditlog_http_session_tree"/>
|
action="action_auditlog_http_session_tree"/>
|
||||||
|
</odoo>
|
||||||
</data>
|
|
||||||
</openerp>
|
|
||||||
|
|
|
||||||