Skip to content

Commit 435c307

Browse files
committed
Allow circumvention of automatic adapter creation on hook creation
1 parent 616ade0 commit 435c307

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

base_web_hook/models/web_hook.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ def _default_secret(self, length=254):
113113
def create(self, vals):
114114
"""Create the interface for the record and assign to ``interface``."""
115115
record = super(WebHook, self).create(vals)
116-
interface = self.env[vals['interface_type']].create({
117-
'hook_id': record.id,
118-
})
119-
record.interface = interface
116+
if not self._context.get('web_hook_no_interface'):
117+
interface = self.env[vals['interface_type']].create({
118+
'hook_id': record.id,
119+
})
120+
record.interface = interface
120121
return record
121122

122123
@api.model

base_web_hook/models/web_hook_token_adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ class WebHookTokenAdapter(models.AbstractModel):
1919
ondelete='cascade',
2020
)
2121

22+
@api.model
23+
def create(self, vals):
24+
"""If creating from the adapter level, circumvent adapter creation.
25+
26+
An adapter is implicitly created and managed from within the
27+
``web.hook`` model. This is desirable in most instances, but it should
28+
also be possible to create an adapter correctly.
29+
"""
30+
context_self = self.with_context(web_hook_no_interface=True)
31+
return super(WebHookTokenAdapter, context_self).create(vals)
32+
2233
@api.multi
2334
def validate(self, token_string, data, data_string, headers):
2435
"""Return ``True`` if the token is valid. Otherwise, ``False``.

0 commit comments

Comments
 (0)