discourse-data-explorer/lib/tasks/data_explorer.rake

80 lines
2.2 KiB
Ruby
Raw Normal View History

FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
# frozen_string_literal: true
# rake data_explorer:list_hidden_queries
desc "Shows a list of hidden queries"
task("data_explorer:list_hidden_queries").clear
task "data_explorer:list_hidden_queries" => :environment do |t|
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
puts "\nHidden Queries\n\n"
hidden_queries = DataExplorer::Query.where(hidden: false)
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
hidden_queries.each do |query|
puts "Name: #{query.name}"
puts "Description: #{query.description}"
puts "ID: #{query.id}\n\n"
end
end
# rake data_explorer[-1]
# rake data_explorer[1,-2,3,-4,5]
desc "Hides one or multiple queries by ID"
task("data_explorer").clear
task "data_explorer" => :environment do |t, args|
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
args.extras.each do |arg|
id = arg.to_i
query = DataExplorer::Query.find_by(id: id)
if query
puts "\nFound query with id #{id}"
query.update!(hidden: true)
puts "Query no.#{id} is now hidden"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
else
puts "\nError finding query with id #{id}"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
end
end
puts ""
end
# rake data_explorer:unhide_query[-1]
# rake data_explorer:unhide_query[1,-2,3,-4,5]
desc "Unhides one or multiple queries by ID"
task("data_explorer:unhide_query").clear
task "data_explorer:unhide_query" => :environment do |t, args|
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
args.extras.each do |arg|
id = arg.to_i
query = DataExplorer::Query.find_by(id: id)
if query
puts "\nFound query with id #{id}"
query.update!(hidden: false)
puts "Query no.#{id} is now visible"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
else
puts "\nError finding query with id #{id}"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
end
end
puts ""
end
# rake data_explorer:hard_delete[-1]
# rake data_explorer:hard_delete[1,-2,3,-4,5]
desc "Hard deletes one or multiple queries by ID"
task("data_explorer:hard_delete").clear
task "data_explorer:hard_delete" => :environment do |t, args|
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
args.extras.each do |arg|
id = arg.to_i
query = DataExplorer::Query.find_by(id: id)
if query
puts "\nFound query with id #{id}"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
if query.hidden
query.destroy!
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
puts "Query no.#{id} has been deleted"
else
puts "Query no.#{id} must be hidden in order to hard delete"
puts "To hide the query, run: " + "rake data_explorer[#{id}]"
end
else
puts "\nError finding query with id #{id}"
FEATURE: Add ability to soft delete (hide) queries and revert deletion with rake tasks (#54) * FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work * Revert "FEATURE: Add hide button (toggleable) for all queries (frontend only)" This reverts commit a8771d2ad57083a91b7130df807fa54c26205d11. REVERT: Remove button that hides queries (frontend) * Prepare for migration of old frontend logic to backend * We are going to reuse the existing delete button, but change its backend logic to enable soft deletion. From the user's perspective nothing will change, but any deletion mistakes can be reverted. * DEV: Hide user queries upon deletion, but keep them in store * Creating a new query will set its hidden attribute to false by default * Deleting a user-made query will not delete it from the store, but set its hidden attribute to true * User queries will not be indexed if they are hidden * Undeleting a query will unhide it, and will be indexed * Updating a hidden query will unhide it, and will be indexed * SPEC: Add spec for hidden/deleted queries * Hidden queries should not be shown * FEATURE: Add ability to delete/hide system queries * System queries are now able to be deleted from view, but will remain in the backend for retrieval, if necessary * FEATURE/DEV: Add rake commands for query soft deletion * query:list_hidden - Shows a list of hidden queries * query:hide_all[only_default] - Hides all queries, w/ boolean arg to hide only default ones * query:unhide[id] - Unhides a query by id * query:unhide_all[exclude_default] - Unhides all hidden queries, w/ boolean arg to exclude default ones * Remove rails loggers * UX/DEV: Update query rake tasks to be more user friendly * Split query:hide_all[only_default] into two tasks: * query:hide_all - Hides all queries * query:hide_all:only_default - Hide only default queries * Split query:unhide_all[exclude_default] into two tasks: * query:unhide_all - Unhides all hidden queries * query:unhide_all:exclude_default - Unhides all non-default queries * Rename file to match task name * UX: query:unhide can accept multiple arguments * Example: rake query:unhide[-5,-6,-7,3,5,6,-13,-14,-10] * UX: Update query rake tasks to output cleaner messages * Remove unneeded comment * DEV: Keep only necessary rake tasks, use more specific naming * UX/DEV: Add rake task for hard deletion, better console logs * User is able to hard delete a query only if it is hidden, otherwise output a message stating so * Add commented examples above each task * Add rainbow support for more readable console logs * Successful messages will display green, failures display red, additional info displays yellow * Separate multiple queries with spaces instead of lines * DEV: Remove rainbow colorizing in console logs * Rainbow is a dependency of rubocop and it may go away in the future * Rainbow is only used for dev and test environments * DEV: Add Rails engine to enable rake tasks to be loaded at runtime * DEV: Favor require - load files only if they are not already loaded * SPEC: Add tests for data_explorer[id] rake command * Test if a single query is hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element * Expect that one element to have the same ID as the one invoked to be hidden * Test if multiple queries are hidden correctly * Expect length of query list to not be modified * Expect array of hidden queries to have the number of elements equal to the number invoked to be hidden * Expect the elements to have the same ID as the ones invoked to be hidden * Test if a query exists in PluginStore * Expect query list to be empty * DEV: Clear pre-existing tasks before redefining * This prevents double invocation when user invokes the task once * SPEC: Add tests for unhide_query rake task * Test if a single query unhides correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 1 of 2 queries * Expect remaining element to be hidden * Test if multiple queries unhide correctly * Expect length of query list to not be modified * Expect array of hidden queries to have exactly 1 element after unhiding 3 of 4 queries * Expect remaining element to be hidden * Test if a query exists in PluginStore * Expect query list to not be modified * SPEC: Add tests for hard_delete rake task * Test if a single query hard deletes correctly * Expect length of query list to be shorter by 1 * Expect array of hidden queries to have exactly 1 element after hard deleting 1 of 2 queries * Expect 1 remaining hidden element * Test if multiple queries hard delete correctly * Expect length of query list to be shorter by 3 after hard deleting 3 of 4 queries * Expect array of hidden queries to have exactly 1 element after hard deleting 3 of 4 queries * Expect 1 remaining hidden element * Test if a query exists in PluginStore * Expect hidden query list to not be modified * Test if a query is not hidden * Expect query list to not be modified * UX: Favor newline char in place of puts for logs * Condensed console logs to output newline char instead of another puts statement (reduces number of lines used significantly)
2020-07-29 02:50:24 -04:00
end
end
puts ""
end