Esempio n. 1
0
def apply_user_propose(header, payload, state):
    user_proposal = user_transaction_pb2.ProposeUpdateUserManager()
    user_proposal.ParseFromString(payload.content)

    prop_state_entries = _validate_state_and_return_user(header, user_proposal, state)

    state_change.propose_manager_change(
        proposal_state_entries=prop_state_entries,
        header=header,
        user_proposal=user_proposal,
        state=state,
    )
def propose_manager(txn_key, batch_key, proposal_id, user_id, new_manager_id,
                    reason, metadata):
    """Create a BatchList with a ProposeUpdateUserManager transaction
    in it.

    Args:
        txn_key (Key): The transaction signer public/private key pair
        batch_key (Key): The batch signer public/private key pair
        proposal_id (str): The id of the proposal supplied by the rest api.
        user_id (str): The User id of the user whose manager will be updated.
        new_manager_id (str): The new manager's id.
        reason (str): The reason for this update.
        metadata (str): Client supplied metadata.

    Returns:
        tuple
            BatchList, batch header_signature tuple
    """

    propose_update_payload = user_transaction_pb2.ProposeUpdateUserManager(
        proposal_id=proposal_id,
        user_id=user_id,
        new_manager_id=new_manager_id,
        reason=reason,
        metadata=metadata,
    )

    inputs = [
        addresser.user.address(user_id),
        addresser.user.address(new_manager_id),
        addresser.proposal.address(object_id=user_id,
                                   related_id=new_manager_id),
        addresser.user.address(txn_key.public_key),
    ]

    outputs = [
        addresser.proposal.address(object_id=user_id,
                                   related_id=new_manager_id)
    ]

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=propose_update_payload.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.PROPOSE_UPDATE_USER_MANAGER,
        inputs=inputs,
        outputs=outputs,
    )

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