5
0
mirror of https://github.com/odoo/runbot.git synced 2025-03-21 10:25:44 +07:00
runbot/runbot_merge/models/res_partner.py
Xavier Morel b96bc9a58c [FIX] runbot_merge: make github_login case insensitive
Rather than try to fix up various bits where we search & all and
wonder what index we should be using, make the column a CIText.

For mergebot the main use case would be properly handling
delegate=XXX: currently if XXX is not a case-sensitive match we're
going to create a new partner with the new github login and
give *them* delegation, and the intended target of the delegation
isn't going to work correctly.

Also try to install the citext extension if it's not in the database,
and run the database-creation process with `check=True` so if that
fails we properly bubble up the error and don't try to run tests on a
corrupted / broken DB.

Fixes 
2020-02-11 09:17:52 +01:00

47 lines
1.7 KiB
Python

from email.utils import parseaddr
from odoo import fields, models, tools, api
class CIText(fields.Char):
type = 'char'
column_type = ('citext', 'citext')
column_cast_from = ('varchar', 'text')
class Partner(models.Model):
_inherit = 'res.partner'
github_login = CIText()
delegate_reviewer = fields.Many2many('runbot_merge.pull_requests')
formatted_email = fields.Char(string="commit email", compute='_rfc5322_formatted')
review_rights = fields.One2many('res.partner.review', 'partner_id')
def _auto_init(self):
res = super(Partner, self)._auto_init()
tools.create_unique_index(
self._cr, 'runbot_merge_unique_gh_login', self._table, ['github_login'])
return res
@api.depends('name', 'email', 'github_login')
def _rfc5322_formatted(self):
for partner in self:
if partner.email:
email = parseaddr(partner.email)[1]
elif partner.github_login:
email = '%s@users.noreply.github.com' % partner.github_login
else:
email = ''
partner.formatted_email = '%s <%s>' % (partner.name, email)
class ReviewRights(models.Model):
_name = 'res.partner.review'
_description = "mapping of review rights between partners and repos"
partner_id = fields.Many2one('res.partner', required=True, ondelete='cascade')
repository_id = fields.Many2one('runbot_merge.repository', required=True)
review = fields.Boolean(default=False)
self_review = fields.Boolean(default=False)
def _auto_init(self):
res = super()._auto_init()
tools.create_unique_index(self._cr, 'runbot_merge_review_m2m', self._table, ['partner_id', 'repository_id'])
return res