Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[37257] Bust cache on settings name format change (#9276)

Oliver Güntherbb27cf990340
diff --git a/lib/api/v3/users/user_representer.rb b/lib/api/v3/users/user_representer.rb
index fd96edb9076..38b7f55b0d7 100644
--- a/lib/api/v3/users/user_representer.rb
+++ b/lib/api/v3/users/user_representer.rb
@@ -36,7 +36,15 @@ module API
extend ::API::V3::Utilities::CustomFieldInjector::RepresenterClass
cached_representer key_parts: %i(auth_source),
- dependencies: ->(*) { avatar_cache_dependencies }
+ dependencies: ->(*) {
+ [
+ # For the name rendering
+ Setting.user_format,
+ # For avatars
+ Setting.plugin_openproject_avatars,
+ Setting.protocol
+ ]
+ }
self_link
diff --git a/modules/avatars/lib/open_project/avatars/engine.rb b/modules/avatars/lib/open_project/avatars/engine.rb
index da7f956f05b..4ec5d99a7f4 100644
--- a/modules/avatars/lib/open_project/avatars/engine.rb
+++ b/modules/avatars/lib/open_project/avatars/engine.rb
@@ -66,6 +66,5 @@ module OpenProject::Avatars
end
patches %i[User]
- patch_with_namespace :API, :V3, :Users, :UserRepresenter
end
end
diff --git a/modules/avatars/lib/open_project/avatars/patches/user_representer_patch.rb b/modules/avatars/lib/open_project/avatars/patches/user_representer_patch.rb
deleted file mode 100644
index 6b42bf571a8..00000000000
--- a/modules/avatars/lib/open_project/avatars/patches/user_representer_patch.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module OpenProject::Avatars::Patches
- module UserRepresenterPatch
- extend ActiveSupport::Concern
-
- included do
- ##
- # Dependencies required to cache users with avatars
- # When the plugin is loaded, depend on its settings
- def avatar_cache_dependencies
- [Setting.plugin_openproject_avatars, Setting.protocol]
- end
- end
- end
-end
diff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rb
index ef37ce10868..ade816ecc27 100644
--- a/spec/lib/api/v3/users/user_representer_spec.rb
+++ b/spec/lib/api/v3/users/user_representer_spec.rb
@@ -286,11 +286,13 @@ describe ::API::V3::Users::UserRepresenter do
describe '#json_cache_key' do
let(:auth_source) { FactoryBot.build_stubbed(:auth_source) }
+ let(:former_cache_key) { representer.json_cache_key }
before do
user.auth_source = auth_source
+
+ former_cache_key
end
- let!(:former_cache_key) { representer.json_cache_key }
it 'includes the name of the representer class' do
expect(representer.json_cache_key)
@@ -311,6 +313,33 @@ describe ::API::V3::Users::UserRepresenter do
.not_to eql former_cache_key
end
+ it 'changes when user format setting changes' do
+ allow(Setting)
+ .to receive(:user_format)
+ .and_return 'something else'
+
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
+ end
+
+ it 'changes when the avatars plugin settings change' do
+ allow(Setting)
+ .to receive(:plugin_openproject_avatars)
+ .and_return 'something else'
+
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
+ end
+
+ it 'changes when the protocol settings change' do
+ allow(Setting)
+ .to receive(:protocol)
+ .and_return 'something else'
+
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
+ end
+
it 'changes when the user\'s auth_source is updated' do
user.auth_source.updated_at = Time.now + 20.seconds