You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2015 ABF OSIELL (<http://osiell.com>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api
  22. from openerp.http import request
  23. class AuditlogtHTTPSession(models.Model):
  24. _name = 'auditlog.http.session'
  25. _description = u"Auditlog - HTTP User session log"
  26. _order = "create_date DESC"
  27. name = fields.Char(u"Session ID")
  28. user_id = fields.Many2one(
  29. 'res.users', string=u"User")
  30. http_request_ids = fields.One2many(
  31. 'auditlog.http.request', 'http_session_id', string=u"HTTP Requests")
  32. @api.model
  33. def current_http_session(self):
  34. """Create a log corresponding to the current HTTP user session, and
  35. returns its ID. This method can be called several times during the
  36. HTTP query/response cycle, it will only log the user session on the
  37. first call.
  38. If no HTTP user session is available, returns `False`.
  39. """
  40. httpsession = request.httpsession
  41. if httpsession:
  42. existing_session = self.search(
  43. [('name', '=', httpsession.sid),
  44. ('user_id', '=', request.uid)])
  45. if existing_session:
  46. return existing_session.id
  47. vals = {
  48. 'name': httpsession.sid,
  49. 'user_id': request.uid,
  50. }
  51. httpsession.auditlog_http_session_id = self.create(vals).id
  52. return httpsession.auditlog_http_session_id
  53. return False