def confirm_add_task_admins(txn_key, batch_key, proposal_id, task_id, user_id,
                            reason):
    confirm_payload = task_transaction_pb2.ConfirmAddTaskAdmin(
        proposal_id=proposal_id,
        task_id=task_id,
        user_id=user_id,
        reason=reason)

    inputs = [
        addresser.task.admin.address(task_id, txn_key.public_key),
        addresser.proposal.address(task_id, user_id),
    ]

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

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=confirm_payload.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.CONFIRM_ADD_TASK_ADMINS,
    )

    return make_header_and_batch(rbac_payload, inputs, outputs, txn_key,
                                 batch_key)
Beispiel #2
0
def apply_confirm(header, payload, state, is_remove=False):
    """Apply the (Add | Remove) TaskAdmins transaction.

    Args:
        header (TransactionHeader): The protobuf TransactionHeader.
        payload (RBACPayload): The protobuf RBACPayload.
        state (Context): The class that handles state gets and sets.
        is_remove (boolean): Determines if task admin is being added or removed.

    Raises:
        InvalidTransaction:
            - The transaction is invalid.
    """

    if not is_remove:
        confirm_payload = task_transaction_pb2.ConfirmAddTaskAdmin()
    else:
        confirm_payload = task_transaction_pb2.ConfirmRemoveTaskAdmin()

    confirm_payload.ParseFromString(payload.content)

    task_admins_address = addresser.task.admin.address(confirm_payload.task_id,
                                                       confirm_payload.user_id)

    txn_signer_admin_address = addresser.task.admin.address(
        confirm_payload.task_id, header.signer_public_key)

    state_entries = task_validator.validate_task_admin_or_owner(
        header=header,
        confirm=confirm_payload,
        txn_signer_rel_address=txn_signer_admin_address,
        task_rel_address=task_admins_address,
        state=state,
        is_remove=is_remove,
    )

    state_change.confirm_task_action(
        state_entries=state_entries,
        header=header,
        confirm=confirm_payload,
        task_rel_address=task_admins_address,
        state=state,
        is_remove=is_remove,
    )