Return more information on GET /admin/order

In addition to the info returned by the regular /order endpoint, return
a few more admin-only fields.
This commit is contained in:
Blockstream Satellite 2023-01-31 22:34:02 -03:00
parent 895d9f785f
commit b3454d7340
3 changed files with 22 additions and 4 deletions

View File

@ -21,6 +21,12 @@ class Order(db.Model):
region_code = db.Column(db.Integer)
channel = db.Column(db.Integer, default=1)
invoices = db.relationship('Invoice', backref='order', lazy=True)
tx_confirmations = db.relationship('TxConfirmation',
backref='order',
lazy=True)
rx_confirmations = db.relationship('RxConfirmation',
backref='order',
lazy=True)
class Invoice(db.Model):

View File

@ -16,7 +16,7 @@ from error import get_http_error_resp
from invoice_helpers import new_invoice, pay_invoice
from models import Order, RxConfirmation, TxConfirmation
from regions import region_number_list_to_code
from schemas import order_schema, orders_schema,\
from schemas import admin_order_schema, order_schema, orders_schema,\
order_upload_req_schema, order_bump_schema,\
rx_confirmation_schema, tx_confirmation_schema
import bidding
@ -50,8 +50,8 @@ class OrderResource(Resource):
constants.CHANNEL_INFO[order.channel].user_permissions:
return get_http_error_resp('ORDER_CHANNEL_UNAUTHORIZED_OP',
order.channel)
return order_schema.dump(order)
schema = admin_order_schema if admin_mode else order_schema
return schema.dump(order)
def delete(self, uuid):
admin_mode = request.path.startswith("/admin/")

View File

@ -3,7 +3,8 @@ from datetime import datetime, timedelta
from marshmallow import fields, Schema, validate, ValidationError
from regions import all_region_numbers, region_code_to_number_list
from regions import all_region_numbers, region_code_to_number_list, \
region_id_to_number
import constants
@ -25,6 +26,16 @@ class OrderSchema(Schema):
lambda obj: region_code_to_number_list(obj.region_code))
class AdminOrderSchema(OrderSchema):
channel = fields.Integer()
tx_confirmations = fields.Function(
lambda obj:
[region_id_to_number(x.region_id) for x in obj.tx_confirmations])
rx_confirmations = fields.Function(
lambda obj:
[region_id_to_number(x.region_id) for x in obj.rx_confirmations])
def must_be_region_number(input):
if input not in all_region_numbers:
raise ValidationError(
@ -81,6 +92,7 @@ class RxConfirmationSchema(Schema):
order_schema = OrderSchema()
admin_order_schema = AdminOrderSchema()
order_upload_req_schema = OrderUploadReqSchema()
order_bump_schema = OrderBumpSchema()
orders_schema = OrdersSchema()