Commit Graph

20 Commits

Author SHA1 Message Date
Martin Brennan 8d19a33250
FIX: Optionally linkify URL columns server-side (#330)
Followup da1c99ec2d

We already had the functionality to convert results like
this:

```
|blah_url|
|--------|
|3,https://test.com|
```

To a link clientside, so in the UI it looks like this:

```
<a href="https://test.com">3</a>
```

With the addition of the recurring report to post automation,
and the existing report to PM automation, we also need to be
able to do this server-side, so reports don't come out malformed
if they have these type of count + URL columns.
2024-10-14 16:33:13 +10:00
Martin Brennan da1c99ec2d
FEATURE: Add script to post report results in a topic regularly (#328)
This script is similar to the existing one that schedules
report results to to be sent to a PM on a regular basis,
but instead takes a topic ID and posts to that. This way
people can have report results sent to a public topic regularly
too and not have to deal with PM recipients and so on.
2024-10-10 16:09:09 +10:00
Jarek Radosz ba9ead855e
DEV: Fix autoloading (#322)
A follow-up to e23c31195b

Fixes errors like:
```
NameError:
       uninitialized constant DiscourseDataExplorer::ValidationError
     # ./plugins/discourse-data-explorer/spec/lib/parameter_spec.rb:15:in `block (3 levels) in <main>'
```
2024-08-28 10:11:08 +02:00
Linca e23c31195b
DEV: Use Rails autoloading (#321)
This commit enables Rails autoloading for Data Explorer. See:

https://meta.discourse.org/t/structuring-a-plugin-for-rails-autoloading/256092
2024-08-28 11:36:44 +08:00
锦心 1d991c6192
FIX: fix double validation (#314)
The old float validation had several bugs. It will recognize strings
like "a1.2" and "3.4b" as valid doubles, but will not recognize integers
like "1234" as doubles. Also, since an empty string is not falsy in Ruby,
it will recognize "Inf" as -Infinity.

This commit fixes these issues
2024-08-21 15:39:56 +08:00
锦心 6bf3ac7426
FIX: Fix `user_id` validation (#312)
Validation of `user_id` parameter will throw a 500 error because
`User.find_by_username_or_email` does not throw
`ActiveRecord::RecordNotFound`, but silently returns `nil`.
This results in a `NoMethodError` in `object.id` on the next line
2024-08-21 12:03:29 +08:00
锦心 760667d744
FIX: Param should be displayed when the default value is invalid (#313)
What's the problem?
===================

TL;DR: When the user enters an incorrect default value, its
corresponding param-input will disappear

When creating a parameter from SQL, we perform cast_to_ruby, which means
that if the default value given by the user is invalid, the entire
parameter will not be added to the param_list of the query.
This behavior is very confusing, and users will not understand why an
incorrect initial value will cause the param-input to disappear.

What's the fix?
================

The cast_to_ruby process is canceled in create_from_sql, so that
param-input with incorrect default value will still be displayed.
We have a simple validation process on the front end, which is enough to
prompt whether some default inputs are incorrect.
2024-08-21 12:03:11 +08:00
锦心 b063db4ba4
FIX: Use with_deleted only in topic and post (#308)
We used `with_deleted` incorrectly in the code. This method does not exist
on `User`, `Badge`, and `Group`. This will cause an error when entering a
numeric id in these three parameter input, forcing the user to enter the
name/username of these inputs.

See https://github.com/discourse/discourse-data-explorer/pull/307#issuecomment-2291017256
2024-08-15 20:01:53 +08:00
Robert 6e986c008c
FEATURE: add instant run-off voting export query (#294) 2024-07-17 14:45:40 +02:00
Loïc Guitaut c19fca4060
DEV: Update rubocop-discourse to version 3.8.0 (#292) 2024-05-28 11:16:14 +02:00
Penar Musaraj 2f1044820c
FEATURE: Add group_list parameter type (#283)
This allows admins to select multiple groups from a dropdown list and
filter results using that parameter.
2024-03-12 12:06:01 -04:00
Martin Brennan f09e631636
DEV: Adapt to core bookmark changes (#280)
* Added can_see_bookmarkable? methods to BaseBookmarkable, implement
  that in QueryGroupBookmarkable
* Update spec to check that Notification for reminder has
  bookmarkable_id and bookmarkable_type

c.f. https://github.com/discourse/discourse/pull/25905
2024-02-29 09:11:40 +10:00
Martin Brennan 48a4038809
FEATURE: Allow topic URL without post number for post_id param (#275)
This commit allows base topic URLs (e.g. https://meta.discourse.org/t/hide-text-in-text-select-popup-menu-feedback/287656)
to be used by the post_id parameter type. We just assume in this case
that the post_id for the param is 1.
2024-01-16 15:09:05 +10:00
TheJammiestDodger 9f841a4c6f
FIX: Update 'Largest Uploads' queries to use the upload_references table (#261)
The post_uploads table has been deprecated. This commit updates the 'Top 50 Largest Uploads' query to use the new upload_references table instead.
2023-11-13 09:53:33 +00:00
Martin Brennan 5776aa7fc9
FEATURE: Add JSON result type component (#260)
If a column is payload or contains _payload it will be assumed
it has JSON data in it, then we will show the truncated JSON in the
result column with a button to show the full-screen formatted
JSON using our full-screen code viewer. We also do the same if
the column is the `json` postgres data type.
2023-11-02 09:50:05 +10:00
Canapin 98e96fccc2
[FIX] The user_list parameter returned user objects instead of their IDs (#239) 2023-04-15 22:02:32 +01:00
Bianca Nenciu 206d937a78
DEV: Update plugin to match latest guidelines (#229)
This commit updates the plugin to the latest guidelines, as shown in
discourse-plugin-skeleton, which involves moving a lot of the code to
dedicated files, use proper namespaces, use the autoloader as much as
possible, etc.
2023-03-22 23:29:08 +02:00
Bianca Nenciu 0f6b30c2d8
Revert "DEV: Update plugin to match latest guidelines (#227)" (#228)
This reverts commit 9210cf6fa2.
2023-02-23 19:10:46 +02:00
Bianca Nenciu 9210cf6fa2
DEV: Update plugin to match latest guidelines (#227)
- Define extension modules
- Use different files instead of plugin.rb
- Make sure plugin is disabled according to the setting
2023-02-23 15:29:13 +02:00
Ricky Chon dcfb92d7f8
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 a8771d2ad5.

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 16:50:24 +10:00