コード例 #1
0
def apply_propose_remove(header, payload, state):
    propose = task_transaction_pb2.ProposeRemoveTaskOwner()
    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_del_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.REMOVE_TASK_OWNERS,
    ):
        raise InvalidTransaction(
            "There is already an open proposal for REMOVE_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.REMOVE_TASK_OWNERS,
        state=state,
    )
コード例 #2
0
def apply_propose_remove(header, payload, state):
    """Apply the ProposeRemoveTaskAdmins 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_payload = task_transaction_pb2.ProposeRemoveTaskAdmin()
    propose_payload.ParseFromString(payload.content)

    task_admins_address = addresser.make_task_admins_address(
        task_id=propose_payload.task_id, user_id=propose_payload.user_id
    )

    proposal_address = addresser.make_proposal_address(
        propose_payload.task_id, propose_payload.user_id
    )

    state_entries = task_validator.validate_task_rel_del_proposal(
        header=header,
        propose=propose_payload,
        rel_address=task_admins_address,
        state=state,
    )

    if not proposal_validator.has_no_open_proposal(
        state_entries=state_entries,
        object_id=propose_payload.task_id,
        related_id=propose_payload.user_id,
        proposal_address=proposal_address,
        proposal_type=proposal_state_pb2.Proposal.REMOVE_TASK_ADMINS,
    ):
        raise InvalidTransaction(
            "There is already an open proposal for REMOVE_TASK_ADMINS "
            "with task id {} and user id {}".format(
                propose_payload.task_id, propose_payload.user_id
            )
        )
    state_change.propose_task_action(
        state_entries=state_entries,
        header=header,
        payload=propose_payload,
        address=proposal_address,
        proposal_type=proposal_state_pb2.Proposal.REMOVE_TASK_ADMINS,
        state=state,
    )