Skip to content

[IMP] runbot: public API #1101

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

Open
wants to merge 2 commits into
base: 18.0
Choose a base branch
from
Open

[IMP] runbot: public API #1101

wants to merge 2 commits into from

Conversation

Williambraecky
Copy link
Contributor

@Williambraecky Williambraecky commented Mar 13, 2025

Until now api routes on runbot have been created through custom website
pages in production.
We want to unify the API by making a 'public' api, inspired by the way
web_search_read works.

This commit adds:

  • A route to list all publicly available models
  • A route to do a read on a public model
  • A route to fetch the publicly available specification for a model
  • A public model mixin that provides all the tools required to support
    the above mentionned routes.

The mixin adds the ability to add the public attribute on fields.
Any field marked as public can then be publicly queried through the
controller.
Relational fields work in a nested manner (fields key in the field's
sub-specification) (up to a depth of 10).
The public api does not allow going through a relationship back and
front (parent->child->parent is NOT allowed).

Because we are based on web_search_read, we heavily focus on
validating the specification, for security reasons, and offset the load
of reading to the web_read function (we currently don't provide limit
metadata).

NOTE: this PR focuses on the public api feature, not the implementation so information might be lacking as of writing this.

@Williambraecky Williambraecky changed the title 18.0 public api wbr [WIP] public api Mar 13, 2025
@Williambraecky Williambraecky force-pushed the 18.0-public-api-wbr branch 4 times, most recently from 4ea8d45 to 7c4d102 Compare March 17, 2025 12:38
@Williambraecky Williambraecky changed the title [WIP] public api [IMP] runbot: public API Mar 17, 2025
@Williambraecky Williambraecky marked this pull request as ready for review March 17, 2025 12:44
Until now api routes on runbot have been created through custom website
pages in production.
We want to unify the API by making a 'public' api, inspired by the way
`web_search_read` works.

This commit adds:
 - A route to list all publicly available models
 - A route to do a read on a public model
 - A route to fetch the publicly available specification for a model
 - A public model mixin that provides all the tools required to support
   the above mentionned routes.

The mixin adds the ability to add the `public` attribute on fields.
Any field marked as public can then be publicly queried through the
controller.
Relational fields work in a nested manner (`fields` key in the field's
sub-specification) (up to a depth of 10).
The public api does not allow going through a relationship back and
front (parent->child->parent is NOT allowed).

Because we are based on `web_search_read`, we heavily focus on
validating the specification, for security reasons, and offset the load
of reading to the `web_read` function (we currently don't provide limit
metadata).
@C3POdoo C3POdoo requested a review from a team March 17, 2025 12:45
Implements the public model mixin for `runbot.bundle` and make enough
fields public to be able to render the runbot homepage.
Comment on lines +26 to +27
DEFAULT_LIMIT = 20
DEFAULT_MAX_LIMIT = 60
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two are only moved once and have been replaced with methods so probably not necessary.

'many2one', 'one2many', 'many2many',
}
RELATIONAL_FIELD_TYPES = {'many2one', 'one2many', 'many2many'}
SPEC_MAX_DEPTH = 10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could also be moved to a method instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant