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.

29 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Florent de Labarre - 2016
  3. from openerp import api, fields, models
  4. class auth_oauth_multi_token(models.Model):
  5. """Class defining list of tokens"""
  6. _name = 'auth.oauth.multi.token'
  7. _description = 'OAuth2 token'
  8. _order = "id desc"
  9. oauth_access_token = fields.Char('OAuth Access Token', readonly=True, copy=False)
  10. user_id = fields.Many2one('res.users', 'User', required=True)
  11. active_token = fields.Boolean('Active')
  12. @api.model
  13. def create(self, vals):
  14. res = super(auth_oauth_multi_token, self).create(vals)
  15. oauth_access_token_ids = self.search([('user_id', '=', vals['user_id']), ('active_token', '=', True)], ).ids
  16. oauth_access_max_token = self.env['res.users'].search([('id', '=', vals['user_id'])], limit=1).oauth_access_max_token
  17. if len(oauth_access_token_ids) >= oauth_access_max_token:
  18. self.browse(oauth_access_token_ids[oauth_access_max_token]).write({
  19. 'oauth_access_token': "****************************",
  20. 'active_token': False})
  21. return res
  22. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: