Skip to content

Commit 6f11b8d

Browse files
[IMP] github_connector: Add input validation for Github Name in sync wizard
1 parent 8b2cb33 commit 6f11b8d

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎github_connector/wizards/wizard_load_github_model.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import fields, models
5+
from odoo import exceptions, fields, models
66

77

88
class WizardLoadGithubModel(models.TransientModel):
@@ -28,10 +28,34 @@ class WizardLoadGithubModel(models.TransientModel):
2828
def button_create_from_github(self):
2929
for wizard in self:
3030
if wizard.github_type == "organization":
31+
if "/" in wizard.name:
32+
raise exceptions.UserError(
33+
self.env._(
34+
"You selected 'Organization' but provided a repository "
35+
"name containing a '/'. Please select 'Repository' "
36+
"as the Github Type Name instead."
37+
)
38+
)
3139
github_model = self.env["github.organization"]
3240
elif wizard.github_type == "user":
41+
if "/" in wizard.name:
42+
raise exceptions.UserError(
43+
self.env._(
44+
"You selected 'User' but provided a repository name"
45+
" containing a '/'. Please select 'Repository' "
46+
"as the Github Type Name instead."
47+
)
48+
)
3349
github_model = self.env["res.partner"]
3450
elif wizard.github_type == "repository":
51+
if "/" not in wizard.name:
52+
raise exceptions.UserError(
53+
self.env._(
54+
"You selected 'Repository' but provided a name "
55+
"without a '/'. Repositories should be in the format "
56+
"'organization/repository'."
57+
)
58+
)
3559
github_model = self.env["github.repository"]
3660
my_obj = github_model.create_from_name(wizard.name)
3761
if wizard.child_update:

0 commit comments

Comments
 (0)