Skip to content

Commit

Permalink
Fixed validation bid document upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Nov 21, 2016
1 parent 057ad4d commit e3552c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
11 changes: 9 additions & 2 deletions openprocurement/auctions/flash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class Guarantee(Model):
currency = StringType(required=True, default=u'UAH', max_length=3, min_length=3) # The currency in 3-letter ISO 4217 format.


class AuctionPeriodEndRequired(PeriodEndRequired):

def validate_startDate(self, data, period):
if period and data.get('endDate') and data.get('endDate') < period:
raise ValidationError(u"period should begin before its end")


def calc_auction_end_time(bids, start):
return start + bids * BIDDER_TIME + SERVICE_TIME + AUCTION_STAND_STILL_TIME

Expand Down Expand Up @@ -520,8 +527,8 @@ def __local_roles__(self):
submissionMethodDetails = StringType() # Any detailed or further information on the submission method.
submissionMethodDetails_en = StringType()
submissionMethodDetails_ru = StringType()
enquiryPeriod = ModelType(PeriodEndRequired, required=True) # The period during which enquiries may be made and will be answered.
tenderPeriod = ModelType(PeriodEndRequired, required=True) # The period when the auction is open for submissions. The end date is the closing date for auction submissions.
enquiryPeriod = ModelType(AuctionPeriodEndRequired, required=True) # The period during which enquiries may be made and will be answered.
tenderPeriod = ModelType(AuctionPeriodEndRequired, required=True) # The period when the auction is open for submissions. The end date is the closing date for auction submissions.
hasEnquiries = BooleanType() # A Yes/No field as to whether enquiries were part of auction process.
eligibilityCriteria = StringType() # A description of any eligibility criteria for potential suppliers.
eligibilityCriteria_en = StringType()
Expand Down
8 changes: 8 additions & 0 deletions openprocurement/auctions/flash/tests/bidder.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,14 @@ def test_create_auction_bidder_document(self):
self.assertEqual(doc_id, response.json["data"]["id"])
self.assertEqual('name.doc', response.json["data"]["title"])

self.set_status('active.awarded', {'status': 'active.tendering'})

response = self.app.post('/auctions/{}/bids/{}/documents'.format(
self.auction_id, self.bid_id), upload_files=[('file', 'name.doc', 'content')], status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertIn("Document can be added only during the tendering period: from", response.json['errors'][0]["description"])

self.set_status('active.awarded')

response = self.app.post('/auctions/{}/bids/{}/documents'.format(
Expand Down
55 changes: 19 additions & 36 deletions openprocurement/auctions/flash/views/bid_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
description="Auction bidder documents")
class AuctionBidDocumentResource(APIResource):

def validate_bid_document(self, operation):
auction = self.request.validated['auction']
if auction.status not in ['active.tendering', 'active.qualification']:
self.request.errors.add('body', 'data', 'Can\'t {} document in current ({}) auction status'.format(operation, auction.status))
self.request.errors.status = 403
return
if auction.status == 'active.tendering' and (auction.tenderPeriod.startDate and get_now() < auction.tenderPeriod.startDate or get_now() > auction.tenderPeriod.endDate):
self.request.errors.add('body', 'data', 'Document can be {} only during the tendering period: from ({}) to ({}).'.format('added' if operation == 'add' else 'updated', auction.tenderPeriod.startDate.isoformat(), auction.tenderPeriod.endDate.isoformat()))
self.request.errors.status = 403
return
if auction.status == 'active.qualification' and not [i for i in auction.awards if i.status == 'pending' and i.bid_id == self.request.validated['bid_id']]:
self.request.errors.add('body', 'data', 'Can\'t {} document because award of bid is not in pending state'.format(operation))
self.request.errors.status = 403
return
return True

@json_view(permission='view_auction')
def collection_get(self):
"""Auction Bid Documents List"""
Expand All @@ -47,18 +63,7 @@ def collection_get(self):
def collection_post(self):
"""Auction Bid Document Upload
"""
if self.request.validated['auction_status'] not in ['active.tendering', 'active.qualification']:
self.request.errors.add('body', 'data', 'Can\'t add document in current ({}) auction status'.format(self.request.validated['auction_status']))
self.request.errors.status = 403
return
auction = self.request.validated['auction']
if self.request.validated['auction_status'] == 'active.tendering' and (auction.tenderPeriod.startDate and get_now() < auction.tenderPeriod.startDate or get_now() > auction.tenderPeriod.endDate):
self.request.errors.add('body', 'data', 'Document can be added only during the tendering period: from ({}) to ({}).'.format(auction.auctionPeriod.startDate and auction.auctionPeriod.startDate.isoformat(), auction.auctionPeriod.endDate.isoformat()))
self.request.errors.status = 403
return
if self.request.validated['auction_status'] == 'active.qualification' and not [i for i in self.request.validated['auction'].awards if i.status == 'pending' and i.bid_id == self.request.validated['bid_id']]:
self.request.errors.add('body', 'data', 'Can\'t add document because award of bid is not in pending state')
self.request.errors.status = 403
if not self.validate_bid_document('add'):
return
document = upload_file(self.request)
self.context.documents.append(document)
Expand Down Expand Up @@ -93,18 +98,7 @@ def get(self):
@json_view(validators=(validate_file_update,), permission='edit_bid')
def put(self):
"""Auction Bid Document Update"""
if self.request.validated['auction_status'] not in ['active.tendering', 'active.qualification']:
self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) auction status'.format(self.request.validated['auction_status']))
self.request.errors.status = 403
return
auction = self.request.validated['auction']
if self.request.validated['auction_status'] == 'active.tendering' and (auction.tenderPeriod.startDate and get_now() < auction.tenderPeriod.startDate or get_now() > auction.tenderPeriod.endDate):
self.request.errors.add('body', 'data', 'Document can be updated only during the tendering period: from ({}) to ({}).'.format(auction.auctionPeriod.startDate and auction.auctionPeriod.startDate.isoformat(), auction.auctionPeriod.endDate.isoformat()))
self.request.errors.status = 403
return
if self.request.validated['auction_status'] == 'active.qualification' and not [i for i in self.request.validated['auction'].awards if i.status == 'pending' and i.bid_id == self.request.validated['bid_id']]:
self.request.errors.add('body', 'data', 'Can\'t update document because award of bid is not in pending state')
self.request.errors.status = 403
if not self.validate_bid_document('update'):
return
document = upload_file(self.request)
self.request.validated['bid'].documents.append(document)
Expand All @@ -118,18 +112,7 @@ def put(self):
@json_view(content_type="application/json", validators=(validate_patch_document_data,), permission='edit_bid')
def patch(self):
"""Auction Bid Document Update"""
if self.request.validated['auction_status'] not in ['active.tendering', 'active.qualification']:
self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) auction status'.format(self.request.validated['auction_status']))
self.request.errors.status = 403
return
auction = self.request.validated['auction']
if self.request.validated['auction_status'] == 'active.tendering' and (auction.tenderPeriod.startDate and get_now() < auction.tenderPeriod.startDate or get_now() > auction.tenderPeriod.endDate):
self.request.errors.add('body', 'data', 'Document can be updated only during the tendering period: from ({}) to ({}).'.format(auction.auctionPeriod.startDate and auction.auctionPeriod.startDate.isoformat(), auction.auctionPeriod.endDate.isoformat()))
self.request.errors.status = 403
return
if self.request.validated['auction_status'] == 'active.qualification' and not [i for i in self.request.validated['auction'].awards if i.status == 'pending' and i.bid_id == self.request.validated['bid_id']]:
self.request.errors.add('body', 'data', 'Can\'t update document because award of bid is not in pending state')
self.request.errors.status = 403
if not self.validate_bid_document('update'):
return
if self.request.validated['auction_status'] == 'active.tendering':
self.request.validated['auction'].modified = False
Expand Down

0 comments on commit e3552c2

Please sign in to comment.