mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: generic api
This commit is contained in:
parent
a00fa04e07
commit
4d7580605e
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import api
|
||||||
from . import frontend
|
from . import frontend
|
||||||
from . import hook
|
from . import hook
|
||||||
from . import badge
|
from . import badge
|
69
runbot/controllers/api.py
Normal file
69
runbot/controllers/api.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
from odoo import http
|
||||||
|
from odoo.http import request
|
||||||
|
from odoo.tools import consteq
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RunbotController(http.Controller):
|
||||||
|
|
||||||
|
@http.route('/runbot/api/web_search_read', type='http', auth='public', csrf=False)
|
||||||
|
def api_web_search_read(self, uid=None, token=None, model=None, specification=None, id=None, ids=None, domain=None, limit=200, offset=0, order=None):
|
||||||
|
"""
|
||||||
|
model: the model to read
|
||||||
|
fields: dictionnary
|
||||||
|
|
||||||
|
Example of usage:
|
||||||
|
|
||||||
|
requests.post(
|
||||||
|
'http://127.0.0.1:8069/runbot/api/read',
|
||||||
|
data={
|
||||||
|
'uid': <uid>
|
||||||
|
'token': '<token>',
|
||||||
|
'model': 'runbot.bundle',
|
||||||
|
'domain':json.dumps([('sticky', '=', True), ('project_id', '=', 1)]),
|
||||||
|
'specification': json.dumps({
|
||||||
|
"id": {},
|
||||||
|
'name': {},
|
||||||
|
'last_done_batch': {
|
||||||
|
'fields': {
|
||||||
|
'commit_ids': {
|
||||||
|
'fields': {
|
||||||
|
'name': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
).json()
|
||||||
|
"""
|
||||||
|
user = request.env['res.users'].sudo().browse(int(uid))
|
||||||
|
if not user or not token or len(token) < 32 or not consteq(user.runbot_api_token, token):
|
||||||
|
time.sleep(1)
|
||||||
|
return json.dumps({'error': 'Invalid user or token'})
|
||||||
|
request.env.cache.clear()
|
||||||
|
limit = max(min(2000, limit), 1)
|
||||||
|
if not model.startswith('runbot.'):
|
||||||
|
return json.dumps({'error': 'Invalid model'})
|
||||||
|
if id:
|
||||||
|
ids = [id]
|
||||||
|
if ids:
|
||||||
|
domain = [('id', '=', ids)]
|
||||||
|
else:
|
||||||
|
domain = json.loads(domain)
|
||||||
|
if not domain:
|
||||||
|
return json.dumps({'error': 'Invalid domain'})
|
||||||
|
specification = json.loads(specification)
|
||||||
|
|
||||||
|
try:
|
||||||
|
user_env = request.env(user=user)
|
||||||
|
result = user_env[model].web_search_read(domain, specification, limit=limit, offset=offset, order=order)
|
||||||
|
return json.dumps(result)
|
||||||
|
except Exception:
|
||||||
|
_logger.exception('Something went wrong reading %s %s %s', model, specification, domain)
|
||||||
|
return json.dumps({'error': 'Something went wrong'})
|
@ -19,7 +19,7 @@ class BuildErrorLink(models.Model):
|
|||||||
_order = 'log_date desc, build_id desc'
|
_order = 'log_date desc, build_id desc'
|
||||||
|
|
||||||
build_id = fields.Many2one('runbot.build', required=True, index=True)
|
build_id = fields.Many2one('runbot.build', required=True, index=True)
|
||||||
build_error_id =fields.Many2one('runbot.build.error', required=True, index=True)
|
build_error_id = fields.Many2one('runbot.build.error', required=True, index=True, ondelete='cascade')
|
||||||
log_date = fields.Datetime(string='Log date')
|
log_date = fields.Datetime(string='Log date')
|
||||||
host = fields.Char(related='build_id.host')
|
host = fields.Char(related='build_id.host')
|
||||||
dest = fields.Char(related='build_id.dest')
|
dest = fields.Char(related='build_id.dest')
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
|
|
||||||
@ -8,3 +9,9 @@ class User(models.Model):
|
|||||||
# Add default action_id
|
# Add default action_id
|
||||||
action_id = fields.Many2one('ir.actions.actions',
|
action_id = fields.Many2one('ir.actions.actions',
|
||||||
default=lambda self: self.env.ref('runbot.open_view_warning_tree', raise_if_not_found=False))
|
default=lambda self: self.env.ref('runbot.open_view_warning_tree', raise_if_not_found=False))
|
||||||
|
runbot_api_token = fields.Char('API Token', help='The token to use to authenticate against the API')
|
||||||
|
|
||||||
|
|
||||||
|
def action_generate_token(self):
|
||||||
|
self.ensure_one()
|
||||||
|
self.runbot_api_token = uuid.uuid4().hex
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
<xpath expr="//notebook" position="inside">
|
<xpath expr="//notebook" position="inside">
|
||||||
<page string="Runbot">
|
<page string="Runbot">
|
||||||
<group>
|
<group>
|
||||||
|
<button type="object" name="action_generate_token" string="Set token"/>
|
||||||
|
<field name="runbot_api_token"/>
|
||||||
<field name="github_login"/>
|
<field name="github_login"/>
|
||||||
<field name="runbot_team_ids"/>
|
<field name="runbot_team_ids"/>
|
||||||
</group>
|
</group>
|
||||||
|
Loading…
Reference in New Issue
Block a user