def apply_propose(header, payload, state):
    propose = task_transaction_pb2.ProposeAddTaskOwner()
    propose.ParseFromString(payload.content)

    task_owners_address = addresser.task.owner.address(propose.task_id, propose.user_id)

    proposal_address = addresser.proposal.address(
        object_id=propose.task_id, target_id=propose.user_id
    )

    state_entries = task_validator.validate_task_rel_proposal(
        header=header, propose=propose, rel_address=task_owners_address, state=state
    )

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

    state_change.propose_task_action(
        state_entries=state_entries,
        header=header,
        payload=propose,
        address=proposal_address,
        proposal_type=proposal_state_pb2.Proposal.ADD_TASK_OWNERS,
        state=state,
    )
def propose_add_task_owner(txn_key, batch_key, proposal_id, task_id, user_id,
                           reason, metadata):
    propose = task_transaction_pb2.ProposeAddTaskOwner(
        proposal_id=proposal_id,
        task_id=task_id,
        user_id=user_id,
        reason=reason,
        metadata=metadata,
    )

    inputs = [
        addresser.user.address(user_id),
        addresser.task.owner.address(task_id, user_id),
        addresser.task.address(task_id),
        addresser.proposal.address(task_id, user_id),
    ]

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

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

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