Example #1
0
    def delete(self, offer_id):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:offer:delete', cdict, cdict)

        o_id = offer.Offer.get(offer_id)

        permission = []
        for o in o_id:
            try:
                if o.project_id != request.project_id:
                    policy.authorize('esi_leap:offer:offer_admin', cdict,
                                     cdict)
                permission.append(o)
            except oslo_policy.PolicyNotAuthorized:
                continue
            if len(permission) > 1:
                raise exception.ContractDuplicateName(name=offer_id)

        if len(permission) == 0:
            raise exception.OfferNotFound(offer_id=offer_id)

        OffersController._verify_resource_permission(cdict, o_id[0].to_dict())

        o_id[0].cancel()
Example #2
0
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]
Example #3
0
    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]