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

add language to user api (#8812)

ulferts8175dc4acdd3
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rb
index c9ffd7ead54..7d964b7e449 100644
--- a/app/contracts/users/base_contract.rb
+++ b/app/contracts/users/base_contract.rb
@@ -39,6 +39,7 @@ module Users
attribute :name
attribute :mail
attribute :admin
+ attribute :language
attribute :auth_source_id
attribute :identity_url
diff --git a/lib/api/v3/users/user_representer.rb b/lib/api/v3/users/user_representer.rb
index ad718cb1197..e48750284d2 100644
--- a/lib/api/v3/users/user_representer.rb
+++ b/lib/api/v3/users/user_representer.rb
@@ -159,6 +159,13 @@ module API
render_nil: true,
cache_if: -> { current_user_is_admin_or_self }
+ property :language,
+ exec_context: :decorator,
+ render_nil: false,
+ getter: ->(*) { represented.language },
+ setter: ->(fragment:, represented:, **) { represented.language = fragment },
+ cache_if: -> { current_user_is_admin_or_self }
+
# Write-only properties
property :password,
diff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rb
index 9b617a1672f..8d8cb722ddc 100644
--- a/spec/lib/api/v3/users/user_representer_spec.rb
+++ b/spec/lib/api/v3/users/user_representer_spec.rb
@@ -54,6 +54,7 @@ describe ::API::V3::Users::UserRepresenter do
is_expected.not_to have_json_path('createdAt')
is_expected.not_to have_json_path('status')
is_expected.not_to have_json_path('email')
+ is_expected.not_to have_json_path('language')
end
end
@@ -70,6 +71,7 @@ describe ::API::V3::Users::UserRepresenter do
is_expected.to have_json_path('createdAt')
is_expected.to have_json_path('status')
is_expected.to have_json_path('email')
+ is_expected.to have_json_path('language')
is_expected.not_to have_json_path('admin')
end
@@ -87,6 +89,7 @@ describe ::API::V3::Users::UserRepresenter do
is_expected.to have_json_path('status')
is_expected.to have_json_path('email')
is_expected.to have_json_path('admin')
+ is_expected.to have_json_path('language')
end
it_behaves_like 'has UTC ISO 8601 date and time' do
diff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rb
index 4e5d7e30f3b..b179c7002f5 100644
--- a/spec/requests/api/v3/user/create_user_resource_spec.rb
+++ b/spec/requests/api/v3/user/create_user_resource_spec.rb
@@ -91,7 +91,8 @@ describe ::API::V3::Users::UsersAPI, type: :request do
login: 'myusername',
firstName: 'Foo',
lastName: 'Bar',
+ email: '[email protected]',
+ language: 'de'
}
}
diff --git a/spec/requests/api/v3/user/update_user_resource_spec.rb b/spec/requests/api/v3/user/update_user_resource_spec.rb
index 6a7598d35b4..326b46b1e79 100644
--- a/spec/requests/api/v3/user/update_user_resource_spec.rb
+++ b/spec/requests/api/v3/user/update_user_resource_spec.rb
@@ -69,8 +69,8 @@ describe ::API::V3::Users::UsersAPI, type: :request do
end
describe 'attribute change' do
- let(:parameters) { { email: '[email protected]' } }
- it_behaves_like 'successful update', mail: '[email protected]'
+ let(:parameters) { { email: '[email protected]', language: 'de' } }
+ it_behaves_like 'successful update', mail: '[email protected]', language: 'de'
end
describe 'password update' do