mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
--wip-- [skip ci]
This commit is contained in:
parent
f2e79007b9
commit
8e96f9b29e
@ -3,3 +3,4 @@
|
||||
from . import frontend
|
||||
from . import hook
|
||||
from . import badge
|
||||
from . import public_api
|
||||
|
34
runbot/controllers/public_api.py
Normal file
34
runbot/controllers/public_api.py
Normal file
@ -0,0 +1,34 @@
|
||||
from werkzeug.exceptions import Forbidden, UnprocessableEntity, BadRequest
|
||||
|
||||
from odoo.http import Controller, request, route
|
||||
|
||||
from odoo.addons.runbot.models.public_model_mixin import PublicModelMixin
|
||||
|
||||
|
||||
class PublicApi(Controller):
|
||||
|
||||
@route('/runbot/api/<model>/read', auth='public', methods=['POST'], readonly=True, csrf=False)
|
||||
def read(self, *, model: str):
|
||||
REQUIRED_DATA_KEYS = {'schema', 'domain'}
|
||||
|
||||
data = request.get_json_data()
|
||||
if not isinstance(data, dict) or any(key not in data for key in REQUIRED_DATA_KEYS):
|
||||
raise BadRequest('Invalid payload')
|
||||
try:
|
||||
Model = request.env[model]
|
||||
except KeyError:
|
||||
raise BadRequest('Unknown model')
|
||||
if PublicModelMixin._name not in Model._inherit:
|
||||
raise BadRequest('Unknown model')
|
||||
schema = data['schema']
|
||||
try:
|
||||
if not Model._verify_schema(schema) and\
|
||||
not request.env.user.has_group('runbot.group_runbot_admin'):
|
||||
raise BadRequest('Invalid schema or trying to access private data.')
|
||||
except (ValueError, AssertionError) as e:
|
||||
raise BadRequest('Invalid schema') from e
|
||||
try:
|
||||
records = Model.search(data['domain'])
|
||||
except ValueError as e:
|
||||
raise BadRequest('Invalid domain') from e
|
||||
return request.make_json_response(records._read_schema(schema))
|
@ -11,7 +11,7 @@ from ..common import dt2time, s2human_long
|
||||
class Bundle(models.Model):
|
||||
_name = 'runbot.bundle'
|
||||
_description = "Bundle"
|
||||
_inherit = 'mail.thread'
|
||||
_inherit = ['mail.thread', 'runbot.public.model.mixin']
|
||||
|
||||
name = fields.Char('Bundle name', required=True, help="Name of the base branch")
|
||||
project_id = fields.Many2one('runbot.project', required=True, index=True)
|
||||
|
@ -6,11 +6,12 @@ class Project(models.Model):
|
||||
_name = 'runbot.project'
|
||||
_description = 'Project'
|
||||
_order = 'sequence, id'
|
||||
_inherit = ['runbot.public.model.mixin']
|
||||
|
||||
name = fields.Char('Project name', required=True)
|
||||
name = fields.Char('Project name', required=True, public=True)
|
||||
group_ids = fields.Many2many('res.groups', string='Required groups')
|
||||
keep_sticky_running = fields.Boolean('Keep last sticky builds running')
|
||||
trigger_ids = fields.One2many('runbot.trigger', 'project_id', string='Triggers')
|
||||
trigger_ids = fields.One2many('runbot.trigger', 'project_id', string='Triggers', public=True)
|
||||
dockerfile_id = fields.Many2one('runbot.dockerfile', index=True, help="Project Default Dockerfile")
|
||||
repo_ids = fields.One2many('runbot.repo', 'project_id', string='Repos')
|
||||
sequence = fields.Integer('Sequence')
|
||||
|
@ -35,7 +35,9 @@ class PublicModelMixin(models.AbstractModel):
|
||||
def _valid_field_parameter(self, field: fields.Field, name: str):
|
||||
if field.type in SUPPORTED_FIELD_TYPES:
|
||||
return name in (
|
||||
'public', # boolean, whether the field is readable through the public api
|
||||
# boolean, whether the field is readable through the public api,
|
||||
# public fields on record on which the user does not have access are not exposed.
|
||||
'public',
|
||||
) or super()._valid_field_parameter(field, name)
|
||||
return super()._valid_field_parameter(field, name)
|
||||
|
||||
|
@ -43,13 +43,13 @@ class Trigger(models.Model):
|
||||
"""
|
||||
|
||||
_name = 'runbot.trigger'
|
||||
_inherit = 'mail.thread'
|
||||
_inherit = ['mail.thread', 'runbot.public.model.mixin']
|
||||
_description = 'Triggers'
|
||||
|
||||
_order = 'sequence, id'
|
||||
|
||||
sequence = fields.Integer('Sequence')
|
||||
name = fields.Char("Name")
|
||||
name = fields.Char("Name", public=True)
|
||||
description = fields.Char("Description", help="Informative description")
|
||||
project_id = fields.Many2one('runbot.project', string="Project id", required=True)
|
||||
repo_ids = fields.Many2many('runbot.repo', relation='runbot_trigger_triggers', string="Triggers", domain="[('project_id', '=', project_id)]")
|
||||
|
Loading…
Reference in New Issue
Block a user