From 767769f0636ca7a3c6662b02645dc36d1c6a4bcd Mon Sep 17 00:00:00 2001 From: Koen Gremmelprez Date: Tue, 10 Sep 2024 16:30:57 +0200 Subject: [PATCH 1/4] Added a feature flag to opt-out of Gravatar --- back/app/jobs/generate_user_avatar_job.rb | 1 + back/config/schemas/settings.schema.json.erb | 15 +++++++++++++- .../jobs/generate_user_avatar_job_spec.rb | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/back/app/jobs/generate_user_avatar_job.rb b/back/app/jobs/generate_user_avatar_job.rb index 050c3bef61e9..fd4e0c0fe73a 100644 --- a/back/app/jobs/generate_user_avatar_job.rb +++ b/back/app/jobs/generate_user_avatar_job.rb @@ -5,6 +5,7 @@ class GenerateUserAvatarJob < ApplicationJob def run(user) return unless AppConfiguration.instance.feature_activated?('user_avatars') + return unless AppConfiguration.instance.feature_activated?('gravatar_avatars') return unless user && !user.avatar? && user.email hash = Digest::MD5.hexdigest(user.email) diff --git a/back/config/schemas/settings.schema.json.erb b/back/config/schemas/settings.schema.json.erb index 580b6a0dc8dc..91e39fce426b 100644 --- a/back/config/schemas/settings.schema.json.erb +++ b/back/config/schemas/settings.schema.json.erb @@ -255,6 +255,18 @@ } }, + "gravatar_avatars": { + "type": "object", + "title": "Automatically try to download an avatar from an external service called Gravatar when a user registers without an avatar", + "description": "Allow users to upload a profile picture.", + "additionalProperties": false, + "required": ["allowed", "enabled"], + "properties": { + "allowed": { "type": "boolean", "default": true }, + "enabled": { "type": "boolean", "default": true } + } + }, + "internal_commenting": { "type": "object", "title": "Internal commenting", @@ -1354,7 +1366,8 @@ "large_summaries": ["analysis"], "ask_a_question": ["analysis"], "advanced_autotagging": ["analysis"], - "import_printed_forms": ["input_importer"] + "import_printed_forms": ["input_importer"], + "gravatar_avatars": ["user_avatars"] }, "definitions": { "multiloc_string": { diff --git a/back/spec/jobs/generate_user_avatar_job_spec.rb b/back/spec/jobs/generate_user_avatar_job_spec.rb index d9a9d97556dc..6a956d42f505 100644 --- a/back/spec/jobs/generate_user_avatar_job_spec.rb +++ b/back/spec/jobs/generate_user_avatar_job_spec.rb @@ -28,5 +28,25 @@ job.perform(user) end end + + context 'when gravatar_avatars is enabled' do + before { SettingsService.new.activate_feature!('gravatar_avatars') } + + it 'retrieves and stores an avatar when the user has a gravatar for his email address' do + job.perform(user) + expect(user.reload.avatar).to be_present + end + end + + context 'when gravatar_avatars is disabled' do + before { SettingsService.new.deactivate_feature!('gravatar_avatars') } + + it 'does not retrieve and store the gravatar' do + expect(user).not_to receive(:remote_avatar_url=) + expect(user).not_to receive(:save) + + job.perform(user) + end + end end end From 2a486a5a4065666afa0c06ba49cd97de314e21ea Mon Sep 17 00:00:00 2001 From: Koen Gremmelprez Date: Tue, 10 Sep 2024 16:43:58 +0200 Subject: [PATCH 2/4] Fix specs --- back/spec/acceptance/users_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/back/spec/acceptance/users_spec.rb b/back/spec/acceptance/users_spec.rb index 5552124bdde0..cb8d5ea83bfa 100644 --- a/back/spec/acceptance/users_spec.rb +++ b/back/spec/acceptance/users_spec.rb @@ -174,7 +174,10 @@ end context 'when the user_avatars module is inactive' do - before { SettingsService.new.deactivate_feature!('user_avatars') } + before do + SettingsService.new.deactivate_feature!('gravatar_avatars') + SettingsService.new.deactivate_feature!('user_avatars') + end example_request 'Create a user without avatar' do assert_status 201 @@ -1192,7 +1195,10 @@ end describe 'when user_avatars is disabled' do - before { SettingsService.new.deactivate_feature!('user_avatars') } + before do + SettingsService.new.deactivate_feature!('gravatar_avatars') + SettingsService.new.deactivate_feature!('user_avatars') + end example 'The user avatar can be removed' do @user.update!(avatar: Rails.root.join('spec/fixtures/male_avatar_1.jpg').open) From 44f86bef687f0c6efacac834285e04e491eecdbe Mon Sep 17 00:00:00 2001 From: Koen Gremmelprez Date: Tue, 10 Sep 2024 17:34:55 +0200 Subject: [PATCH 3/4] Fixed specs --- back/engines/commercial/multi_tenancy/db/seeds/tenants.rb | 4 ++++ back/spec/jobs/generate_user_avatar_job_spec.rb | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/back/engines/commercial/multi_tenancy/db/seeds/tenants.rb b/back/engines/commercial/multi_tenancy/db/seeds/tenants.rb index 720816f470bb..c8daa9f10b51 100644 --- a/back/engines/commercial/multi_tenancy/db/seeds/tenants.rb +++ b/back/engines/commercial/multi_tenancy/db/seeds/tenants.rb @@ -397,6 +397,10 @@ def create_localhost_tenant enabled: true, allowed: true }, + gravatar_avatars: { + enabled: true, + allowed: true + }, internal_commenting: { enabled: true, allowed: true diff --git a/back/spec/jobs/generate_user_avatar_job_spec.rb b/back/spec/jobs/generate_user_avatar_job_spec.rb index 6a956d42f505..94443c4fa164 100644 --- a/back/spec/jobs/generate_user_avatar_job_spec.rb +++ b/back/spec/jobs/generate_user_avatar_job_spec.rb @@ -19,7 +19,11 @@ end context 'when user_avatars is disabled' do - before { SettingsService.new.deactivate_feature!('user_avatars') } + + before do + SettingsService.new.deactivate_feature!('gravatar_avatars') + SettingsService.new.deactivate_feature!('user_avatars') + end it 'does not retrieve and store the gravatar' do expect(user).not_to receive(:remote_avatar_url=) From 01c8d0fbdd369591ba0ed2512e7777e30e49c5b5 Mon Sep 17 00:00:00 2001 From: Koen Gremmelprez Date: Tue, 10 Sep 2024 17:44:57 +0200 Subject: [PATCH 4/4] Robocopicopi --- back/spec/jobs/generate_user_avatar_job_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/back/spec/jobs/generate_user_avatar_job_spec.rb b/back/spec/jobs/generate_user_avatar_job_spec.rb index 94443c4fa164..19fe25f27c8a 100644 --- a/back/spec/jobs/generate_user_avatar_job_spec.rb +++ b/back/spec/jobs/generate_user_avatar_job_spec.rb @@ -19,7 +19,6 @@ end context 'when user_avatars is disabled' do - before do SettingsService.new.deactivate_feature!('gravatar_avatars') SettingsService.new.deactivate_feature!('user_avatars')