-
Couldn't load subscription status.
- Fork 153
18.0 poc frontend owl wbr #1120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Williambraecky
wants to merge
12
commits into
18.0
Choose a base branch
from
18.0-poc-frontend-owl-wbr
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc0ba9b
[REF] runbot: reorganize static folder
Williambraecky 89ca91c
[FIX] runbot: export diff_match_patch properly
Williambraecky 5b9b934
[IMP] runbot: vendor owl and expose through odoo module
Williambraecky 2f11202
[IMP] runbot: add basic owl structure
Williambraecky 819437f
[IMP] runbot: add interaction framework
Williambraecky d48300c
[REF] runbot: rewrite runbot.js
Williambraecky 0927026
[REF] runbot: move all assets to the bundle
Williambraecky a84a8d7
[IMP] runbot: implement public api mixin
Williambraecky 32d23de
[IMP] runbot: implement public model mixin for bundle
Williambraecky 2eb7901
[POC] runbot: single page application for runbot
Williambraecky fb46cae
[POC] runbot: add searchbar
Williambraecky a2d6d16
[POC] runbot: fix useQuery
Williambraecky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| from . import frontend | ||
| from . import hook | ||
| from . import badge | ||
| from . import public_api | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import json | ||
|
|
||
| from werkzeug.exceptions import BadRequest, Forbidden | ||
|
|
||
| from odoo.exceptions import AccessError | ||
| from odoo.http import Controller, request, route | ||
| from odoo.tools import mute_logger | ||
|
|
||
| from odoo.addons.runbot.models.public_model_mixin import PublicModelMixin | ||
|
|
||
|
|
||
| class PublicApi(Controller): | ||
|
|
||
| @mute_logger('odoo.addons.base.models.ir_model') # We don't care about logging acl errors | ||
| def _get_model(self, model: str) -> PublicModelMixin: | ||
| """ | ||
| Returns the model from a model string. | ||
|
|
||
| Raises the appropriate exception if: | ||
| - The model does not exist | ||
| - The model is not a public model | ||
| - The current user can not read the model | ||
| """ | ||
| pool = request.env.registry | ||
| try: | ||
| Model = pool[model] | ||
| except KeyError: | ||
| raise BadRequest('Unknown model') | ||
| if not issubclass(Model, pool['runbot.public.model.mixin']): | ||
| raise BadRequest('Unknown model') | ||
| Model = request.env[model] | ||
| Model.check_access('read') | ||
| if not Model._api_request_allow_direct_access(): | ||
| raise Forbidden('This model does not allow direct access') | ||
| return Model | ||
|
|
||
| @route('/runbot/api/models', auth='public', methods=['GET'], readonly=True) | ||
| def models(self): | ||
| models = [] | ||
| for model in request.env.keys(): | ||
| try: | ||
| models.append(self._get_model(model)) | ||
| except (BadRequest, AccessError, Forbidden): | ||
| pass | ||
| return request.make_json_response( | ||
| [Model._name for Model in models] | ||
| ) | ||
|
|
||
| @route('/runbot/api/<model>/read', auth='public', methods=['POST'], readonly=True, csrf=False) | ||
| def read(self, *, model: str): | ||
| Model = self._get_model(model) | ||
| required_keys = Model._api_request_required_keys() | ||
| allowed_keys = Model._api_request_allowed_keys() | ||
| try: | ||
| data = request.get_json_data() | ||
| except json.JSONDecodeError: | ||
| raise BadRequest('Invalid payload, missing or malformed json') | ||
| if not isinstance(data, dict): | ||
| raise BadRequest('Invalid payload, should be a dict.') | ||
| if (missing_keys := required_keys - set(data.keys())): | ||
| raise BadRequest(f'Invalid payload, missing keys: {", ".join(missing_keys)}') | ||
| if (unknown_keys := set(data.keys()) - allowed_keys): | ||
| raise BadRequest(f'Invalid payload, unknown keys: {", ".join(unknown_keys)}') | ||
| if 'context' in data: | ||
| Model = Model.with_context(**data['context']) | ||
| if Model._api_request_requires_project(): | ||
| if not isinstance(data['project_id'], int): | ||
| raise BadRequest('Invalid project_id, should be an int') | ||
| # This is an additional layer of protection for project_id | ||
| project = request.env['runbot.project'].browse(data['project_id']).exists() | ||
| if not project: | ||
| raise BadRequest('Unknown project_id') | ||
| project.check_access('read') | ||
| Model = Model.with_context(project_id=project.id) | ||
| return request.make_json_response(Model._api_request_read(data)) | ||
|
|
||
| @route('/runbot/api/<model>/spec', auth='public', methods=['GET'], readonly=True) | ||
| def spec(self, *, model: str): | ||
| Model = self._get_model(model) | ||
| required_keys = Model._api_request_required_keys() | ||
| allowed_keys = Model._api_request_allowed_keys() | ||
| return request.make_json_response({ | ||
| 'requires_project': Model._api_request_requires_project(), | ||
| 'default_page_size': Model._api_request_default_limit(), | ||
| 'max_page_size': Model._api_request_max_limit(), | ||
| 'required_keys': list(Model._api_request_required_keys()), | ||
| 'allowed_keys': list(allowed_keys - required_keys), | ||
| 'specification': self._get_model(model)._api_public_specification(), | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.