This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/models
Tarek Khalil f8480ed911
FEATURE: Exposing a way to add a generic report filter (#6816)
* FEATURE: Exposing a way to add a generic report filter

## Why do we need this change?

Part of the work discussed [here](https://meta.discourse.org/t/gain-understanding-of-file-uploads-usage/104994), and implemented a first spike [here](https://github.com/discourse/discourse/pull/6809), I am trying to expose a single generic filter selector per report.

## How does this work?

We basically expose a simple, single generic filter that is computed and displayed based on backend values passed into the report.

This would be a simple contract between the frontend and the backend.

**Backend changes:** we simply need to return a list of dropdown / select options, and enable the report's newly introduced `custom_filtering` property.

For example, for our [Top Uploads](https://github.com/discourse/discourse/pull/6809/files#diff-3f97cbb8726f3310e0b0c386dbe89e22R1423) report, it can look like this on the backend:

```ruby
report.custom_filtering = true
report.custom_filter_options = [{ id: "any", name: "Any" }, { id: "jpg", name: "JPEG" } ]
```

In our javascript report HTTP call, it will look like:

```js
{
  "custom_filtering": true,
  "custom_filter_options": [
    {
      "id": "any",
      "name": "Any"
    },
    {
      "id": "jpg",
      "name": "JPG"
    }
  ]
}
```

**Frontend changes:** We introduced a generic `filter` param and a `combo-box` which hooks up into the existing framework for fetching a report.

This works alright, with the limitation of being a single custom filter per report. If we wanted to add, for an instance a `filesize filter`, this will not work for us. _I went through with this approach because it is hard to predict and build abstractions for requirements or problems we don't have yet, or might not have._

## How does it look like?

![a1ktg1odde](https://user-images.githubusercontent.com/45508821/50485875-f17edb80-09ee-11e9-92dd-1454ab041fbb.gif)

## More on the bigger picture

The major concern here I have is the solution I introduced might serve the `think small` version of the reporting work, but I don't think it serves the `think big`, I will try to shed some light into why.

Within the current design, It is hard to maintain QueryParams for dynamically generated params (based on the idea of introducing more than one custom filter per report).

To allow ourselves to have more than one generic filter, we will need to:

a. Use the Route's model to retrieve the report's payload (we are now dependent on changes of the QueryParams via computed properties)
b. After retrieving the payload, we can use the `setupController` to define our dynamic QueryParams based on the custom filters definitions we received from the backend
c. Load a custom filter specific Ember component based on the definitions we received from the backend
2019-03-15 12:15:38 +00:00
..
concerns PERF: Avoid loading ActiveRecord objects when checking for second factor. 2019-03-15 15:09:44 +08:00
about.rb UX: sort admins and moderators by last seen date on /about page 2019-01-15 17:26:11 +05:30
admin_dashboard_data.rb FEATURE: PWA compatibility checks in the Dashboard (#6850) 2019-01-09 08:46:11 +08:00
admin_dashboard_next_data.rb FIX: makes dashboard more resilient to errors (#6217) 2018-07-31 21:23:28 -04:00
admin_dashboard_next_general_data.rb FIX: treats users_(by_type|tl) as other reports (#6391) 2018-09-13 17:35:54 +02:00
admin_dashboard_next_index_data.rb UI: improves dashboard table reports 2018-07-31 17:35:13 -04:00
api_key.rb Fix all the errors to get our tests green on Rails 5.1. 2017-09-25 13:48:58 +08:00
application_request.rb FEATURE: control which web crawlers can access using a whitelist or blacklist 2018-03-22 15:41:02 -04:00
auto_track_duration_site_setting.rb fix the build 2015-09-14 10:48:24 +02:00
backup_file.rb FEATURE: Support backup uploads/downloads directly to/from S3. 2018-10-15 09:43:31 +08:00
backup_location_site_setting.rb DEV: Enable Style/SingleLineMethods and Style/Semicolon in Rubocop (#6717) 2018-12-04 11:48:13 +08:00
badge_grouping.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
badge_type.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
badge.rb FIX: Badges appeared in wrong badge group 2019-01-21 21:09:33 +01:00
category_and_topic_lists.rb FEATURE: new 'categories_and_latest' endpoint 2016-08-29 22:47:44 +02:00
category_custom_field.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
category_featured_topic.rb refinement and test for batch mode on feature_topics 2017-12-20 13:58:05 +11:00
category_group.rb FEATURE: move staff tags setting to tag group settings 2018-04-20 15:34:23 -04:00
category_list.rb UX: order categories based on recent activity when using categories_and_latest_topics layout (#7166) 2019-03-15 17:14:49 +11:00
category_page_style.rb Feature: add boxes with subcategories option for desktop categories page (#6471) 2018-10-11 15:59:37 +08:00
category_search_data.rb Update annotations. 2018-07-16 14:19:07 +08:00
category_tag_group.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
category_tag_stat.rb Update annotations. 2018-07-16 14:19:07 +08:00
category_tag.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
category_user.rb Update Rubocop to 0.60 2018-12-04 10:48:16 +01:00
category.rb FIX: Failed to detect existing category permalink 2019-03-14 13:42:05 +01:00
child_theme.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
color_scheme_color.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
color_scheme.rb PERF: Reduce N+1s on theme admin page 2019-02-26 14:22:02 +00:00
custom_emoji.rb Update annotations. 2017-03-22 14:26:53 +08:00
developer.rb missing annotation 2016-08-15 17:59:36 +10:00
digest_email_site_setting.rb FEATURE: More digest email frequency options. Digests can be sent as often as every 30 minutes. 2016-03-02 15:43:47 -05:00
directory_item.rb FIX user directory time period count (#6586) 2018-11-12 15:30:05 +01:00
discourse_single_sign_on.rb SECURITY: correct edge case when SSO provides unvalidated emails 2018-09-11 08:24:02 +10:00
discourse_version_check.rb REFACTOR: Avoid duplicated logic on server and client. 2017-11-21 17:10:04 +08:00
draft_sequence.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
draft.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
email_change_request.rb FIX: Don't allow invalid email to be saved. 2016-12-21 17:47:11 +08:00
email_log.rb DEV: Remove ignored columns 2019-02-08 12:12:38 +01:00
email_token.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
embeddable_host.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
embedding.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
emoji_set_site_setting.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
emoji.rb Revert "FIX: Better emoji escaping for topic title" 2019-03-13 13:02:56 +01:00
github_user_info.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
given_daily_like.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
global_setting.rb FEATURE: add setting to bypass sending redis CLIENT commands 2019-01-04 15:08:33 +11:00
group_archived_message.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
group_custom_field.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
group_history.rb FEATURE: Group logs. 2016-12-12 17:29:54 +08:00
group_manager.rb update annotations 2015-09-18 10:41:10 +10:00
group_mention.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
group_user.rb FIX: change title when primary group changes (#6602) 2018-11-14 08:28:41 +08:00
group.rb FIX: allow moderators to create categories setting broken 2019-03-06 17:44:18 +11:00
ignored_user.rb FEATURE: Introduce Ignore user (#7072) 2019-02-27 14:49:07 +01:00
incoming_domain.rb FIX: If the host can't be extracted don't raise an error 2017-05-04 13:26:37 -04:00
incoming_email.rb FEATURE: Use Message-ID for detecting email replies to group 2018-04-05 11:00:38 +02:00
incoming_link.rb FIX: ignore invalid usernames in incoming link tracker 2018-09-04 12:28:32 +10:00
incoming_links_report.rb FIX: Heisentest - don't memoize on a class variable 2019-02-25 14:49:01 -05:00
incoming_referer.rb FIX: catch specific exception 2014-08-06 10:00:55 +10:00
instagram_user_info.rb annotate models 2016-03-28 15:21:45 +11:00
invite_redeemer.rb FIX: invite approval StaffActionLogger bug (#7151) 2019-03-12 13:32:25 +00:00
invite.rb FEATURE: remove all expired invitations by default 2019-03-07 15:28:39 +05:30
invited_group.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
javascript_cache.rb FIX: extracted theme JavaScripts for multisite (#6502) 2018-10-18 17:05:34 +11:00
like_notification_frequency_site_setting.rb FEATURE: like notification frequency of never 2016-03-06 09:12:59 +11:00
locale_site_setting.rb FEATURE: Allow plugins to register a new locale 2018-01-25 14:57:41 +01:00
mailing_list_mode_site_setting.rb Remove daily mailing mode option as it doesn't scale. 2017-05-05 12:21:50 +08:00
muted_user.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
new_topic_duration_site_setting.rb fix the build 2015-09-14 10:48:24 +02:00
notification_level_when_replying_site_setting.rb FEATURE: Add normal as a preference for topic subscription state when replying to a topic 2017-04-20 22:33:10 -04:00
notification.rb FIX: Liked notification consolidation has to account for user like frequency setting. 2019-01-17 14:33:23 +08:00
oauth2_user_info.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
onceoff_log.rb annotate models 2016-05-30 10:45:32 +10:00
optimized_image.rb FIX: only call 'unlink' for tempfiles 2019-03-08 11:22:20 +01:00
permalink.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
plugin_store_row.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
plugin_store.rb FEATURE: Added method to get multiple values at once from PluginStore. (#6225) 2018-08-01 18:42:40 +02:00
post_action_type.rb Remove legacy vote post action code. (#6009) 2018-07-09 16:54:18 +08:00
post_action.rb FIX: When disagreeing with a flag that silenced a user, unsilence them 2019-02-08 08:50:50 -05:00
post_analyzer.rb DEV: Avoid using send and make the method public instead. 2018-09-13 16:34:32 +08:00
post_custom_field.rb Update annotations. 2018-07-16 14:19:07 +08:00
post_detail.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
post_mover.rb FIX: allow banner topic posts to be moved to regular topic (and vice versa) 2019-03-14 23:41:23 +05:30
post_reply_key.rb Revert "FIX: Partial reply key search in email sent logs." 2019-01-10 10:05:56 +08:00
post_reply.rb FIX: Update post replies when we move posts. (#4324) 2016-07-13 17:34:21 +02:00
post_revision.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
post_search_data.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
post_stat.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
post_timing.rb DEV: add API endpoint to destroy_timings only of last post 2018-11-13 16:07:48 +11:00
post_upload.rb Update annotations. 2016-11-24 10:13:03 +08:00
post.rb Revert "REFACTOR: remove unnecessary parentheses attempt 2 (follow-up on 154f503d)" 2019-03-14 08:15:40 +08:00
previous_replies_site_setting.rb FEATURE: allow users to control how many previous replies they get 2016-02-19 13:57:07 +11:00
push_subscription.rb Update annotations. 2018-07-16 14:19:07 +08:00
queued_post.rb FIX: tags added while editing a pending approval topic do not show up (#6959) 2019-02-14 15:42:40 +11:00
quoted_post.rb FIX: ignore self-quotes from the same post when saving (#6082) 2018-07-10 16:17:28 +08:00
remote_theme.rb FIX: Imported themes should set their color scheme automatically 2019-01-31 17:45:11 +00:00
report.rb FEATURE: Exposing a way to add a generic report filter (#6816) 2019-03-15 12:15:38 +00:00
s3_region_site_setting.rb FEATURE: Add missing S3 regions 2019-03-07 22:42:20 +01:00
screened_email.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
screened_ip_address.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
screened_url.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
search_log.rb DEV: Remove the unique_searches column from select query 2018-12-19 02:45:48 +05:30
shared_draft.rb Update annotations. 2018-07-16 14:19:07 +08:00
single_sign_on_record.rb PERF: Add index on user_id to single_sign_on_records. 2019-01-30 09:34:19 +08:00
site_setting.rb FIX: Backwards compatibility for SiteSetting.queue_jobs 2019-03-14 11:39:10 -04:00
site.rb FIX: unable to create new categories 2019-02-15 10:24:29 +11:00
skipped_email_log.rb FEATURE: Skip sending emails to domains on the .invalid TLD (#7162) 2019-03-13 16:17:59 +00:00
slug_setting.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
stylesheet_cache.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
tag_group_membership.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
tag_group_permission.rb Update annotations. 2018-07-16 14:19:07 +08:00
tag_group.rb FIX: Disable 'Create Topic' button if tag is staff-only. (#6984) 2019-03-12 19:23:36 +11:00
tag_search_data.rb Update annotations. 2018-07-16 14:19:07 +08:00
tag_user.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
tag.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
theme_field.rb FEATURE: support custom icons in themes (#7155) 2019-03-15 17:16:15 +11:00
theme_setting.rb PERF: Eradicate N+1 queries from the theme admin page 2018-12-21 11:03:58 +02:00
theme_translation_override.rb FEATURE: Support for localized themes (#6848) 2019-01-17 11:46:11 +00:00
theme.rb FIX: Use field name to name files in theme export. (#7009) 2019-02-27 10:45:22 +01:00
top_lists.rb BUGFIX: show the draft on top page 2014-02-06 11:39:43 +01:00
top_menu_item.rb BUGFIX: proper handling of top_menu_items 2014-02-03 16:08:00 +01:00
top_topic.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
topic_allowed_group.rb update annotations 2014-04-08 17:35:44 +02:00
topic_allowed_user.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
topic_converter.rb FIX: update categories topic_count when converting topic to a PM and vice versa 2018-04-04 12:01:56 +05:30
topic_custom_field.rb Update annotations. 2018-07-16 14:19:07 +08:00
topic_embed.rb FIX: properly escape embed url 2019-01-07 18:11:43 +01:00
topic_featured_users.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
topic_invite.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
topic_link_click.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_link.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_list.rb FIX: Shared draft performance fix + missing avatars 2018-03-28 16:11:43 -04:00
topic_notifier.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
topic_participants_summary.rb FEATURE: Add recipient avatars in PM topic list even if they not yet replied 2019-01-25 19:41:49 +05:30
topic_poster.rb FEATURE: primary group class on avatars in topic list 2017-02-20 15:55:10 -05:00
topic_posters_summary.rb Require dependency otherwise it causes Sidekiq to lock up in development. 2017-09-25 13:48:59 +08:00
topic_search_data.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_tag.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_timer.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_tracking_state.rb Enable Lint/ShadowingOuterLocalVariable for Rubocop. 2018-09-04 10:16:42 +08:00
topic_user.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
topic_view_item.rb DEV: remove all calls to SqlBuilder use DB.build instead 2018-06-20 17:53:49 +10:00
topic.rb FEATURE: Skip small actions when counting replies in PMs. (#7108) 2019-03-08 10:49:34 +02:00
translation_override.rb REFACTOR: Use keyword argument for fallback_to_english flag 2019-02-19 15:28:47 +01:00
trust_level3_requirements.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
trust_level_and_staff_setting.rb FEATURE: Support disabling tag creation for non-staff users. 2018-06-27 07:15:02 +08:00
trust_level_setting.rb FIX: Only add the trust level name for numeric trust levels 2019-01-16 12:04:12 +00:00
unsubscribe_key.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
upload.rb FIX: Upload#migrate_to_new_scheme should not migrate system uploads. 2019-03-14 12:45:03 +08:00
user_action.rb FEATURE: Consolidate likes notifications. (#6879) 2019-01-16 10:40:16 +08:00
user_api_key.rb FIX: add support for missing verbs in user api key 2019-02-13 15:49:43 +11:00
user_archived_message.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_associated_account.rb DEV: Style and performance improvements 2018-12-11 09:58:20 +00:00
user_auth_token_log.rb FEATURE: Let users see their user auth tokens. (#6313) 2018-08-31 10:18:06 +02:00
user_auth_token.rb DEV: Remove ignored columns 2019-02-08 12:12:38 +01:00
user_avatar.rb FIX: Job exception: undefined method `email' for nil:NilClass 2019-03-08 13:39:56 -05:00
user_badge.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_badges.rb Add rubocop to our build. (#5004) 2017-07-28 10:20:09 +09:00
user_custom_field.rb FIX: remove nullable dates post upgrade to Rails 4 2014-08-27 15:19:25 +10:00
user_email.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_export.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_field_option.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_field.rb UX: make name optional for confirmation user field (#7149) 2019-03-13 18:40:43 +01:00
user_history.rb FEATURE: Log user approvals. (#7121) 2019-03-12 19:16:56 +11:00
user_open_id.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user_option.rb DEV: Remove ignored columns 2019-02-08 12:12:38 +01:00
user_profile_view.rb DEV: remove all calls to SqlBuilder use DB.build instead 2018-06-20 17:53:49 +10:00
user_profile.rb DEV: remove user_profile events added for akismet (#7044) 2019-03-12 17:51:09 +01:00
user_search_data.rb Update annotations. 2018-07-16 14:19:07 +08:00
user_search.rb FEATURE: autocomplete usernames early in topic based on participation 2019-02-20 13:34:43 +11:00
user_second_factor.rb PERF: Avoid loading ActiveRecord objects when checking for second factor. 2019-03-15 15:09:44 +08:00
user_stat.rb FIX: do not store key tracking last seen time indefinitely 2018-12-03 08:35:26 +11:00
user_summary.rb FIX: sort topics/posts/links in descending order in user summaries 2019-01-16 23:58:46 +01:00
user_upload.rb Add missing annotations 2018-10-08 18:01:21 +02:00
user_visit.rb DEV: remove exec_sql and replace with mini_sql 2018-06-19 16:13:36 +10:00
user_warning.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
user.rb PERF: N+1 queries admin users pages. 2019-03-15 15:09:44 +08:00
username_validator.rb Revert "FIX: Username uniqueness check should not happen to current user_id" 2018-04-03 00:44:04 +08:00
watched_word.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
web_crawler_request.rb Update annotations. 2018-07-16 14:19:07 +08:00
web_hook_event_type.rb Rename approval web hook event type to queued post 2018-07-26 10:29:38 +05:30
web_hook_event.rb FIX: Previous annotations were broken 2019-01-11 14:30:19 -05:00
web_hook.rb FIX: post & topic destroyed hooks not triggering with tag filter 2019-03-06 22:52:54 +05:30