Commit 3f08862e authored by mashony's avatar mashony
Browse files

feat: add custom bidder protect function. Add get_auction_procedure api...

feat: add custom bidder protect function. Add get_auction_procedure api endpoint with procedure data
parent 1ec6cf9a
......@@ -121,7 +121,8 @@
"id": "b75870ac-dad1-405a-9aae-ecea87cd38f7",
"scheme": "string",
"legalName": {
"uk_UA": "asd"
"uk_UA": "участник алала",
"en_US": "bidder ENGLISH"
}
},
"additionalIdentifiers": [
......@@ -129,7 +130,8 @@
"id": "b75870ac-dad1-405a-9aae-ecea87cd38f7",
"scheme": "string",
"legalName": {
"uk_UA": "asd"
"uk_UA": "участник алала",
"en_US": "bidder ENGLISH"
}
}
],
......@@ -201,7 +203,8 @@
"id": "b75870ac-dad1-405a-9aae-ecea87cd38f7",
"scheme": "string",
"legalName": {
"uk_UA": "asd"
"uk_UA": "участник фифифиф",
"en_US": "another bidder ENGLISH"
}
},
"additionalIdentifiers": [
......@@ -209,7 +212,8 @@
"id": "b75870ac-dad1-405a-9aae-ecea87cd38f7",
"scheme": "string",
"legalName": {
"uk_UA": "asd"
"uk_UA": "участник фифифиф",
"en_US": "another bidder ENGLISH"
}
}
],
......
......@@ -12,6 +12,8 @@ from prozorro_sale.tools.errors import expects
from prozorro_sale.auction import db, utils, errors, messages, logging
import trafaret as t
from prozorro_sale.auction.utils import get_role_from_context, get_procedure_from_databridge
LOG = logging.get_custom_logger(__name__)
FRONTEND_LOG = logging.get_custom_logger('frontend')
SEVERITY = ('warning', 'error', 'critical')
......@@ -165,6 +167,16 @@ async def post_bid_auction(request, auction_id):
return web.json_response(msg, status=201, dumps=ujson.dumps)
async def get_auction_procedure_data(request, auction_id):
"""
Get procedure data depends on a role.
"""
_auction = await db.read_auction(auction_id)
role = get_role_from_context(_auction, request._context)
procedure_data = await get_procedure_from_databridge(_auction.procedureId, role)
return web.json_response(procedure_data, status=200, dumps=ujson.dumps)
@swagger_path('/swagger/cancel_bid_auction.yaml')
@utils.expects({errors.ForbiddenStateError: (400, messages.CANNOT_CANCEL_BID)})
@utils.auth_token_required
......
......@@ -20,6 +20,7 @@ routes = [
web.get('/api/auctions/{auction_id}/protocol', api.generate_protocol, allow_head=False),
web.get('/api/auctions/{auction_id}/protocol/yaml', api.generate_protocol_yaml, allow_head=False),
web.get('/api/auctions/{auction_id}/logout', api.logout_auction, allow_head=False),
web.get('/api/auctions/{auction_id}/procedure_data', api.get_auction_procedure_data, allow_head=False),
web.post('/api/auctions/rooms', room_api.create_room),
web.get('/api/auctions/rooms/{room_id}/feed', room_api.room_feed, allow_head=False),
......
......@@ -77,9 +77,13 @@ class UnverifiedTokenError(AuctionException):
class ProcedureNotFound(AuctionException):
""" Class for custom exception in case of non existing procedure. """
def __init__(self, object_id):
LOG.info(f'Procedure with auctionId {object_id} not found')
super().__init__(f'Procedure with auctionId {object_id} not found')
def __init__(self, object_id, procedure_id=None):
if not object_id and procedure_id:
message = f'Procedure with procedureId {procedure_id} not found'
else:
message = f'Procedure with auctionId {object_id} not found'
LOG.info(message)
super().__init__(message)
class RemoteServiceBroken(AuctionException):
......
import random
from hashlib import blake2b
class ProtectMap:
......@@ -41,10 +42,13 @@ class ProtectMap:
child_conf = NestF(config.name, config.fields_set.values())
else:
child_conf = config.fields_set[child_key]
if isinstance(child_val, (dict, list, tuple)):
value[child_key] = self._protect(child_val, child_conf)
if isinstance(child_conf, NestF) and child_conf.func:
value[child_key] = child_conf.func(child_val, child_conf)
else:
value[child_key] = self.protect_primitive(child_val)
if isinstance(child_val, (dict, list, tuple)):
value[child_key] = self._protect(child_val, child_conf)
else:
value[child_key] = self.protect_primitive(child_val)
if isinstance(value, (list, tuple)):
for indx, child_val in enumerate(value):
if isinstance(child_val, (dict, list, tuple)):
......@@ -61,21 +65,23 @@ class NestF:
"""
nested field obj
"""
__slots__ = ['name', 'fields_set', 'normalized']
__slots__ = ['name', 'fields_set', 'normalized', 'func']
def _init_fields_map(self, data):
fields_map = {}
for item in data:
if isinstance(item, NestF):
fields_map[item.name] = item
else:
fields_map[item] = item
if data:
for item in data:
if isinstance(item, NestF):
fields_map[item.name] = item
else:
fields_map[item] = item
return fields_map
def __init__(self, name, fields_map=None, normalized=False):
def __init__(self, name, fields_map=None, normalized=False, func=None):
self.name = name
self.fields_set = self._init_fields_map(fields_map)
self.normalized = normalized
self.func = func
def __hash__(self):
return hash(self.name)
......@@ -84,6 +90,14 @@ class NestF:
return self.name == other
def anon_bidder(lang):
def _wr(value, conf):
h = blake2b(digest_size=4)
h.update(value.encode('utf-8'))
return f'{"Учасник" if lang == "uk" else "Bidder"} {h.hexdigest()}'
return _wr
def get_protected_auction_config():
# todo simplify comfig
address_config = {
......@@ -108,7 +122,10 @@ def get_protected_auction_config():
}),
NestF("identifier", {
"id",
NestF("legalName", {"uk_UA", "en_US"}),
NestF("legalName", {
NestF("uk_UA", func=anon_bidder("uk")),
NestF("en_US", func=anon_bidder("en"))
}),
}),
NestF("additionalIdentifiers", {
"id",
......
......@@ -537,6 +537,22 @@ def get_procedure(auction_id):
return resp.json()
async def get_procedure_from_databridge(procedure_id, role):
"""
get procedure from procedure databridge
"""
protect = str(int(role == 'public'))
async with ClientSession() as session:
async with session.get(
f"http://{ENV_VARS.PROCEDURE_DATABRIDGE}"
f"/api/procedure/{procedure_id}?protect={protect}"
) as resp:
if resp.status == 200:
data = await resp.json()
return data
raise errors.ProcedureNotFound(None, procedure_id)
def patch_model_to_definition(func):
"""
Decorator for excluding model properties.
......
......@@ -58,7 +58,7 @@
}),
'identifier': dict({
'legalName': dict({
'uk_UA': '*****',
'uk_UA': 'Учасник 9afa5c1d',
}),
'scheme': 'string',
}),
......@@ -72,7 +72,8 @@
'additionalIdentifiers': list([
dict({
'legalName': dict({
'uk_UA': '*****',
'en_US': '***** ***** ***** ***** *****',
'uk_UA': '***** ***** ***** *****',
}),
'scheme': 'string',
}),
......@@ -101,7 +102,8 @@
}),
'identifier': dict({
'legalName': dict({
'uk_UA': '*****',
'en_US': 'Bidder aa15efa6',
'uk_UA': 'Учасник 0e625f3d',
}),
'scheme': 'string',
}),
......@@ -115,7 +117,8 @@
'additionalIdentifiers': list([
dict({
'legalName': dict({
'uk_UA': '*****',
'en_US': '***** ***** *****',
'uk_UA': '***** ***** *****',
}),
'scheme': 'string',
}),
......@@ -144,7 +147,8 @@
}),
'identifier': dict({
'legalName': dict({
'uk_UA': '*****',
'en_US': 'Bidder 92ecb461',
'uk_UA': 'Учасник 8b18a5ad',
}),
'scheme': 'string',
}),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment