Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions endpoint/models/endpoint_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class EndpointMixin(models.AbstractModel):
)
exec_as_user_id = fields.Many2one(comodel_name="res.users")
company_id = fields.Many2one("res.company", string="Company")
url = fields.Char(
compute="_compute_url",
help="Handy link to share or access the endpoint's final URL. ",
)

def _compute_url(self):
# Use current URL to respect the domain used by the current user.
# `base.url` might be different from the one used by the user.
base_url = http.request.httprequest.url_root
for rec in self:
rec.url = f"{base_url.rstrip('/')}/{rec.route.lstrip('/')}"

def _selection_exec_mode(self):
return [("code", "Execute code")]
Expand Down
4 changes: 4 additions & 0 deletions endpoint/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,7 @@ def test_registry_sync(self):
def test_duplicate(self):
endpoint = self.endpoint.copy()
self.assertTrue(endpoint.route.endswith("/COPY_FIXME"))

def test_url(self):
with self._get_mocked_request():
self.assertTrue(self.endpoint.url, "http://localhost/demo/one")
3 changes: 3 additions & 0 deletions endpoint/views/endpoint_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<h2>
<field name="route" />
</h2>
<h3 class="oe_read_only">
<field name="url" widget="url" />
</h3>
</div>
<notebook>
<page name="main" string="Main">
Expand Down
Loading