Skip to content

Commit b5ff5cd

Browse files
Xavier-Dod-fence
authored andcommitted
[IMP] runbot: add required fields to OAuth providers
1 parent fcfae54 commit b5ff5cd

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

runbot/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'category': 'Website',
99
'version': '5.14',
1010
'application': True,
11-
'depends': ['base', 'base_automation', 'website'],
11+
'depends': ['base', 'base_automation', 'website', 'auth_oauth'],
1212
'data': [
1313
'security/runbot_security.xml',
1414
'security/ir.model.access.csv',
@@ -53,6 +53,7 @@
5353
'views/dashboard_views.xml',
5454
'views/dockerfile_views.xml',
5555
'views/host_views.xml',
56+
'views/oauth_provider_views.xml',
5657
'views/repo_views.xml',
5758
'views/res_config_settings_views.xml',
5859
'views/stat_views.xml',

runbot/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from . import ir_model_fields_converter
2020
from . import ir_qweb
2121
from . import ir_logging
22+
from . import oauth_provider
2223
from . import project
2324
from . import repo
2425
from . import res_config_settings

runbot/models/oauth_provider.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from odoo import models, fields
2+
3+
4+
class OAuthProvider(models.Model):
5+
_inherit = 'auth.oauth.provider'
6+
7+
required_fields = fields.Char(
8+
string="Required Fields",
9+
help="List of fields that are required to sign up a user using this OAuth provider. "
10+
"Fields should be separated by spaces.",
11+
)

runbot/models/res_users.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

44
from odoo import fields, models
5+
from odoo.exceptions import ValidationError
56

67

78
class ResUsers(models.Model):
@@ -23,3 +24,18 @@ def write(self, values):
2324
if list(values.keys()) == ['github_login'] and self.env.user.has_group('runbot.group_runbot_team_manager'):
2425
return super(ResUsers, self.sudo()).write(values)
2526
return super().write(values)
27+
28+
def _auth_oauth_validate(self, provider, access_token):
29+
validation = super()._auth_oauth_validate(provider, access_token)
30+
provider = self.env['auth.oauth.provider'].browse(provider)
31+
required_fields = (provider.required_fields or '').split()
32+
for field in required_fields:
33+
if not validation.get(field):
34+
raise ValidationError("The `%s` field is required to sign in." % field)
35+
return validation
36+
37+
def _generate_signup_values(self, provider, validation, params):
38+
signup_values = super()._generate_signup_values(provider, validation, params)
39+
if 'github_login' in validation:
40+
signup_values['github_login'] = validation['github_login']
41+
return signup_values
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<odoo>
2+
<data>
3+
<record id="view_oauth_provider_form" model="ir.ui.view">
4+
<field name="name">auth.oauth.provider.form</field>
5+
<field name="model">auth.oauth.provider</field>
6+
<field name="inherit_id" ref="auth_oauth.view_oauth_provider_form" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//field[@name='scope']" position="after">
9+
<field name="required_fields"/>
10+
</xpath>
11+
</field>
12+
</record>
13+
</data>
14+
</odoo>

0 commit comments

Comments
 (0)