From a8311cd97249d03b874eae8b1e0a05abfc32283c Mon Sep 17 00:00:00 2001 From: Erin Bond Date: Tue, 4 Sep 2018 14:54:09 -0400 Subject: [PATCH 1/3] don't increment abuse score after content moderation --- shared/middleware/files_api.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/shared/middleware/files_api.rb b/shared/middleware/files_api.rb index 34e7f15b7073c..6ad090f771de7 100644 --- a/shared/middleware/files_api.rb +++ b/shared/middleware/files_api.rb @@ -856,15 +856,14 @@ def files_put_file(encrypted_channel_id, filename, body) project_type = storage_apps.project_type_from_channel_id(encrypted_channel_id) if MODERATE_THUMBNAILS_FOR_PROJECT_TYPES.include? project_type file_mime_type = mime_type(File.extname(filename.downcase)) - rating = ImageModeration.rate_image(file, file_mime_type, request.fullpath) - if %i(adult racy).include? rating - # Incrementing abuse score by 15 to differentiate from manually reported projects - new_score = storage_apps.increment_abuse(encrypted_channel_id, 15) - FileBucket.new.replace_abuse_score(encrypted_channel_id, s3_prefix, new_score) - response.headers['x-cdo-content-rating'] = rating.to_s - cache_for 1.hour - not_found - end + ImageModeration.rate_image(file, file_mime_type, request.fullpath) + # We are going to re-enable content moderation, but will be adjusting + # the thresholds in a series of trials to optimize for identifying + # inappropriate images without incorrectly flagging appropriate images. + # In the meantime, we don't want to increment abuse score until we + # identify the optimal threshold. + # TODO (ErinB) re-enable abuse score incrementation when + # the correct thresholds are set. end end From 70c5d5429b2dd5bba2d7dda79c767fb3da913fd6 Mon Sep 17 00:00:00 2001 From: Erin Bond Date: Tue, 4 Sep 2018 18:34:23 -0400 Subject: [PATCH 2/3] temporarily remove tests for racy and adult thumbnails --- .../files_api/test_public_thumbnails.rb | 56 ------------------- 1 file changed, 56 deletions(-) diff --git a/shared/test/middleware/files_api/test_public_thumbnails.rb b/shared/test/middleware/files_api/test_public_thumbnails.rb index 648017862291d..1929b20193ddd 100644 --- a/shared/test/middleware/files_api/test_public_thumbnails.rb +++ b/shared/test/middleware/files_api/test_public_thumbnails.rb @@ -10,62 +10,6 @@ def setup Aws::S3::Client.expects(:new).never end - def test_adult_thumbnail - ImageModeration.stubs(:rate_image).once.returns :adult - - with_project_type('applab') do |channel_id| - get "/v3/files-public/#{channel_id}/#{@thumbnail_filename}" - - # Responds with a 404, like we do for flagged content - assert not_found? - - # Includes content rating metadata in the response that the client can read - assert_equal 'adult', last_response['x-cdo-content-rating'] - - # Response is cached for an hour - assert_equal 'public, max-age=3600, s-maxage=1800', last_response['Cache-Control'] - - # Flags the project as abusive. - get "/v3/channels/#{channel_id}/abuse" - assert successful? - assert_equal 15, JSON.parse(last_response.body)['abuse_score'] - - # Flags the thumbnail as abusive - thumbnail = FileBucket.new.get(channel_id, @thumbnail_filename) - metadata = thumbnail[:metadata] - thumbnail_abuse = [metadata['abuse_score'].to_i, metadata['abuse-score'].to_i].max - assert_equal 15, thumbnail_abuse - end - end - - def test_racy_thumbnail - ImageModeration.stubs(:rate_image).once.returns :racy - - with_project_type('applab') do |channel_id| - get "/v3/files-public/#{channel_id}/#{@thumbnail_filename}" - - # Responds with a 404, like we do for flagged content - assert not_found? - - # Includes content rating metadata in the response that the client can read - assert_equal 'racy', last_response['x-cdo-content-rating'] - - # Response is cached for an hour - assert_equal 'public, max-age=3600, s-maxage=1800', last_response['Cache-Control'] - - # Flags the project as abusive. - get "/v3/channels/#{channel_id}/abuse" - assert successful? - assert_equal 15, JSON.parse(last_response.body)['abuse_score'] - - # Flags the thumbnail as abusive - thumbnail = FileBucket.new.get(channel_id, @thumbnail_filename) - metadata = thumbnail[:metadata] - thumbnail_abuse = [metadata['abuse_score'].to_i, metadata['abuse-score'].to_i].max - assert_equal 15, thumbnail_abuse - end - end - def test_everyone_thumbnail ImageModeration.stubs(:rate_image).once.returns(:everyone).with do |file, _, _| # Real ImageModeration reads the IO stream in order to do its work. From 8810dbab41021938fb8cab10d4f9003545b22b71 Mon Sep 17 00:00:00 2001 From: Erin Bond Date: Tue, 4 Sep 2018 22:08:42 -0400 Subject: [PATCH 3/3] skip rather than delete tests --- .../files_api/test_public_thumbnails.rb | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/shared/test/middleware/files_api/test_public_thumbnails.rb b/shared/test/middleware/files_api/test_public_thumbnails.rb index 1929b20193ddd..e9c8712c26087 100644 --- a/shared/test/middleware/files_api/test_public_thumbnails.rb +++ b/shared/test/middleware/files_api/test_public_thumbnails.rb @@ -10,6 +10,66 @@ def setup Aws::S3::Client.expects(:new).never end + #Disabled while we gather Azure moderation stats. (PR 24626)' + def test_adult_thumbnail + skip + ImageModeration.stubs(:rate_image).once.returns :adult + + with_project_type('applab') do |channel_id| + get "/v3/files-public/#{channel_id}/#{@thumbnail_filename}" + + # Responds with a 404, like we do for flagged content + assert not_found? + + # Includes content rating metadata in the response that the client can read + assert_equal 'adult', last_response['x-cdo-content-rating'] + + # Response is cached for an hour + assert_equal 'public, max-age=3600, s-maxage=1800', last_response['Cache-Control'] + + # Flags the project as abusive. + get "/v3/channels/#{channel_id}/abuse" + assert successful? + assert_equal 15, JSON.parse(last_response.body)['abuse_score'] + + # Flags the thumbnail as abusive + thumbnail = FileBucket.new.get(channel_id, @thumbnail_filename) + metadata = thumbnail[:metadata] + thumbnail_abuse = [metadata['abuse_score'].to_i, metadata['abuse-score'].to_i].max + assert_equal 15, thumbnail_abuse + end + end + + #Disabled while we gather Azure moderation stats. (PR 24626)' + def test_racy_thumbnail + skip + ImageModeration.stubs(:rate_image).once.returns :racy + + with_project_type('applab') do |channel_id| + get "/v3/files-public/#{channel_id}/#{@thumbnail_filename}" + + # Responds with a 404, like we do for flagged content + assert not_found? + + # Includes content rating metadata in the response that the client can read + assert_equal 'racy', last_response['x-cdo-content-rating'] + + # Response is cached for an hour + assert_equal 'public, max-age=3600, s-maxage=1800', last_response['Cache-Control'] + + # Flags the project as abusive. + get "/v3/channels/#{channel_id}/abuse" + assert successful? + assert_equal 15, JSON.parse(last_response.body)['abuse_score'] + + # Flags the thumbnail as abusive + thumbnail = FileBucket.new.get(channel_id, @thumbnail_filename) + metadata = thumbnail[:metadata] + thumbnail_abuse = [metadata['abuse_score'].to_i, metadata['abuse-score'].to_i].max + assert_equal 15, thumbnail_abuse + end + end + def test_everyone_thumbnail ImageModeration.stubs(:rate_image).once.returns(:everyone).with do |file, _, _| # Real ImageModeration reads the IO stream in order to do its work.