Skip to content

Commit

Permalink
Deprecate column picker settings page
Browse files Browse the repository at this point in the history
Delete the GraphQL field list_columns from TeamType, delete the respective model method and any other dependent code and related tests

Reference: CV2-3920
  • Loading branch information
danielevalverde committed Jan 3, 2024
1 parent 4e107b7 commit 2390aba
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 340 deletions.
1 change: 0 additions & 1 deletion app/graph/mutations/team_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/graph/types/project_media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
Expand Down
2 changes: 0 additions & 2 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 :get_data_report_url, GraphQL::Types::String, null: true
field :url, GraphQL::Types::String, null: true
field :get_tipline_inbox_filters, JsonStringType, null: true
Expand Down Expand Up @@ -133,7 +132,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
Expand Down
11 changes: 0 additions & 11 deletions app/helpers/validations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions app/models/concerns/team_duplication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def self.duplicate(t, custom_slug = nil, custom_name = nil)

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
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/team_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ module TeamValidations
validate :language_format
validate :languages_format
validate :fieldsets_format
validate :list_columns_format
end
end
13 changes: 0 additions & 13 deletions app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,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 = [
Expand Down
151 changes: 0 additions & 151 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app/models/team_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,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, YAML::dump(User.current))
end

def update_teamwide_tasks
self.team&.clear_list_columns_cache
fields = {
label: self.saved_change_to_label?,
description: self.saved_change_to_description?,
Expand All @@ -129,7 +127,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, YAML::dump(User.current), YAML::dump({}), self.keep_completed_tasks)
end
Expand Down
1 change: 0 additions & 1 deletion app/workers/project_media_cache_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/tasks/migrate/20220715122310_update_cached_fields.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 0 additions & 94 deletions test/controllers/graphql_controller_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2390aba

Please sign in to comment.