def propose_add_task_admins(txn_key, batch_key, proposal_id, task_id, user_id,
                            reason, metadata):
    propose_payload = task_transaction_pb2.ProposeAddTaskAdmin(
        proposal_id=proposal_id,
        task_id=task_id,
        user_id=user_id,
        reason=reason,
        metadata=metadata,
    )

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

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

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=propose_payload.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.PROPOSE_ADD_TASK_ADMINS,
    )

    return make_header_and_batch(rbac_payload, inputs, outputs, txn_key,
                                 batch_key)
Exemple #2
0
def apply_propose(header, payload, state):
    """Apply the ProposeAddTaskAdmins transaction.

    Args:
        header (TransactionHeader): The protobuf TransactionHeader.
        payload (RBACPayload): The protobuf RBACPayload.
        state (Context): The class that handles state gets and sets.

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

    propose = task_transaction_pb2.ProposeAddTaskAdmin()
    propose.ParseFromString(payload.content)

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

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

    state_entries = task_validator.validate_task_rel_proposal(
        header=header,
        propose=propose,
        rel_address=task_admins_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_ADMINS,
    ):
        raise InvalidTransaction(
            "There is already an open proposal for ADD_TASK_ADMINS "
            "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_ADMINS,
        state=state,
    )