コード例 #1
0
def apply_propose_remove(header, payload, state):
    proposal_payload = role_transaction_pb2.ProposeRemoveRoleMember()
    proposal_payload.ParseFromString(payload.content)

    role_owners_address = addresser.role.owner.address(
        proposal_payload.role_id, proposal_payload.user_id)

    proposal_address = addresser.proposal.address(
        object_id=proposal_payload.role_id, target_id=proposal_payload.user_id)

    state_entries = role_validator.validate_role_rel_proposal(
        header, proposal_payload, role_owners_address, state, True)

    if not proposal_validator.has_no_open_proposal(
            state_entries=state_entries,
            object_id=proposal_payload.role_id,
            related_id=proposal_payload.user_id,
            proposal_address=proposal_address,
            proposal_type=proposal_state_pb2.Proposal.REMOVE_ROLE_OWNERS,
    ):
        raise InvalidTransaction(
            "There is already an open proposal for REMOVE_ROLE_OWNERS "
            "with role id {} and user id {}".format(proposal_payload.role_id,
                                                    proposal_payload.user_id))

    state_change.propose_role_action(
        state_entries=state_entries,
        header=header,
        payload=proposal_payload,
        address=proposal_address,
        proposal_type=proposal_state_pb2.Proposal.REMOVE_ROLE_OWNERS,
        state=state,
    )
コード例 #2
0
def propose_remove_role_members(txn_key, batch_key, proposal_id, role_id,
                                user_id, reason, metadata):
    propose = role_transaction_pb2.ProposeRemoveRoleMember(
        proposal_id=proposal_id,
        role_id=role_id,
        user_id=user_id,
        reason=reason,
        metadata=metadata,
    )

    inputs = [
        addresser.role.member.address(role_id, user_id),
        addresser.role.address(role_id),
        addresser.user.address(user_id),
        addresser.proposal.address(role_id, user_id),
    ]

    outputs = [addresser.proposal.address(role_id, user_id)]

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=propose.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.PROPOSE_REMOVE_ROLE_MEMBER,
    )

    return make_header_and_batch(rbac_payload, inputs, outputs, txn_key,
                                 batch_key)