From d1b5cc047932dc28f06b2bec0a35798d0b02d886 Mon Sep 17 00:00:00 2001 From: Vitalii Martyniak Date: Tue, 14 Apr 2020 16:23:20 +0300 Subject: [PATCH] Move supplier ACL from Tender to Contract --- .../models/submodels/contract.py | 5 ++++- .../tender/cfaselectionua/models/tender.py | 4 ---- .../tender/competitivedialogue/models.py | 5 +---- src/openprocurement/tender/core/models.py | 6 ++--- src/openprocurement/tender/core/utils.py | 22 ++++++++----------- src/openprocurement/tender/esco/models.py | 4 ---- src/openprocurement/tender/openeu/models.py | 4 ---- src/openprocurement/tender/openua/models.py | 5 +---- 8 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/openprocurement/tender/cfaselectionua/models/submodels/contract.py b/src/openprocurement/tender/cfaselectionua/models/submodels/contract.py index 3b66967bac..9e5f9f3663 100644 --- a/src/openprocurement/tender/cfaselectionua/models/submodels/contract.py +++ b/src/openprocurement/tender/cfaselectionua/models/submodels/contract.py @@ -4,7 +4,7 @@ from schematics.types.compound import ModelType from schematics.types import StringType from openprocurement.tender.core.models import ContractValue -from openprocurement.tender.core.utils import get_contract_supplier_roles +from openprocurement.tender.core.utils import get_contract_supplier_roles, get_contract_supplier_permissions from openprocurement.api.utils import get_now from openprocurement.api.models import Model, ListType, Contract as BaseContract, Document @@ -17,6 +17,9 @@ class Options: awardID = StringType(required=True) documents = ListType(ModelType(Document, required=True), default=list()) + def __acl__(self): + return get_contract_supplier_permissions(self) + def get_role(self): root = self.get_root() request = root.request diff --git a/src/openprocurement/tender/cfaselectionua/models/tender.py b/src/openprocurement/tender/cfaselectionua/models/tender.py index 2b1721b71e..32946860c7 100644 --- a/src/openprocurement/tender/cfaselectionua/models/tender.py +++ b/src/openprocurement/tender/cfaselectionua/models/tender.py @@ -23,7 +23,6 @@ Cancellation as BaseCancellation, validate_features_uniq, ) -from openprocurement.tender.core.utils import get_contract_supplier_permissions class Cancellation(BaseCancellation): @@ -233,9 +232,6 @@ def __acl__(self): (Allow, "g:brokers", "create_cancellation_complaint") ] ) - suppliers_permissions = get_contract_supplier_permissions(self) - if suppliers_permissions: - acl.extend(suppliers_permissions) self._acl_cancellation(acl) return acl diff --git a/src/openprocurement/tender/competitivedialogue/models.py b/src/openprocurement/tender/competitivedialogue/models.py index a6249daad7..db704b7d53 100644 --- a/src/openprocurement/tender/competitivedialogue/models.py +++ b/src/openprocurement/tender/competitivedialogue/models.py @@ -33,7 +33,7 @@ Lot as BaseLotUA, EUConfidentialDocument, ) -from openprocurement.tender.core.utils import calculate_tender_business_date, get_contract_supplier_permissions +from openprocurement.tender.core.utils import calculate_tender_business_date from openprocurement.tender.openua.models import Item as BaseUAItem, Tender as BaseTenderUA from openprocurement.tender.openua.constants import TENDER_PERIOD as TENDERING_DURATION_UA from openprocurement.tender.openeu.models import ( @@ -397,9 +397,6 @@ def stage2__acl__(obj): ] ) - suppliers_permissions = get_contract_supplier_permissions(obj) - if suppliers_permissions: - acl.extend(suppliers_permissions) return acl diff --git a/src/openprocurement/tender/core/models.py b/src/openprocurement/tender/core/models.py index 47d60efa9f..71dcd634ee 100644 --- a/src/openprocurement/tender/core/models.py +++ b/src/openprocurement/tender/core/models.py @@ -386,6 +386,9 @@ class Options: awardID = StringType(required=True) documents = ListType(ModelType(Document, required=True), default=list()) + def __acl__(self): + return get_contract_supplier_permissions(self) + def get_role(self): root = self.get_root() request = root.request @@ -1420,9 +1423,6 @@ def get_role(self): def __acl__(self): acl = [(Allow, "{}_{}".format(i.owner, i.owner_token), "create_award_complaint") for i in self.bids] - suppliers_permissions = get_contract_supplier_permissions(self) - if suppliers_permissions: - acl.extend(suppliers_permissions) acl.extend( [ (Allow, "{}_{}".format(self.owner, self.owner_token), "edit_complaint"), diff --git a/src/openprocurement/tender/core/utils.py b/src/openprocurement/tender/core/utils.py index 234dabf7a6..aac5ffeda2 100644 --- a/src/openprocurement/tender/core/utils.py +++ b/src/openprocurement/tender/core/utils.py @@ -577,19 +577,17 @@ def check_complaints(complaints): check_complaints(award.complaints) -def get_contract_supplier_permissions(tender): +def get_contract_supplier_permissions(contract): """ Set `upload_contract_document` permissions for award in `active` status owners """ suppliers_permissions = [] - if tender.get('bids', []) and tender.get('awards', []): - win_bids = jmespath.search("awards[?status=='active'].bid_id", tender._data) or [] - for bid in tender.bids: - if bid.status == "active" and bid.id in win_bids: - suppliers_permissions.append( - (Allow, "{}_{}".format(bid.owner, bid.owner_token), "upload_contract_documents") - ) - suppliers_permissions.append((Allow, "{}_{}".format(bid.owner, bid.owner_token), "edit_contract")) + if not hasattr(contract, "__parent__") or 'bids' not in contract.__parent__: + return suppliers_permissions + win_bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract.awardID), contract.__parent__._data)[0] + win_bid = jmespath.search("bids[?id=='{}'].[owner,owner_token]".format(win_bid_id), contract.__parent__._data)[0] + bid_acl = "_".join(win_bid) + suppliers_permissions.extend([(Allow, bid_acl, "upload_contract_documents"), (Allow, bid_acl, "edit_contract")]) return suppliers_permissions @@ -598,8 +596,6 @@ def get_contract_supplier_roles(contract): if 'bids' not in contract.__parent__: return roles bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract.awardID), contract.__parent__)[0] - tokens = jmespath.search("bids[?id=='{}'].[owner,owner_token]".format(bid_id), contract.__parent__) - if tokens: - for item in tokens: - roles['_'.join(item)] = 'contract_supplier' + bid_data = jmespath.search("bids[?id=='{}'].[owner,owner_token]".format(bid_id), contract.__parent__)[0] + roles['_'.join(bid_data)] = 'contract_supplier' return roles diff --git a/src/openprocurement/tender/esco/models.py b/src/openprocurement/tender/esco/models.py index e5a8744155..6a98adcba2 100644 --- a/src/openprocurement/tender/esco/models.py +++ b/src/openprocurement/tender/esco/models.py @@ -56,7 +56,6 @@ extend_next_check_by_complaint_period_ends, ) from openprocurement.tender.core.constants import CPV_ITEMS_CLASS_FROM -from openprocurement.tender.core.utils import get_contract_supplier_permissions from openprocurement.tender.openua.models import Tender as OpenUATender from openprocurement.tender.openua.constants import COMPLAINT_SUBMIT_TIME, ENQUIRY_STAND_STILL_TIME, AUCTION_PERIOD_TIME from openprocurement.tender.openeu.models import ( @@ -663,9 +662,6 @@ def __acl__(self): self._acl_cancellation_complaint(acl) - suppliers_permissions = get_contract_supplier_permissions(self) - if suppliers_permissions: - acl.extend(suppliers_permissions) return acl @serializable(serialized_name="enquiryPeriod", type=ModelType(EnquiryPeriod)) diff --git a/src/openprocurement/tender/openeu/models.py b/src/openprocurement/tender/openeu/models.py index 2f18c836b3..73aeb2e6dc 100644 --- a/src/openprocurement/tender/openeu/models.py +++ b/src/openprocurement/tender/openeu/models.py @@ -54,7 +54,6 @@ calculate_complaint_business_date, calculate_clarifications_business_date, extend_next_check_by_complaint_period_ends, - get_contract_supplier_permissions, ) from openprocurement.tender.belowthreshold.models import Tender as BaseTender from openprocurement.tender.core.validation import validate_lotvalue_value, validate_relatedlot @@ -652,9 +651,6 @@ def __acl__(self): ] ) - suppliers_permissions = get_contract_supplier_permissions(self) - if suppliers_permissions: - acl.extend(suppliers_permissions) self._acl_cancellation_complaint(acl) return acl diff --git a/src/openprocurement/tender/openua/models.py b/src/openprocurement/tender/openua/models.py index fc93ca8e3b..684c7b15cd 100644 --- a/src/openprocurement/tender/openua/models.py +++ b/src/openprocurement/tender/openua/models.py @@ -57,7 +57,6 @@ calculate_complaint_business_date, calculate_clarifications_business_date, extend_next_check_by_complaint_period_ends, - get_contract_supplier_permissions, ) from openprocurement.tender.core.validation import validate_lotvalue_value, validate_relatedlot from openprocurement.tender.belowthreshold.models import Tender as BaseTender @@ -616,9 +615,7 @@ def __acl__(self): (Allow, "{}_{}".format(self.owner, self.owner_token), "upload_contract_documents"), ] ) - suppliers_permissions = get_contract_supplier_permissions(self) - if suppliers_permissions: - acl.extend(suppliers_permissions) + self._acl_cancellation_complaint(acl) return acl