def _handle_task_rel_container(state_entries, create_task, pubkeys_by_address, state): entries_to_set = {} for addr, pubkeys in pubkeys_by_address.items(): try: state_entry = get_state_entry(state_entries, addr) container = task_state_pb2.TaskRelationshipContainer() container.ParseFromString(state_entry.data) except KeyError: container = task_state_pb2.TaskRelationshipContainer() _add_task_rel_to_container(container, create_task.task_id, pubkeys) entries_to_set[addr] = container.SerializeToString() return entries_to_set
def handle_confirm(state_entries, header, confirm, task_rel_address, state, is_remove): """ Updates proposal and task relationship objects according to the task admin/owner transaction. Args: state_entries: List of states for the proposal, task relationship, and task admins object. header (TransactionHeader): The protobuf TransactionHeader. confirm (RBACPayload): The protobuf RBACPayload. task_rel_address (str): The task relationship address. state (Context): The class that handles state gets and sets. is_remove (boolean): Determines if task admin/owner is being removed or added. """ proposal_address = addresser.make_proposal_address( object_id=confirm.task_id, related_id=confirm.user_id) proposal_entry = get_state_entry(state_entries, proposal_address) proposal_container = return_prop_container(proposal_entry) proposal = get_prop_from_container(proposal_container, proposal_id=confirm.proposal_id) proposal.status = proposal_state_pb2.Proposal.CONFIRMED proposal.closer = header.signer_public_key proposal.close_reason = confirm.reason address_values = {proposal_address: proposal_container.SerializeToString()} try: task_rel_entry = get_state_entry(state_entries, task_rel_address) task_rel_container = return_task_rel_container(task_rel_entry) except KeyError: task_rel_container = task_state_pb2.TaskRelationshipContainer() try: task_rel = get_task_rel_from_container(container=task_rel_container, task_id=confirm.task_id, identifier=confirm.user_id) except KeyError: task_rel = task_rel_container.relationships.add() task_rel.task_id = confirm.task_id if not is_remove: task_rel.identifiers.append(confirm.user_id) else: task_rel.identifiers.remove(confirm.user_id) address_values[task_rel_address] = task_rel_container.SerializeToString() set_state(state, address_values)
def handle_confirm_add(state_entries, header, confirm, task_rel_address, state): proposal_address = addresser.make_proposal_address( object_id=confirm.task_id, related_id=confirm.user_id) proposal_entry = get_state_entry(state_entries, proposal_address) proposal_container = return_prop_container(proposal_entry) proposal = get_prop_from_container( proposal_container, proposal_id=confirm.proposal_id) proposal.status = proposal_state_pb2.Proposal.CONFIRMED proposal.closer = header.signer_public_key proposal.close_reason = confirm.reason address_values = { proposal_address: proposal_container.SerializeToString() } try: task_rel_entry = get_state_entry(state_entries, task_rel_address) task_rel_container = return_task_rel_container(task_rel_entry) except KeyError: task_rel_container = task_state_pb2.TaskRelationshipContainer() try: task_rel = get_task_rel_from_container( container=task_rel_container, task_id=confirm.task_id, identifier=confirm.user_id) except KeyError: task_rel = task_rel_container.relationships.add() task_rel.task_id = confirm.task_id task_rel.identifiers.append(confirm.user_id) address_values[task_rel_address] = task_rel_container.SerializeToString() set_state(state, address_values)
def return_task_rel_container(entry): task_rel_container = task_state_pb2.TaskRelationshipContainer() task_rel_container.ParseFromString(entry.data) return task_rel_container