Skip to content

Commit

Permalink
Move supplier ACL from Tender to Contract
Browse files Browse the repository at this point in the history
  • Loading branch information
VDigitall committed Apr 17, 2020
1 parent 27b24c8 commit d1b5cc0
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/openprocurement/tender/cfaselectionua/models/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Cancellation as BaseCancellation,
validate_features_uniq,
)
from openprocurement.tender.core.utils import get_contract_supplier_permissions


class Cancellation(BaseCancellation):
Expand Down Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/openprocurement/tender/competitivedialogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -397,9 +397,6 @@ def stage2__acl__(obj):
]
)

suppliers_permissions = get_contract_supplier_permissions(obj)
if suppliers_permissions:
acl.extend(suppliers_permissions)
return acl


Expand Down
6 changes: 3 additions & 3 deletions src/openprocurement/tender/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down
22 changes: 9 additions & 13 deletions src/openprocurement/tender/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
4 changes: 0 additions & 4 deletions src/openprocurement/tender/esco/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions src/openprocurement/tender/openeu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/openprocurement/tender/openua/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d1b5cc0

Please sign in to comment.