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 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, )