From 50487db1224851a49ee523bbc013d5f8686a7a55 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 25 Aug 2022 04:27:47 +0200 Subject: Add ability to filter individual posts (#18945) * Add database table for status-specific filters * Add REST endpoints, entities and attributes * Show status filters in /filters interface * Perform server-side filtering for individual posts filters * Fix filtering on context mismatch * Refactor `toServerSideType` by moving it to its own module * Move loupe and delete icons to their own module * Add ability to filter individual posts from WebUI * Replace keyword list by warnings (expired, context mismatch) * Refactor server-side filtering code * Add tests --- app/serializers/rest/filter_result_serializer.rb | 5 +++++ app/serializers/rest/filter_serializer.rb | 1 + app/serializers/rest/filter_status_serializer.rb | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 app/serializers/rest/filter_status_serializer.rb (limited to 'app/serializers') diff --git a/app/serializers/rest/filter_result_serializer.rb b/app/serializers/rest/filter_result_serializer.rb index 0ef4db79a..54ead2f1f 100644 --- a/app/serializers/rest/filter_result_serializer.rb +++ b/app/serializers/rest/filter_result_serializer.rb @@ -3,4 +3,9 @@ class REST::FilterResultSerializer < ActiveModel::Serializer belongs_to :filter, serializer: REST::FilterSerializer has_many :keyword_matches + has_many :status_matches + + def status_matches + object.status_matches&.map(&:to_s) + end end diff --git a/app/serializers/rest/filter_serializer.rb b/app/serializers/rest/filter_serializer.rb index 98d7edb17..8816dd807 100644 --- a/app/serializers/rest/filter_serializer.rb +++ b/app/serializers/rest/filter_serializer.rb @@ -3,6 +3,7 @@ class REST::FilterSerializer < ActiveModel::Serializer attributes :id, :title, :context, :expires_at, :filter_action has_many :keywords, serializer: REST::FilterKeywordSerializer, if: :rules_requested? + has_many :statuses, serializer: REST::FilterStatusSerializer, if: :rules_requested? def id object.id.to_s diff --git a/app/serializers/rest/filter_status_serializer.rb b/app/serializers/rest/filter_status_serializer.rb new file mode 100644 index 000000000..6bcbaa249 --- /dev/null +++ b/app/serializers/rest/filter_status_serializer.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class REST::FilterStatusSerializer < ActiveModel::Serializer + attributes :id, :status_id + + def id + object.id.to_s + end + + def status_id + object.status_id.to_s + end +end -- cgit