def contract_destroy(contract_uuid): query = model_query(models.Contract, get_session()) contract_ref = query.filter_by(uuid=contract_uuid).one_or_none() if not contract_ref: raise exception.ContractNotFound(contract_uuid=contract_uuid) query.delete()
def get_contract_authorized(uuid_or_name, cdict, status_filters=[]): if uuidutils.is_uuid_like(uuid_or_name): c = contract.Contract.get(uuid_or_name) contract_objs = [] if not status_filters or c.status in status_filters: contract_objs.append(c) else: contract_objs = contract.Contract.get_all({ 'name': uuid_or_name, 'status': status_filters }) permitted = [] for c in contract_objs: try: contract_authorize_management(c, cdict) permitted.append(c) except oslo_policy.PolicyNotAuthorized: continue if len(permitted) > 1: raise exception.ContractDuplicateName(name=uuid_or_name) if len(permitted) == 0: raise exception.ContractNotFound(contract_id=uuid_or_name) return permitted[0]
def contract_destroy(context, contract_uuid): contract_ref = contract_get(context, contract_uuid) if not contract_ref: raise exception.ContractNotFound(contract_uuid=contract_uuid) if not context.is_admin: if context.project_id != contract_ref.project_id: raise exception.ContractNoPermission(contract_uuid=contract_uuid) model_query(context, models.Contract, get_session()).filter_by(uuid=contract_uuid).delete()
def contract_get(context, contract_uuid): query = model_query(context, models.Contract, get_session()) result = query.filter_by(uuid=contract_uuid).first() if not result: raise exception.ContractNotFound(contract_uuid=contract_uuid) if not context.is_admin: if context.project_id != result.project_id: raise exception.ContractNoPermission(contract_uuid=contract_uuid) return result
def _contract_get_authorized_contract(contract_id, cdict): contract_objs = contract.Contract.get(contract_id) permitted = [] for c in contract_objs: try: ContractsController._contract_authorize_management(c, cdict) permitted.append(c) except oslo_policy.PolicyNotAuthorized: continue if len(permitted) > 1: raise exception.ContractDuplicateName(name=contract_id) if len(permitted) == 0: raise exception.ContractNotFound(contract_id=contract_id) return permitted[0]