diff --git a/app/graph/mutations/team_mutations.rb b/app/graph/mutations/team_mutations.rb index 1e9c1fc94b..87c8be95fc 100644 --- a/app/graph/mutations/team_mutations.rb +++ b/app/graph/mutations/team_mutations.rb @@ -47,7 +47,6 @@ class Update < Mutations::UpdateMutation argument :language, GraphQL::Types::String, required: false argument :languages, JsonStringType, required: false argument :language_detection, GraphQL::Types::Boolean, required: false, camelize: false - argument :list_columns, JsonStringType, required: false, camelize: false argument :tipline_inbox_filters, GraphQL::Types::String, required: false, camelize: false argument :suggested_matches_filters, GraphQL::Types::String, required: false, camelize: false argument :outgoing_urls_utm_code, GraphQL::Types::String, required: false, camelize: false diff --git a/app/graph/types/project_media_type.rb b/app/graph/types/project_media_type.rb index 4e999a8095..eed899f195 100644 --- a/app/graph/types/project_media_type.rb +++ b/app/graph/types/project_media_type.rb @@ -26,7 +26,6 @@ class ProjectMediaType < DefaultObject field :last_seen, GraphQL::Types::String, null: true field :status, GraphQL::Types::String, null: true field :share_count, GraphQL::Types::Int, null: true - field :list_columns_values, JsonStringType, null: true field :feed_columns_values, JsonStringType, null: true field :report_status, GraphQL::Types::String, null: true field :confirmed_as_similar_by_name, GraphQL::Types::String, null: true diff --git a/app/graph/types/team_type.rb b/app/graph/types/team_type.rb index d897d2efc0..329b272c6c 100644 --- a/app/graph/types/team_type.rb +++ b/app/graph/types/team_type.rb @@ -39,7 +39,6 @@ class TeamType < DefaultObject field :get_language_detection, GraphQL::Types::Boolean, null: true field :get_report, JsonStringType, null: true field :get_fieldsets, JsonStringType, null: true - field :list_columns, JsonStringType, null: true field :url, GraphQL::Types::String, null: true field :data_report, JsonStringType, null: true field :available_newsletter_header_types, JsonStringType, null: true # List of header type strings @@ -112,7 +111,6 @@ def get_fieldsets object.get_fieldsets end - field :list_columns, JsonStringType, null: true field :get_data_report_url, GraphQL::Types::String, null: true def get_data_report_url diff --git a/app/helpers/validations_helper.rb b/app/helpers/validations_helper.rb index 10ef380111..a73d33f216 100644 --- a/app/helpers/validations_helper.rb +++ b/app/helpers/validations_helper.rb @@ -49,15 +49,4 @@ def fieldsets_format errors.add(:settings, JSON::Validator.fully_validate(schema, fieldsets)) if !JSON::Validator.validate(schema, fieldsets) end - def list_columns_format - return if self.get_list_columns.blank? - schema = { - type: 'array', - items: { - type: 'string', - } - } - columns = self.get_list_columns - errors.add(:settings, JSON::Validator.fully_validate(schema, columns)) if !JSON::Validator.validate(schema, columns) - end end diff --git a/app/models/concerns/project_media_getters.rb b/app/models/concerns/project_media_getters.rb index e75b203a11..ba7af18797 100644 --- a/app/models/concerns/project_media_getters.rb +++ b/app/models/concerns/project_media_getters.rb @@ -72,10 +72,6 @@ def full_url "#{CheckConfig.get('checkdesk_client')}/#{self.team.slug}#{project_prefix}/media/#{self.id}" end - def created_at_timestamp - self.created_at.to_i - end - def updated_at_timestamp self.updated_at.to_i end diff --git a/app/models/concerns/team_duplication.rb b/app/models/concerns/team_duplication.rb index 642700e497..33f35971ed 100644 --- a/app/models/concerns/team_duplication.rb +++ b/app/models/concerns/team_duplication.rb @@ -41,9 +41,6 @@ def self.duplicate(t, custom_slug = nil, custom_name = nil) end def self.modify_settings(old_team, new_team) - team_task_map = self.team_task_map - new_list_columns = old_team.get_list_columns.to_a.collect{|lc| lc.include?("task_value_") ? "task_value_#{team_task_map[lc.split("_").last.to_i]}" : lc} - new_team.set_list_columns = new_list_columns unless new_list_columns.blank? new_team.set_languages = old_team.get_languages new_team.set_language = old_team.get_language new_team diff --git a/app/models/concerns/team_validations.rb b/app/models/concerns/team_validations.rb index 0a25808b39..9ca736c91b 100644 --- a/app/models/concerns/team_validations.rb +++ b/app/models/concerns/team_validations.rb @@ -15,6 +15,5 @@ module TeamValidations validate :language_format validate :languages_format validate :fieldsets_format - validate :list_columns_format end end diff --git a/app/models/project_media.rb b/app/models/project_media.rb index 5d8ac6e26e..ea59146547 100644 --- a/app/models/project_media.rb +++ b/app/models/project_media.rb @@ -331,19 +331,6 @@ def method_missing(method, *args, &block) end end - def list_columns_values - values = {} - columns = self.team.list_columns || Team.default_list_columns - columns.each do |column| - c = column.with_indifferent_access - if c[:show] - key = c[:key] - values[key] = self.send(key) - end - end - values - end - def feed_columns_values values = {} columns = [ diff --git a/app/models/team.rb b/app/models/team.rb index c6c1ff5ee3..349cb569f8 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -169,17 +169,6 @@ def shorten_outgoing_urls=(bool) self.set_shorten_outgoing_urls = bool end - def clear_list_columns_cache - languages = self.get_languages.to_a + I18n.available_locales.map(&:to_s) - languages.uniq.each { |l| Rails.cache.delete("list_columns:team:#{l}:#{self.id}") } - end - - def list_columns=(columns) - self.clear_list_columns_cache - columns = columns.is_a?(String) ? JSON.parse(columns) : columns - self.send(:set_list_columns, columns) - end - def search_id CheckSearch.id({ 'parent' => { 'type' => 'team', 'slug' => self.slug } }) end @@ -331,30 +320,6 @@ def delete_custom_media_verification_status(status_id, fallback_status_id) end end - def list_columns - Rails.cache.fetch("list_columns:team:#{I18n.locale}:#{self.id}") do - show_columns = self.get_list_columns || Team.default_list_columns.select{ |c| c[:show] }.collect{ |c| c[:key] } - columns = [] - Team.default_list_columns.each do |column| - columns << column.merge({ show: show_columns.include?(column[:key]) }) - end - TeamTask.where(team_id: self.id, fieldset: 'metadata', associated_type: 'ProjectMedia').each do |tt| - key = "task_value_#{tt.id}" - columns << { - key: key, - label: tt.label, - show: show_columns.include?(key), - type: tt.task_type - } - end - columns.sort_by! do |column| - index = show_columns.index(column[:key]) - index.nil? ? show_columns.size : index - end - columns - end - end - def self.reindex_statuses_after_deleting_status(ids_json, fallback_status_id) script = { source: "ctx._source.verification_status = params.status", params: { status: fallback_status_id } } ProjectMedia.bulk_reindex(ids_json, script) @@ -450,122 +415,6 @@ def self.update_reports_if_languages_changed(team_id, languages) end end - # This is a method and not a constant because we need the localizations to be evaluated in runtime - def self.default_list_columns - [ - { - key: 'demand', - label: I18n.t(:list_column_demand), - show: true - }, - { - key: 'share_count', - label: I18n.t(:list_column_share_count), - show: true - }, - { - key: 'linked_items_count', - label: I18n.t(:list_column_linked_items_count), - show: true - }, - { - key: 'type_of_media', - label: I18n.t(:list_column_type), - show: true - }, - { - key: 'status', - label: I18n.t(:list_column_status), - show: true - }, - { - key: 'created_at_timestamp', - label: I18n.t(:list_column_created_at), - show: true - }, - { - key: 'last_seen', - label: I18n.t(:list_column_last_seen), - show: true - }, - { - key: 'updated_at_timestamp', - label: I18n.t(:list_column_updated_at), - show: true - }, - { - key: 'report_status', - label: I18n.t(:list_column_report_status), - show: false - }, - { - key: 'tags_as_sentence', - label: I18n.t(:list_column_tags_as_sentence), - show: false - }, - { - key: 'media_published_at', - label: I18n.t(:list_column_media_published_at), - show: false - }, - { - key: 'published_by', - label: I18n.t(:list_column_published_by), - show: false - }, - { - key: 'fact_check_published_on', - label: I18n.t(:list_column_fact_check_published_on), - show: false - }, - { - key: 'comment_count', - label: I18n.t(:list_column_comment_count), - show: false - }, - { - key: 'reaction_count', - label: I18n.t(:list_column_reaction_count), - show: false - }, - { - key: 'related_count', - label: I18n.t(:list_column_related_count), - show: false - }, - { - key: 'suggestions_count', - label: I18n.t(:list_column_suggestions_count), - show: false - }, - { - key: 'folder', - label: I18n.t(:list_column_folder), - show: false - }, - { - key: 'creator_name', - label: I18n.t(:list_column_creator_name), - show: false - }, - { - key: 'team_name', - label: I18n.t(:list_column_team_name), - show: false - }, - { - key: 'sources_as_sentence', - label: I18n.t(:list_column_sources_as_sentence), - show: false - }, - { - key: 'fact_check_title', - label: I18n.t(:list_column_fact_check_title), - show: false - } - ] - end - def default_language self.get_language || 'en' end diff --git a/app/models/team_task.rb b/app/models/team_task.rb index fdc27fbbce..3d2df9bad5 100644 --- a/app/models/team_task.rb +++ b/app/models/team_task.rb @@ -116,12 +116,10 @@ def tasks_with_answers_count private def add_teamwide_tasks - self.team&.clear_list_columns_cache TeamTaskWorker.perform_in(1.second, 'add', self.id, User.current&.id) end def update_teamwide_tasks - self.team&.clear_list_columns_cache fields = { label: self.saved_change_to_label?, description: self.saved_change_to_description?, @@ -134,7 +132,6 @@ def update_teamwide_tasks end def delete_teamwide_tasks - self.team&.clear_list_columns_cache self.keep_completed_tasks = self.keep_completed_tasks.nil? ? false : self.keep_completed_tasks TeamTaskWorker.perform_in(1.second, 'destroy', self.id, User.current&.id, YAML::dump({}), self.keep_completed_tasks) end diff --git a/app/workers/project_media_cache_worker.rb b/app/workers/project_media_cache_worker.rb index 16ad309fd6..053ef6c62b 100644 --- a/app/workers/project_media_cache_worker.rb +++ b/app/workers/project_media_cache_worker.rb @@ -15,6 +15,5 @@ class ProjectMediaCacheWorker def perform(pmid) pm = ProjectMedia.find(pmid) PROJECT_MEDIA_CACHED_FIELDS.each { |field| pm.send(field) } # Just cache if it's not cached yet - pm.list_columns_values end end diff --git a/db/seeds.rb b/db/seeds.rb index 48a5315401..a86380abf5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -589,10 +589,11 @@ def create_tipline_user_and_data(project_media) Dynamic.create!(annotation_type: 'smooch_user', annotated: project_media.team, annotator: BotUser.smooch_user, set_fields: fields.to_json) # Tipline request + plataform = ['whatsapp', 'telegram', 'messenger'].sample smooch_data = { 'role': 'appUser', 'source': { - 'type': ['whatsapp', 'telegram', 'messenger'].sample, + 'type': plataform, 'id': random_string, 'integrationId': random_string, 'originalMessageId': random_string, @@ -611,6 +612,9 @@ def create_tipline_user_and_data(project_media) 'app_id': random_string } + mapping = {'whatsapp'=> CheckChannels::ChannelCodes::WHATSAPP, 'telegram' => CheckChannels::ChannelCodes::TELEGRAM, 'messenger'=>CheckChannels::ChannelCodes::MESSENGER} + project_media.update_columns(channel: {main: project_media.channel['main'], others: project_media.channel['others'].to_a.push(mapping[plataform]).uniq} ) + TiplineRequest.create!( associated: project_media, team_id: project_media.team_id, diff --git a/lib/check_search.rb b/lib/check_search.rb index c259fda4ba..d10b2c6021 100644 --- a/lib/check_search.rb +++ b/lib/check_search.rb @@ -523,34 +523,7 @@ def team_tasks_conditions end def build_es_sort - # As per spec, for now the team task sort should be just based on "has data" / "has no data" - # Items without data appear first - if @options['sort'] =~ /^task_value_[0-9]+$/ - team_task_id = @options['sort'].match(/^task_value_([0-9]+)$/)[1].to_i - missing = { - asc: '_first', - desc: '_last' - }[@options['sort_type'].to_s.downcase.to_sym] - return [ - { - 'task_responses.id': { - order: @options['sort_type'], - missing: missing, - nested: { - path: 'task_responses', - filter: { - bool: { - must: [ - { term: { 'task_responses.team_task_id': team_task_id } }, - { exists: { field: 'task_responses.value' } } - ] - } - } - } - } - } - ] - elsif SORT_MAPPING.keys.include?(@options['sort'].to_s) + if SORT_MAPPING.keys.include?(@options['sort'].to_s) return [ { SORT_MAPPING[@options['sort'].to_s] => @options['sort_type'].to_s.downcase.to_sym } ] diff --git a/lib/tasks/migrate/20220715122310_update_cached_fields.rake b/lib/tasks/migrate/20220715122310_update_cached_fields.rake index 95d03a91f1..0797899916 100644 --- a/lib/tasks/migrate/20220715122310_update_cached_fields.rake +++ b/lib/tasks/migrate/20220715122310_update_cached_fields.rake @@ -26,7 +26,6 @@ namespace :check do failed = false begin CACHED_FIELDS.each { |field| pm.send(field) } # Just cache if it's not cached yet - pm.list_columns_values rescue Exception => e failed = e.message end diff --git a/test/controllers/graphql_controller_2_test.rb b/test/controllers/graphql_controller_2_test.rb index 9a47232a83..2b743e50b0 100644 --- a/test/controllers/graphql_controller_2_test.rb +++ b/test/controllers/graphql_controller_2_test.rb @@ -141,27 +141,6 @@ def setup assert_nil pm.get_annotations('extracted_text').last end - test "should get cached values for list columns" do - RequestStore.store[:skip_cached_field_update] = false - t = create_team - t.set_list_columns = ["updated_at_timestamp", "last_seen", "demand", "share_count", "folder", "linked_items_count", "suggestions_count", "type_of_media", "status", "created_at_timestamp", "report_status", "tags_as_sentence", "media_published_at", "comment_count", "reaction_count", "related_count", "positive_tipline_search_results_count", "negative_tipline_search_results_count"] - t.save! - 5.times { create_project_media team: t } - u = create_user is_admin: true - create_team_user user: u, team: t, role: 'admin' - authenticate_with_user(u) - - query = 'query CheckSearch { search(query: "{}") { medias(first: 5) { edges { node { list_columns_values } } } } }' - post :create, params: { query: query, team: t.slug } - assert_response :success - - assert_queries(7, '=') do - query = 'query CheckSearch { search(query: "{}") { medias(first: 5) { edges { node { list_columns_values } } } } }' - post :create, params: { query: query, team: t.slug } - assert_response :success - end - end - test "should get team task" do t = create_team t2 = create_team @@ -221,79 +200,6 @@ def setup assert_equal 2, JSON.parse(@response.body)['data']['project_media']['confirmed_similar_items_count'] end - test "should sort search by metadata value where items without metadata value show first on ascending order" do - RequestStore.store[:skip_cached_field_update] = false - u = create_user is_admin: true - t = create_team - create_team_user team: t, user: u - tt1 = create_team_task fieldset: 'metadata', team_id: t.id - tt2 = create_team_task fieldset: 'metadata', team_id: t.id - t.list_columns = ["task_value_#{tt1.id}", "task_value_#{tt2.id}"] - t.save! - pm1 = create_project_media team: t, disable_es_callbacks: false - pm2 = create_project_media team: t, disable_es_callbacks: false - pm3 = create_project_media team: t, disable_es_callbacks: false - pm4 = create_project_media team: t, disable_es_callbacks: false - - m = pm1.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt1.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'B' }.to_json }.to_json - m.save! - m = pm3.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt1.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'A' }.to_json }.to_json - m.save! - m = pm4.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt1.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'C' }.to_json }.to_json - m.save! - sleep 2 - - m = pm1.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt2.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'C' }.to_json }.to_json - m.save! - m = pm2.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt2.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'B' }.to_json }.to_json - m.save! - m = pm4.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt2.id }.last - m.disable_es_callbacks = false - m.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'A' }.to_json }.to_json - m.save! - sleep 2 - - authenticate_with_user(u) - - query = 'query CheckSearch { search(query: "{\"sort\":\"task_value_' + tt1.id.to_s + '\",\"sort_type\":\"asc\"}") {medias(first:20){edges{node{dbid}}}}}' - post :create, params: { query: query, team: t.slug } - assert_response :success - results = JSON.parse(@response.body)['data']['search']['medias']['edges'].collect{ |x| x['node']['dbid'] } - assert_equal 4, results.size - assert_equal pm2.id, results.first - - query = 'query CheckSearch { search(query: "{\"sort\":\"task_value_' + tt2.id.to_s + '\",\"sort_type\":\"asc\"}") {medias(first:20){edges{node{dbid}}}}}' - post :create, params: { query: query, team: t.slug } - assert_response :success - results = JSON.parse(@response.body)['data']['search']['medias']['edges'].collect{ |x| x['node']['dbid'] } - assert_equal 4, results.size - assert_equal pm3.id, results.first - - query = 'query CheckSearch { search(query: "{\"sort\":\"task_value_' + tt1.id.to_s + '\",\"sort_type\":\"desc\"}") {medias(first:20){edges{node{dbid}}}}}' - post :create, params: { query: query, team: t.slug } - assert_response :success - results = JSON.parse(@response.body)['data']['search']['medias']['edges'].collect{ |x| x['node']['dbid'] } - assert_equal 4, results.size - assert_equal pm2.id, results.last - - query = 'query CheckSearch { search(query: "{\"sort\":\"task_value_' + tt2.id.to_s + '\",\"sort_type\":\"desc\"}") {medias(first:20){edges{node{dbid}}}}}' - post :create, params: { query: query, team: t.slug } - assert_response :success - results = JSON.parse(@response.body)['data']['search']['medias']['edges'].collect{ |x| x['node']['dbid'] } - assert_equal 4, results.size - assert_equal pm3.id, results.last - end - test "should load permissions for GraphQL" do pm1 = create_project_media pm2 = create_project_media diff --git a/test/controllers/graphql_controller_8_test.rb b/test/controllers/graphql_controller_8_test.rb index 564e7e9cb9..8acfba1a59 100644 --- a/test/controllers/graphql_controller_8_test.rb +++ b/test/controllers/graphql_controller_8_test.rb @@ -489,7 +489,6 @@ def setup medias_count permissions search_id - list_columns team_tasks(first: 10000) { edges { node { @@ -568,7 +567,6 @@ def setup title description is_read - list_columns_values team { verification_statuses } diff --git a/test/models/project_media_5_test.rb b/test/models/project_media_5_test.rb index a2058ef206..60c8868625 100644 --- a/test/models/project_media_5_test.rb +++ b/test/models/project_media_5_test.rb @@ -988,41 +988,6 @@ def setup assert_nil pm.reload.task_value(tt.id) end - test "should return item columns values" do - RequestStore.store[:skip_cached_field_update] = false - Sidekiq::Testing.inline! do - at = create_annotation_type annotation_type: 'task_response' - create_field_instance annotation_type_object: at, name: 'response_test' - t = create_team - tt1 = create_team_task fieldset: 'metadata', team_id: t.id - tt2 = create_team_task fieldset: 'metadata', team_id: t.id - t.list_columns = ["task_value_#{tt1.id}", "task_value_#{tt2.id}"] - t.save! - pm = create_project_media team: t.reload - m = pm.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt1.id }.last - m.response = { annotation_type: 'task_response', set_fields: { response_test: 'Foo Value' }.to_json }.to_json - m.save! - m = pm.get_annotations('task').map(&:load).select{ |t| t.team_task_id == tt2.id }.last - m.response = { annotation_type: 'task_response', set_fields: { response_test: 'Bar Value' }.to_json }.to_json - m.save! - pm.team - # The only SQL query should be to get the team tasks - assert_queries(1, '=') do - values = pm.list_columns_values - assert_equal 2, values.size - assert_equal 'Foo Value', values["task_value_#{tt1.id}"] - assert_equal 'Bar Value', values["task_value_#{tt2.id}"] - end - pm2 = create_project_media - pm2.team - pm2.media - # The only SQL query should be to get the team tasks - assert_queries(1, '=') do - assert_equal 8, pm2.list_columns_values.keys.size - end - end - end - test "should return error if method does not exist" do pm = create_project_media assert_raises NoMethodError do diff --git a/test/models/team_test.rb b/test/models/team_test.rb index efb6a44126..f480761155 100644 --- a/test/models/team_test.rb +++ b/test/models/team_test.rb @@ -827,28 +827,6 @@ def setup assert t.items_are_similar("test", pm, "blah", 1) end - test "should set list columns" do - t = create_team - t.list_columns = ['type_of_media'] - t.save! - assert_equal 1, t.get_list_columns.size - end - - test "should not set list columns if schema is not valid" do - t = create_team - t.set_list_columns({ foo: 'bar' }) - assert_raises ActiveRecord::RecordInvalid do - t.save! - end - end - - test "should return list columns" do - t = create_team - 2.times { create_team_task(team_id: t.id, fieldset: 'metadata', associated_type: 'ProjectMedia') } - 2.times { create_team_task(team_id: t.id, fieldset: 'metadata', associated_type: 'Source') } - assert_equal 24, t.list_columns.size - end - test "should match rule by title with spaces" do t = create_team p0 = create_project team: t diff --git a/test/workers/project_media_cache_worker_test.rb b/test/workers/project_media_cache_worker_test.rb index 6df11f8e08..2deb4febf8 100644 --- a/test/workers/project_media_cache_worker_test.rb +++ b/test/workers/project_media_cache_worker_test.rb @@ -11,6 +11,6 @@ def setup test "should cache data" do pm = create_project_media assert_queries(10, '>') { ProjectMediaCacheWorker.perform_async(pm.id) } - assert_queries(2, '=') { ProjectMediaCacheWorker.perform_async(pm.id) } + assert_queries(1, '=') { ProjectMediaCacheWorker.perform_async(pm.id) } end end