def apply_propose(header, payload, state): role_admins_payload = role_transaction_pb2.ProposeAddRoleAdmin() role_admins_payload.ParseFromString(payload.content) role_admins_address = addresser.make_role_admins_address( role_id=role_admins_payload.role_id, user_id=role_admins_payload.user_id) proposal_address = addresser.make_proposal_address( object_id=role_admins_payload.role_id, related_id=role_admins_payload.user_id) state_entries = role_validator.validate_role_rel_proposal( header, role_admins_payload, role_admins_address, state) if not proposal_validator.has_no_open_proposal( state_entries=state_entries, object_id=role_admins_payload.role_id, related_id=role_admins_payload.user_id, proposal_address=proposal_address, proposal_type=proposal_state_pb2.Proposal.ADD_ROLE_ADMINS, ): raise InvalidTransaction( "There is already an open proposal for ADD_ROLE_ADMINS " "with role id {} and user id {}".format( role_admins_payload.role_id, role_admins_payload.user_id)) state_change.propose_role_action( state_entries=state_entries, header=header, payload=role_admins_payload, address=proposal_address, proposal_type=proposal_state_pb2.Proposal.ADD_ROLE_ADMINS, state=state, )
def propose_add_role_admins(txn_key, batch_key, proposal_id, role_id, user_id, reason, metadata): """Create a BatchList with a ProposeAddRoleAdmins transaction in it. Args: txn_key (Key): The txn signer key pair. batch_key (Key): The batch signer key pair. role_id (str): The role's id. user_id (str): The user that is being proposed to be an admin. reason (str): The client supplied reason for the proposal. metadata (str): The client supplied metadata. Returns: tuple BatchList, batch header_signature tuple """ propose_add_payload = role_transaction_pb2.ProposeAddRoleAdmin( proposal_id=proposal_id, role_id=role_id, user_id=user_id, reason=reason, metadata=metadata, ) inputs = [ addresser.user.address(user_id), addresser.user.address(txn_key.public_key), addresser.proposal.address(role_id, user_id), addresser.role.admin.address(role_id, user_id), addresser.role.address(role_id), ] outputs = [addresser.proposal.address(role_id, user_id)] rbac_payload = rbac_payload_pb2.RBACPayload( content=propose_add_payload.SerializeToString(), message_type=rbac_payload_pb2.RBACPayload.PROPOSE_ADD_ROLE_ADMIN, inputs=inputs, outputs=outputs, ) return make_header_and_batch(rbac_payload, inputs, outputs, txn_key, batch_key)