def propose_remove_task_admins(txn_key, batch_key, proposal_id, task_id, user_id, reason, metadata): propose = task_transaction_pb2.ProposeRemoveTaskAdmin( 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.SerializeToString(), message_type=rbac_payload_pb2.RBACPayload.PROPOSE_REMOVE_TASK_ADMINS, ) return make_header_and_batch(rbac_payload, inputs, outputs, txn_key, batch_key)
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.task.admin.address(propose_payload.task_id, propose_payload.user_id) proposal_address = addresser.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, )